• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef SRC_INCLUDE_PUFFIN_COMMON_H_
6 #define SRC_INCLUDE_PUFFIN_COMMON_H_
7 
8 #include <functional>
9 #include <memory>
10 #include <vector>
11 
12 #ifndef DISALLOW_COPY_AND_ASSIGN
13 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
14   TypeName(const TypeName&) = delete;      \
15   void operator=(const TypeName&) = delete
16 #endif  // DISALLOW_COPY_AND_ASSIGN
17 
18 #ifndef FALLTHROUGH_INTENDED
19 #ifdef __clang__
20 #define FALLTHROUGH_INTENDED [[clang::fallthrough]]
21 #else
22 #define FALLTHROUGH_INTENDED
23 #endif  // __clang__
24 #endif  // FALLTHROUGH_INTENDED
25 
26 namespace puffin {
27 
28 using Buffer = std::vector<uint8_t>;
29 
30 // This class is similar to the protobuf generated for |ProtoByteExtent|. We
31 // defined an extra class so the users of puffin do not have to include
32 // puffin.pb.h and deal with its use.
33 struct ByteExtent {
ByteExtentByteExtent34   ByteExtent(uint64_t offset, uint64_t length)
35       : offset(offset), length(length) {}
36 
37   bool operator==(const ByteExtent& other) const {
38     return this->length == other.length && this->offset == other.offset;
39   }
40 
41   uint64_t offset;
42   uint64_t length;
43 };
44 
45 struct BitExtent {
BitExtentBitExtent46   BitExtent(uint64_t offset, uint64_t length)
47       : offset(offset), length(length) {}
48 
49   bool operator==(const BitExtent& other) const {
50     return this->length == other.length && this->offset == other.offset;
51   }
52 
53   uint64_t offset;
54   uint64_t length;
55 };
56 
57 }  // namespace puffin
58 
59 #endif  // SRC_INCLUDE_PUFFIN_COMMON_H_
60