#ifdef BOOST_UUID # include # if BOOST_VERSION < 104200 # error "Boost UUIDs required v1.42 or above" # else # include # endif #include #include #include #define uuid_impl boost::uuids::uuid #include "uuid.h" UUID::UUID() { _uuid = new boost::uuids::uuid(boost::uuids::nil_generator()()); } UUID::UUID(const UUID & other) { _uuid = new boost::uuids::uuid(*other._uuid); } UUID::UUID(const std::string & str) { _uuid = new boost::uuids::uuid(boost::uuids::string_generator()(str)); } UUID UUID::generate_random() { UUID u; u._uuid = new boost::uuids::uuid(boost::uuids::random_generator()()); return u; } bool UUID::is_nil() const { return _uuid->is_nil(); } std::string UUID::str() const { return boost::lexical_cast(*_uuid); } UUID & UUID::operator=(const std::string & str) { *_uuid = boost::uuids::string_generator()(str); return *this; } #endif #ifdef OSSP_UUID # include #define uuid_impl uuid #include "uuid.h" UUID::UUID() { _uuid = new uuid(); } UUID::UUID(const UUID & other) { _uuid = new uuid(*other._uuid); } UUID::UUID(const std::string & str) { _uuid = new uuid(); _uuid->import(str.c_str()); } UUID UUID::generate_random() { UUID u; u._uuid->make(UUID_MAKE_V4); return u; } bool UUID::is_nil() const { return _uuid->isnil(); } std::string UUID::str() const { char * s = _uuid->string(); std::string r(s); free(s); return r; } UUID & UUID::operator=(const std::string & str) { _uuid->import(str.c_str()); return *this; } #endif // Shared implementation UUID::~UUID() { delete _uuid; } bool UUID::operator!=(const UUID & other) const { return *_uuid != *other._uuid; } UUID & UUID::operator=(const UUID & other) { *_uuid = *other._uuid; return *this; }