9 static const char rcsid[] __attribute__((used)) =
"$Id: Pointer.cpp 1702 2016-08-13 23:26:06Z sella $";
12 #include "../util/CommonMacro.h"
14 using namespace sella::variant;
16 Pointer::Pointer() throw () :
Nullable(std::make_shared<
void*>((
void*) NULL)) { }
18 Pointer::Pointer(
const std::string &value)
throw (TypeCastException) :
Nullable() {
19 if (boost::regex_match(value, Pointer::Pattern())) {
22 if (scanf(value.c_str(),
"%p", &v) < 1) {
23 THROW(TypeCastException,
"unable to cast '%s' to a pointer value", value.c_str());
26 this->value = std::make_shared<void*>(v);
28 THROW(TypeCastException,
"unable to cast '%s' to a pointer value", value.c_str());
32 Pointer::Pointer(
void* value)
throw () :
Nullable(std::make_shared<void*>(value)) { }
36 if (!other.isNull()) {
38 this->value = std::make_shared<void*>((
void*) other.get());
40 *std::static_pointer_cast<
void*>(this->value) = *std::static_pointer_cast<void*>(other.value);
48 bool Pointer::operator==(
const Pointer &other)
const throw () {
49 return (*std::static_pointer_cast<void*>(this->value) == *std::static_pointer_cast<void*>(other.value));
52 bool Pointer::operator!=(
const Pointer &other)
const throw () {
53 return !(*
this == other);
56 bool Pointer::operator>(
const Pointer &other)
const throw () {
57 return (*std::static_pointer_cast<void*>(this->value) > *std::static_pointer_cast<void*>(other.value));
60 bool Pointer::operator<(
const Pointer &other)
const throw () {
61 return (*std::static_pointer_cast<void*>(this->value) < *std::static_pointer_cast<void*>(other.value));
64 bool Pointer::operator!() throw () {
65 return !(*std::static_pointer_cast<
void*>(this->value));
70 if (!other.isNull()) {
72 this->value = std::make_shared<void*>((
void*) other.get());
74 *std::static_pointer_cast<
void*>(this->value) = *std::static_pointer_cast<void*>(other.value);
84 Pointer& Pointer::operator=(
void *other)
throw () {
86 this->value = std::make_shared<void*>(other);
88 *std::static_pointer_cast<
void*>(this->value) = other;
94 Pointer::~Pointer() throw () { }
96 const void*& Pointer::get()
const throw (UnsupportedOperatorException) {
98 THROW(UnsupportedOperatorException,
"unable to take reference of null value");
101 return *std::static_pointer_cast<
const void*>(this->value);
104 void*& Pointer::get() throw (UnsupportedOperatorException) {
106 THROW(UnsupportedOperatorException,
"unable to take reference of null value");
109 return *std::static_pointer_cast<
void*>(this->value);
115 if (this->isNull()) {
116 if ((c = mpack.append(offset)) == 0) {
117 THROW(TypeCastException,
"Failed to append '%s' at offset %d (buffer length: %d)", str(JSON).c_str(), offset, mpack.length());
120 if ((c = mpack.append(offset, (uint64_t) this->get())) == 0) {
121 THROW(TypeCastException,
"Failed to append '%s' at offset %d (buffer length: %d)", str(JSON).c_str(), offset, mpack.length());
128 void Pointer::msgpackBufferSize(
size_t &size)
const throw () {
129 if (UNLIKELY(isNull())) {
138 std::string Pointer::str(
int type)
const throw () {
139 if (this->isNull()) {
145 snprintf(buffer,
sizeof(buffer),
"%p", this->
get());
150 bool Pointer::isType(
const char *value,
size_t size)
throw () {
151 if (size < 2 || value[0] !=
'0' || value[1] !=
'x' || (size - 2) % 8 != 0) {
155 for (
size_t i = 2; i < size; i += 2) {
156 if (!::isxdigit(value[i]) != 0 || !::isxdigit(value[i + 1]) != 0) {