9 static const char rcsid[] __attribute__((used)) =
"$Id: UUID.cpp 1911 2017-09-02 17:37:35Z sella $";
12 #include "../util/CommonMacro.h"
14 using namespace sella::variant;
16 UUID::UUID() throw () :
Nullable(std::make_shared<sella::util::
UUID>()) { }
18 UUID::UUID(
const std::string &value)
throw (TypeCastException) :
Nullable() {
20 this->value = std::make_shared<sella::util::UUID>();
22 if (LIKELY(boost::regex_match(value.c_str(), UUID::Pattern()))) {
24 this->value = std::make_shared<sella::util::UUID>(value);
25 }
catch (sella::util::UUIDException &e) {
26 THROW(TypeCastException,
"unable to cast '%s' to a UUID value: %s", value.c_str(), e.what());
29 THROW(TypeCastException,
"unable to cast '%s' to a UUID value", value.c_str());
34 UUID::UUID(std::string &&value) throw (TypeCastException) :
Nullable() {
36 this->value = std::make_shared<sella::util::UUID>();
38 if (LIKELY(boost::regex_match(value.c_str(), UUID::Pattern()))) {
40 this->value = std::make_shared<sella::util::UUID>(std::move(value));
41 }
catch (sella::util::UUIDException &e) {
42 THROW(TypeCastException,
"unable to cast '%s' to a UUID value: %s", value.c_str(), e.what());
45 THROW(TypeCastException,
"unable to cast '%s' to a UUID value", value.c_str());
50 UUID::UUID(
const char *value)
throw (TypeCastException) : Nullable() {
52 this->value = std::make_shared<sella::util::UUID>();
54 if (LIKELY(boost::regex_match(value, UUID::Pattern()))) {
55 this->value = std::make_shared<sella::util::UUID>(value);
57 THROW(TypeCastException,
"unable to cast '%s' to a UUID value", value);
62 UUID::UUID(uuid_t &value)
throw () : Nullable() {
63 this->value = std::make_shared<sella::util::UUID>(value);
66 UUID::UUID(
const sella::util::UUID &value)
throw () : Nullable(std::make_shared<sella::util::UUID>(value)) { }
68 UUID::UUID(
sella::util::UUID &&value) throw () : Nullable(std::make_shared<sella::util::
UUID>(std::move(value))) { }
70 UUID::UUID(
const UUID &other)
throw () : Nullable() {
71 if (LIKELY(
this != &other)) {
72 if (LIKELY(!other.isNull())) {
73 if (UNLIKELY(isNull())) {
74 this->value = std::make_shared<sella::util::UUID>(other.get());
76 *std::static_pointer_cast<
sella::util::UUID>(this->value) = *std::static_pointer_cast<sella::util::UUID>(other.value);
84 UUID::UUID(
UUID &&other) throw () : Nullable() {
85 if (LIKELY(!other.isNull())) {
86 this->value = std::move(other.value);
90 UUID::~UUID() throw () { }
92 bool UUID::operator==(
const UUID &other)
const throw () {
93 return (*std::static_pointer_cast<sella::util::UUID>(this->value) == *std::static_pointer_cast<sella::util::UUID>(other.value));
96 bool UUID::operator!=(
const UUID &other)
const throw () {
97 return !(*
this == other);
100 bool UUID::operator>(
const UUID &other)
const throw () {
101 return (*std::static_pointer_cast<sella::util::UUID>(this->value) > *std::static_pointer_cast<sella::util::UUID>(other.value));
104 bool UUID::operator<(
const UUID &other)
const throw () {
105 return (*std::static_pointer_cast<sella::util::UUID>(this->value) < *std::static_pointer_cast<sella::util::UUID>(other.value));
108 UUID& UUID::operator=(
const UUID &other)
throw () {
109 if (LIKELY((
this != &other))) {
110 if (LIKELY(!other.isNull())) {
111 if (UNLIKELY(isNull())) {
112 this->value = std::make_shared<sella::util::UUID>(other.get());
114 *std::static_pointer_cast<
sella::util::UUID>(this->value) = *std::static_pointer_cast<sella::util::UUID>(other.value);
125 if (UNLIKELY(isNull())) {
126 this->value = std::make_shared<sella::util::UUID>(other);
142 void UUID::clear() throw() {
143 if (UNLIKELY(isNull())) {
144 this->value = std::make_shared<sella::util::UUID>();
150 void UUID::shrink_to_fit() throw () {
159 if (UNLIKELY(isNull())) {
160 c = mpack.append(offset);
162 c = mpack.append(offset, std::static_pointer_cast<sella::util::UUID>(this->value)->str());
167 if (UNLIKELY(c == 0)) {
168 THROW(TypeCastException,
"Failed to append uuid '%s' at offset %d (buffer length: %d)", str(JSON).c_str(), offset, mpack.length());
172 void UUID::msgpackBufferSize(
size_t &size)
const throw () {
173 if (UNLIKELY(isNull())) {
182 std::string UUID::str(
int type)
const throw () {
183 if (UNLIKELY(isNull())) {
187 return this->
get().str();
190 bool UUID::isType(
const char *value,
size_t size)
throw () {
191 return (size == 36 && boost::regex_match(std::string(value, size), Pattern()));