Austin Schuh | 64fab80 | 2020-09-09 22:47:47 -0700 | [diff] [blame] | 1 | #ifndef AOS_EVENTS_LOGGING_UUID_H_ |
| 2 | #define AOS_EVENTS_LOGGING_UUID_H_ |
| 3 | |
| 4 | #include <array> |
| 5 | #include <random> |
| 6 | #include <string_view> |
| 7 | |
| 8 | namespace aos { |
| 9 | |
| 10 | // Class to generate and hold a UUID. |
| 11 | class UUID { |
| 12 | public: |
| 13 | // Returns a randomly generated UUID. This is known as a UUID4. |
| 14 | static UUID Random(); |
| 15 | |
| 16 | std::string_view string_view() const { |
| 17 | return std::string_view(data_.data(), data_.size()); |
| 18 | } |
| 19 | |
| 20 | bool operator==(const UUID &other) const { |
| 21 | return other.string_view() == string_view(); |
| 22 | } |
| 23 | bool operator!=(const UUID &other) const { |
| 24 | return other.string_view() != string_view(); |
| 25 | } |
| 26 | |
| 27 | private: |
| 28 | UUID() {} |
| 29 | |
| 30 | // Fixed size storage for the data. Non-null terminated. |
| 31 | std::array<char, 36> data_; |
| 32 | }; |
| 33 | |
| 34 | } // namespace aos |
| 35 | |
| 36 | #endif // AOS_EVENTS_LOGGING_UUID_H_ |