1 // Copyright 2017 The ChromiumOS Authors 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 <ostream> 9 #include <vector> 10 11 #ifndef DISALLOW_COPY_AND_ASSIGN 12 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 13 TypeName(const TypeName&) = delete; \ 14 void operator=(const TypeName&) = delete 15 #endif // DISALLOW_COPY_AND_ASSIGN 16 17 #ifndef FALLTHROUGH_INTENDED 18 #ifdef __clang__ 19 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] 20 #else 21 #define FALLTHROUGH_INTENDED 22 #endif // __clang__ 23 #endif // FALLTHROUGH_INTENDED 24 25 namespace puffin { 26 27 using Buffer = std::vector<uint8_t>; 28 29 // This class is similar to the protobuf generated for |ProtoByteExtent|. We 30 // defined an extra class so the users of puffin do not have to include 31 // puffin.pb.h and deal with its use. 32 struct ByteExtent { ByteExtentByteExtent33 constexpr ByteExtent(uint64_t offset, uint64_t length) 34 : offset(offset), length(length) {} 35 36 constexpr bool operator==(const ByteExtent& other) const { 37 return this->length == other.length && this->offset == other.offset; 38 } 39 40 constexpr bool operator<(const ByteExtent& other) const { 41 if (offset != other.offset) { 42 return offset < other.offset; 43 } 44 return length < other.length; 45 } 46 47 uint64_t offset; 48 uint64_t length; 49 }; 50 51 struct BitExtent { BitExtentBitExtent52 constexpr BitExtent(uint64_t offset, uint64_t length) 53 : offset(offset), length(length) {} 54 55 constexpr bool operator==(const BitExtent& other) const { 56 return this->length == other.length && this->offset == other.offset; 57 } 58 constexpr bool operator<(const BitExtent& other) const { 59 if (offset != other.offset) { 60 return offset < other.offset; 61 } 62 return length < other.length; 63 } 64 65 uint64_t offset; 66 uint64_t length; 67 }; 68 69 } // namespace puffin 70 71 #endif // SRC_INCLUDE_PUFFIN_COMMON_H_ 72