File indexing completed on 2026-04-17 08:35:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef _THRIFT_TUUID_H_
0021 #define _THRIFT_TUUID_H_ 1
0022
0023 #include <thrift/Thrift.h>
0024
0025 #ifdef THRIFT_TUUID_SUPPORT_BOOST_UUID
0026 #include <boost/uuid/uuid.hpp>
0027 #endif
0028
0029 #include <algorithm>
0030 #include <sstream>
0031
0032 namespace apache {
0033 namespace thrift {
0034
0035
0036
0037
0038
0039
0040
0041 class TUuid {
0042 public:
0043 typedef uint8_t value_type;
0044 typedef uint8_t* iterator;
0045 typedef uint8_t const* const_iterator;
0046 typedef std::size_t size_type;
0047 typedef std::ptrdiff_t difference_type;
0048
0049 TUuid() = default;
0050 TUuid(const TUuid& other) = default;
0051 TUuid(TUuid&& other) = default;
0052 TUuid& operator=(const TUuid&) = default;
0053 TUuid& operator=(TUuid&&) = default;
0054 ~TUuid() = default;
0055
0056
0057
0058
0059 explicit TUuid(const uint8_t (&data)[16]) noexcept
0060 {
0061 std::copy(std::begin(data), std::end(data), std::begin(this->data_));
0062 }
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 explicit TUuid(const std::string& str) noexcept;
0077
0078 #ifdef THRIFT_TUUID_SUPPORT_BOOST_UUID
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 #ifdef THRIFT_TUUID_BOOST_CONSTRUCTOR_EXPLICIT
0089 explicit
0090 #endif
0091 TUuid(const boost::uuids::uuid& buuid) noexcept
0092 {
0093 std::copy(buuid.begin(), buuid.end(), std::begin(this->data_));
0094 }
0095 #endif
0096
0097
0098
0099
0100 bool is_nil() const noexcept;
0101
0102
0103
0104
0105 inline bool operator==(const TUuid& other) const;
0106
0107
0108
0109
0110 inline bool operator!=(const TUuid& other) const;
0111
0112 iterator begin() noexcept { return data_; }
0113 const_iterator begin() const noexcept { return data_; }
0114 iterator end() noexcept { return data_ + size(); }
0115 const_iterator end() const noexcept { return data_ + size(); }
0116 size_type size() const noexcept { return 16; }
0117 inline const_iterator data() const { return data_; }
0118 inline iterator data() { return data_; }
0119
0120 void swap(TUuid& other) noexcept { std::swap(data_, other.data_); }
0121
0122 private:
0123
0124
0125
0126 uint8_t data_[16] = {};
0127 };
0128
0129
0130
0131
0132
0133
0134
0135 std::string to_string(const TUuid& uuid) noexcept(false);
0136
0137
0138
0139
0140 inline void swap(TUuid& lhs, TUuid& rhs) noexcept {
0141 lhs.swap(rhs);
0142 }
0143
0144
0145
0146
0147 inline bool TUuid::operator==(const TUuid& other) const {
0148
0149
0150
0151 return std::string(this->begin(), this->end()) == std::string(other.begin(), other.end());
0152 }
0153
0154
0155
0156
0157 inline bool TUuid::operator!=(const TUuid& other) const {
0158 return !(*this == other);
0159 }
0160
0161
0162
0163
0164 inline std::ostream& operator<<(std::ostream& out, const TUuid& obj) {
0165 out << to_string(obj);
0166 return out;
0167 }
0168
0169 }
0170 }
0171
0172 #endif