From 01b6673528127538457fdf445531f3574dc0c20a Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sun, 25 Apr 2010 01:24:24 +0900 Subject: cpp: bool operator==(object& x, const T& y) --- cpp/msgpack/object.hpp | 11 +++++++++++ cpp/msgpack/type/string.hpp | 7 +++++++ 2 files changed, 18 insertions(+) (limited to 'cpp/msgpack') diff --git a/cpp/msgpack/object.hpp b/cpp/msgpack/object.hpp index a094c56..df1079b 100644 --- a/cpp/msgpack/object.hpp +++ b/cpp/msgpack/object.hpp @@ -128,6 +128,9 @@ private: bool operator==(const object x, const object y); bool operator!=(const object x, const object y); +template +bool operator==(const object x, const T& y); + std::ostream& operator<< (std::ostream& s, const object o); @@ -207,6 +210,14 @@ inline packer& operator<< (packer& o, const T& v) inline bool operator!=(const object x, const object y) { return !(x == y); } +template +inline bool operator==(const object x, const T& y) +try { + return x == object(y); +} catch (msgpack::type_error&) { + return false; +} + inline object::implicit_type object::convert() const { diff --git a/cpp/msgpack/type/string.hpp b/cpp/msgpack/type/string.hpp index 796603f..8ca2724 100644 --- a/cpp/msgpack/type/string.hpp +++ b/cpp/msgpack/type/string.hpp @@ -48,6 +48,13 @@ inline void operator<< (object::object_zone& o, const std::string& v) memcpy(ptr, v.data(), v.size()); } +inline void operator<< (object& o, const std::string& v) +{ + o.type = type::RAW; + o.via.raw.ptr = v.data(); + o.via.raw.size = v.size(); +} + } // namespace msgpack -- cgit v1.2.1