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 constexpr ByteExtent(uint64_t offset, uint64_t length) 35 : offset(offset), length(length) {} 36 37 constexpr bool operator==(const ByteExtent& other) const { 38 return this->length == other.length && this->offset == other.offset; 39 } 40 41 constexpr bool operator<(const ByteExtent& other) const { 42 if (offset != other.offset) { 43 return offset < other.offset; 44 } 45 return length < other.length; 46 } 47 48 uint64_t offset; 49 uint64_t length; 50 }; 51 52 struct BitExtent { BitExtentBitExtent53 constexpr BitExtent(uint64_t offset, uint64_t length) 54 : offset(offset), length(length) {} 55 56 constexpr bool operator==(const BitExtent& other) const { 57 return this->length == other.length && this->offset == other.offset; 58 } 59 constexpr bool operator<(const BitExtent& other) const { 60 if (offset != other.offset) { 61 return offset < other.offset; 62 } 63 return length < other.length; 64 } 65 66 uint64_t offset; 67 uint64_t length; 68 }; 69 70 } // namespace puffin 71 72 #endif // SRC_INCLUDE_PUFFIN_COMMON_H_ 73