cpp: bool operator==(object& x, const T& y)

This commit is contained in:
frsyuki 2010-04-25 01:24:24 +09:00
parent 4e85ebbf98
commit 01b6673528
3 changed files with 21 additions and 0 deletions

View File

@ -128,6 +128,9 @@ private:
bool operator==(const object x, const object y); bool operator==(const object x, const object y);
bool operator!=(const object x, const object y); bool operator!=(const object x, const object y);
template <typename T>
bool operator==(const object x, const T& y);
std::ostream& operator<< (std::ostream& s, const object o); std::ostream& operator<< (std::ostream& s, const object o);
@ -207,6 +210,14 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const T& v)
inline bool operator!=(const object x, const object y) inline bool operator!=(const object x, const object y)
{ return !(x == y); } { return !(x == y); }
template <typename T>
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 inline object::implicit_type object::convert() const
{ {

View File

@ -48,6 +48,13 @@ inline void operator<< (object::object_zone& o, const std::string& v)
memcpy(ptr, v.data(), v.size()); 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 } // namespace msgpack

View File

@ -103,6 +103,9 @@ bool operator==(const object x, const object y)
case type::NEGATIVE_INTEGER: case type::NEGATIVE_INTEGER:
return x.via.i64 == y.via.i64; return x.via.i64 == y.via.i64;
case type::DOUBLE:
return x.via.dec == y.via.dec;
case type::RAW: case type::RAW:
return x.via.raw.size == y.via.raw.size && return x.via.raw.size == y.via.raw.size &&
memcmp(x.via.raw.ptr, y.via.raw.ptr, x.via.raw.size) == 0; memcmp(x.via.raw.ptr, y.via.raw.ptr, x.via.raw.size) == 0;