src/utilities/core/UUID.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_CORE_UUID_HPP | ||
| 7 | #define UTILITIES_CORE_UUID_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | #include <boost/regex.hpp> | ||
| 11 | |||
| 12 | #include <boost/optional.hpp> | ||
| 13 | #include <boost/uuid/uuid.hpp> | ||
| 14 | #include <vector> | ||
| 15 | #include <ostream> | ||
| 16 | #include <string> | ||
| 17 | |||
| 18 | namespace openstudio { | ||
| 19 | class UTILITIES_API UUID; | ||
| 20 | |||
| 21 | /// create a UUID | ||
| 22 | UTILITIES_API UUID createUUID(); | ||
| 23 | |||
| 24 | /// create a UUID from a std::string, does not throw, may return a null UUID | ||
| 25 | UTILITIES_API UUID toUUID(const std::string& str); | ||
| 26 | |||
| 27 | /// create a std::string from a UUID | ||
| 28 | UTILITIES_API std::string toString(const UUID& uuid); | ||
| 29 | |||
| 30 | /// create a unique name, prefix << " " << UUID. | ||
| 31 | UTILITIES_API std::string createUniqueName(const std::string& prefix); | ||
| 32 | |||
| 33 | /// create a std::string without curly brackets from a UUID | ||
| 34 | UTILITIES_API std::string removeBraces(const UUID& uuid); | ||
| 35 | |||
| 36 | UTILITIES_API std::ostream& operator<<(std::ostream& os, const UUID& uuid); | ||
| 37 | |||
| 38 | UTILITIES_API bool operator!=(const UUID& lhs, const UUID& rhs); | ||
| 39 | UTILITIES_API bool operator<(const UUID& lhs, const UUID& rhs); | ||
| 40 | UTILITIES_API bool operator==(const UUID& lhs, const UUID& rhs); | ||
| 41 | UTILITIES_API bool operator>(const UUID& lhs, const UUID& rhs); | ||
| 42 | |||
| 43 | /// Universally Unique Identifier | ||
| 44 | class UTILITIES_API UUID : public boost::uuids::uuid | ||
| 45 | { | ||
| 46 | public: | ||
| 47 | UUID(); | ||
| 48 | |||
| 49 | 61481574 | bool isNull() const { | |
| 50 | 61481574 | return is_nil(); | |
| 51 | } | ||
| 52 | |||
| 53 | 4013 | bool isEqual(const UUID& other) const { | |
| 54 | 4013 | return (*this == other); | |
| 55 | } | ||
| 56 | |||
| 57 | using boost::uuids::uuid::iterator; | ||
| 58 | using boost::uuids::uuid::const_iterator; | ||
| 59 | using boost::uuids::uuid::begin; | ||
| 60 | using boost::uuids::uuid::end; | ||
| 61 | |||
| 62 | private: | ||
| 63 | explicit UUID(const boost::uuids::uuid&); | ||
| 64 | |||
| 65 | UTILITIES_API friend UUID openstudio::createUUID(); | ||
| 66 | UTILITIES_API friend UUID openstudio::toUUID(const std::string& str); | ||
| 67 | UTILITIES_API friend std::string openstudio::toString(const UUID& uuid); | ||
| 68 | UTILITIES_API friend std::string openstudio::createUniqueName(const std::string& prefix); | ||
| 69 | UTILITIES_API friend std::string openstudio::removeBraces(const UUID& uuid); | ||
| 70 | UTILITIES_API friend bool openstudio::operator!=(const UUID& lhs, const UUID& rhs); | ||
| 71 | UTILITIES_API friend bool openstudio::operator<(const UUID& lhs, const UUID& rhs); | ||
| 72 | UTILITIES_API friend bool openstudio::operator==(const UUID& lhs, const UUID& rhs); | ||
| 73 | UTILITIES_API friend bool openstudio::operator>(const UUID& lhs, const UUID& rhs); | ||
| 74 | |||
| 75 | static UUID random_generate(); | ||
| 76 | static UUID string_generate(const std::string&); | ||
| 77 | }; | ||
| 78 | |||
| 79 | /// Find version 4 UUIDs in a string. | ||
| 80 | UTILITIES_API const boost::regex& uuidInString(); | ||
| 81 | |||
| 82 | /// create a unique name, prefix << " " << UUID. | ||
| 83 | UTILITIES_API std::string createUniqueName(const std::string& prefix); | ||
| 84 | |||
| 85 | /// optional UUID | ||
| 86 | using OptionalUUID = boost::optional<UUID>; | ||
| 87 | |||
| 88 | /// vector of UUID | ||
| 89 | using UUIDVector = std::vector<UUID>; | ||
| 90 | |||
| 91 | } // namespace openstudio | ||
| 92 | |||
| 93 | #endif // UTILITIES_CORE_UUID_HPP | ||
| 94 |