diff options
| author | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-25 02:30:53 +0900 |
|---|---|---|
| committer | frsyuki <frsyuki@users.sourceforge.jp> | 2010-04-25 02:30:53 +0900 |
| commit | 7d945d3c8e24de21ba5862d699521502bce17fe5 (patch) | |
| tree | 9e3d59f0fa6a5228aa994f91e9cc5952df89df5a /cpp/msgpack | |
| parent | 05e28752f111f6faa8b61432a7063a30b9f51ebf (diff) | |
| download | msgpack-python-7d945d3c8e24de21ba5862d699521502bce17fe5.tar.gz | |
cpp: explicit object(const T& v)
Diffstat (limited to 'cpp/msgpack')
| -rw-r--r-- | cpp/msgpack/object.hpp | 37 | ||||
| -rw-r--r-- | cpp/msgpack/type/define.hpp.erb | 3 |
2 files changed, 35 insertions, 5 deletions
diff --git a/cpp/msgpack/object.hpp b/cpp/msgpack/object.hpp index bfbaeb1..3567ac8 100644 --- a/cpp/msgpack/object.hpp +++ b/cpp/msgpack/object.hpp @@ -90,8 +90,10 @@ struct object { object(); + object(msgpack_object o); + template <typename T> - object(const T& v); + explicit object(const T& v); template <typename T> object(const T& v, zone* z); @@ -131,6 +133,15 @@ bool operator!=(const object x, const object y); template <typename T> bool operator==(const object x, const T& y); +template <typename T> +bool operator==(const T& y, const object x); + +template <typename T> +bool operator!=(const object x, const T& y); + +template <typename T> +bool operator!=(const T& y, const object x); + std::ostream& operator<< (std::ostream& s, const object o); @@ -217,9 +228,6 @@ void operator<< (object::with_zone& o, const T& v) } -inline bool operator!=(const object x, const object y) -{ return !(x == y); } - template <typename T> inline bool operator==(const object x, const T& y) try { @@ -228,6 +236,21 @@ try { return false; } +inline bool operator!=(const object x, const object y) +{ return !(x == y); } + +template <typename T> +inline bool operator==(const T& y, const object x) +{ return x == y; } + +template <typename T> +inline bool operator!=(const object x, const T& y) +{ return !(x == y); } + +template <typename T> +inline bool operator!=(const T& y, const object x) +{ return x != y; } + inline object::implicit_type object::convert() const { @@ -277,6 +300,12 @@ object::object(const T& v, zone* z) } +inline object::object(msgpack_object o) +{ + // FIXME beter way? + ::memcpy(this, &o, sizeof(o)); +} + inline object::operator msgpack_object() { // FIXME beter way? diff --git a/cpp/msgpack/type/define.hpp.erb b/cpp/msgpack/type/define.hpp.erb index 369e12f..9db6f08 100644 --- a/cpp/msgpack/type/define.hpp.erb +++ b/cpp/msgpack/type/define.hpp.erb @@ -28,7 +28,8 @@ { \ msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \ }\ - void msgpack_object(msgpack::object* o, msgpack::zone* z) const \ + template <typename MSGPACK_OBJECT> \ + void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone* z) const \ { \ msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \ } |
