| 58 | class LegacyTypeAdapter; |
| 59 | |
| 60 | class CelValue { |
| 61 | public: |
| 62 | // This class is a container to hold strings/bytes. |
| 63 | // Template parameter N is an artificial discriminator, used to create |
| 64 | // distinct types for String and Bytes (we need distinct types for Oneof). |
| 65 | template <int N> |
| 66 | class StringHolderBase { |
| 67 | public: |
| 68 | StringHolderBase() : value_(absl::string_view()) {} |
| 69 | |
| 70 | StringHolderBase(const StringHolderBase&) = default; |
| 71 | StringHolderBase& operator=(const StringHolderBase&) = default; |
| 72 | |
| 73 | // string parameter is passed through pointer to ensure string_view is not |
| 74 | // initialized with string rvalue. Also, according to Google style guide, |
| 75 | // passing pointers conveys the message that the reference to string is kept |
| 76 | // in the constructed holder object. |
| 77 | explicit StringHolderBase(const std::string* str) : value_(*str) {} |
| 78 | |
| 79 | absl::string_view value() const { return value_; } |
| 80 | |
| 81 | // Group of comparison operations. |
| 82 | friend bool operator==(StringHolderBase value1, StringHolderBase value2) { |
| 83 | return value1.value_ == value2.value_; |
| 84 | } |
| 85 | |
| 86 | friend bool operator!=(StringHolderBase value1, StringHolderBase value2) { |
| 87 | return value1.value_ != value2.value_; |
| 88 | } |
| 89 | |
| 90 | friend bool operator<(StringHolderBase value1, StringHolderBase value2) { |
| 91 | return value1.value_ < value2.value_; |
| 92 | } |
| 93 | |
| 94 | friend bool operator<=(StringHolderBase value1, StringHolderBase value2) { |
| 95 | return value1.value_ <= value2.value_; |
| 96 | } |
| 97 | |
| 98 | friend bool operator>(StringHolderBase value1, StringHolderBase value2) { |
| 99 | return value1.value_ > value2.value_; |
| 100 | } |
| 101 | |
| 102 | friend bool operator>=(StringHolderBase value1, StringHolderBase value2) { |
| 103 | return value1.value_ >= value2.value_; |
| 104 | } |
| 105 | |
| 106 | friend class CelValue; |
| 107 | |
| 108 | private: |
| 109 | explicit StringHolderBase(absl::string_view other) : value_(other) {} |
| 110 | |
| 111 | absl::string_view value_; |
| 112 | }; |
| 113 | |
| 114 | // Helper structure for String datatype. |
| 115 | using StringHolder = StringHolderBase<0>; |
| 116 | |
| 117 | // Helper structure for Bytes datatype. |
no outgoing calls
no test coverage detected