diff options
author | frsyuki <frsyuki@vcore.(none)> | 2009-02-22 15:36:02 +0900 |
---|---|---|
committer | frsyuki <frsyuki@vcore.(none)> | 2009-02-22 15:36:02 +0900 |
commit | d078eb0ad5b2b1c7749942a4618f6cfedd1067d5 (patch) | |
tree | 1766630e47cefe268125672cca8dcafb7479c1db | |
parent | 11abec1093cf8c9914b5aeeac383d30abc1cad72 (diff) | |
download | msgpack-python-d078eb0ad5b2b1c7749942a4618f6cfedd1067d5.tar.gz |
type conversion operator msgpack_object <-> msgpack::object
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | cpp/object.hpp | 24 | ||||
-rw-r--r-- | cpp/unpack.hpp | 3 |
3 files changed, 26 insertions, 3 deletions
diff --git a/configure.in b/configure.in index 9fa6ac5..d7bb926 100644 --- a/configure.in +++ b/configure.in @@ -32,7 +32,7 @@ fi # FIXME AC_PROG_CXX -CXXFLAGS="-O4 -Wall $CXXFLAGS -I.." +CXXFLAGS="-O4 -Wall $CXXFLAGS -I.. -I../c" AM_CONDITIONAL(ENABLE_CXX, test "$enable_cxx" != "no") diff --git a/cpp/object.hpp b/cpp/object.hpp index 08e715d..c3f2872 100644 --- a/cpp/object.hpp +++ b/cpp/object.hpp @@ -18,8 +18,10 @@ #ifndef MSGPACK_OBJECT_HPP__ #define MSGPACK_OBJECT_HPP__ +#include "msgpack/object.h" #include "msgpack/pack.hpp" #include <stdint.h> +#include <string.h> #include <stdexcept> #include <typeinfo> #include <limits> @@ -72,6 +74,7 @@ struct object { object_array array; object_map map; object_raw raw; + object_raw ref; // obsolete }; type::object_type type; @@ -85,6 +88,10 @@ struct object { template <typename T> void convert(T* v); + object(); + object(msgpack_object obj); + operator msgpack_object(); + private: struct implicit_type; @@ -192,6 +199,23 @@ inline bool operator!=(const object x, const object y) { return !(x == y); } +inline object::object() { } + +inline object::object(msgpack_object obj) +{ + // FIXME beter way? + ::memcpy(this, &obj, sizeof(obj)); +} + +inline object::operator msgpack_object() +{ + // FIXME beter way? + msgpack_object obj; + ::memcpy(&obj, this, sizeof(obj)); + return obj; +} + + inline object::implicit_type object::convert() { return implicit_type(*this); diff --git a/cpp/unpack.hpp b/cpp/unpack.hpp index 8c77726..57623f2 100644 --- a/cpp/unpack.hpp +++ b/cpp/unpack.hpp @@ -191,8 +191,7 @@ inline bool unpacker::execute() inline object unpacker::data() { - msgpack_object obj = msgpack_unpacker_data(this); - return *reinterpret_cast<object*>(&obj); + return msgpack_unpacker_data(this); } inline zone* unpacker::release_zone() |