diff options
author | frsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731> | 2009-02-15 09:09:59 +0000 |
---|---|---|
committer | frsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731> | 2009-02-15 09:09:59 +0000 |
commit | c3021d3236e1276bb575802597bfaf8279fced72 (patch) | |
tree | 321525d884b1328952baef8441ef5814bf4f9d0c /cpp/object.hpp | |
parent | 1ad04b22d8d3e5267ceec7fc1527651ee0eb0ffe (diff) | |
download | msgpack-python-c3021d3236e1276bb575802597bfaf8279fced72.tar.gz |
lang/c/msgpack: added msgpack::define
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@75 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
Diffstat (limited to 'cpp/object.hpp')
-rw-r--r-- | cpp/object.hpp | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/cpp/object.hpp b/cpp/object.hpp index 13402cc..5ed1fab 100644 --- a/cpp/object.hpp +++ b/cpp/object.hpp @@ -81,21 +81,6 @@ inline object& operator>> (object o, object& v) template <typename Stream> packer<Stream>& operator<< (packer<Stream>& o, const object& v); - - -template <typename T> -inline T& operator>> (object o, T& v) -{ - v.msgpack_unpack(o); - return v; -} - -template <typename Stream, typename T> -inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) -{ - o << v.msgpack_pack(); - return o; -} template <typename T> @@ -123,6 +108,44 @@ inline void pack_copy(packer<Stream>& o, T v) pack(o, v); } + + +template <typename T> +inline T& operator>> (object o, T& v) +{ + v.msgpack_unpack(o); + return v; +} + +template <typename Stream, typename T> +inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) +{ + o << v.msgpack_pack(); + return o; +} + + +template <typename Type> +class define : public Type { +public: + typedef Type msgpack_type; + typedef define<Type> define_type; + + define() {} + define(msgpack_type v) : msgpack_type(v) {} + + msgpack_type msgpack_pack() const + { + return *this; + } + + void msgpack_unpack(object o) + { + convert(static_cast<msgpack_type&>(*this), o); + } +}; + + template <typename Stream> packer<Stream>& operator<< (packer<Stream>& o, const object& v) |