mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 23:42:40 +02:00
Modified passed by value of object to const reference of object.
Removed C function call in operator==.
This commit is contained in:
parent
56b0ad6809
commit
8a08548f36
@ -24,7 +24,7 @@
|
|||||||
{ \
|
{ \
|
||||||
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
||||||
} \
|
} \
|
||||||
void msgpack_unpack(msgpack::object o) \
|
void msgpack_unpack(msgpack::object const& o) \
|
||||||
{ \
|
{ \
|
||||||
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
||||||
}\
|
}\
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#define MSGPACK_ADD_ENUM(enum) \
|
#define MSGPACK_ADD_ENUM(enum) \
|
||||||
namespace msgpack { \
|
namespace msgpack { \
|
||||||
template <> \
|
template <> \
|
||||||
inline enum& operator>> (object o, enum& v) \
|
inline enum& operator>> (object const& o, enum& v) \
|
||||||
{ \
|
{ \
|
||||||
int tmp; \
|
int tmp; \
|
||||||
o >> tmp; \
|
o >> tmp; \
|
||||||
@ -71,7 +71,7 @@ struct define_imp {
|
|||||||
define_imp<Tuple, N-1>::pack(pk, t);
|
define_imp<Tuple, N-1>::pack(pk, t);
|
||||||
pk.pack(std::get<N-1>(t));
|
pk.pack(std::get<N-1>(t));
|
||||||
}
|
}
|
||||||
static void unpack(msgpack::object o, Tuple& t) {
|
static void unpack(msgpack::object const& o, Tuple& t) {
|
||||||
define_imp<Tuple, N-1>::unpack(o, t);
|
define_imp<Tuple, N-1>::unpack(o, t);
|
||||||
const size_t size = o.via.array.size;
|
const size_t size = o.via.array.size;
|
||||||
if(size <= N-1) { return; }
|
if(size <= N-1) { return; }
|
||||||
@ -89,7 +89,7 @@ struct define_imp<Tuple, 1> {
|
|||||||
static void pack(Packer& pk, Tuple const& t) {
|
static void pack(Packer& pk, Tuple const& t) {
|
||||||
pk.pack(std::get<0>(t));
|
pk.pack(std::get<0>(t));
|
||||||
}
|
}
|
||||||
static void unpack(msgpack::object o, Tuple& t) {
|
static void unpack(msgpack::object const& o, Tuple& t) {
|
||||||
const size_t size = o.via.array.size;
|
const size_t size = o.via.array.size;
|
||||||
if(size <= 0) { return; }
|
if(size <= 0) { return; }
|
||||||
o.via.array.ptr[0].convert(&std::get<0>(t));
|
o.via.array.ptr[0].convert(&std::get<0>(t));
|
||||||
@ -112,7 +112,7 @@ struct define {
|
|||||||
|
|
||||||
define_imp<tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
|
define_imp<tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
|
||||||
}
|
}
|
||||||
void msgpack_unpack(msgpack::object o)
|
void msgpack_unpack(msgpack::object const& o)
|
||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ struct define<> {
|
|||||||
{
|
{
|
||||||
pk.pack_array(0);
|
pk.pack_array(0);
|
||||||
}
|
}
|
||||||
void msgpack_unpack(msgpack::object o)
|
void msgpack_unpack(msgpack::object const& o)
|
||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ const packer<Stream>& operator<< (
|
|||||||
template <typename Tuple, std::size_t N>
|
template <typename Tuple, std::size_t N>
|
||||||
struct Converter {
|
struct Converter {
|
||||||
static void convert(
|
static void convert(
|
||||||
object o,
|
object const& o,
|
||||||
Tuple& v) {
|
Tuple& v) {
|
||||||
Converter<Tuple, N-1>::convert(o, v);
|
Converter<Tuple, N-1>::convert(o, v);
|
||||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(&type::get<N-1>(v));
|
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(&type::get<N-1>(v));
|
||||||
@ -148,7 +148,7 @@ struct Converter {
|
|||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
struct Converter<Tuple, 1> {
|
struct Converter<Tuple, 1> {
|
||||||
static void convert (
|
static void convert (
|
||||||
object o,
|
object const& o,
|
||||||
Tuple& v) {
|
Tuple& v) {
|
||||||
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(type::get<0>(v))>::type>(&type::get<0>(v));
|
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(type::get<0>(v))>::type>(&type::get<0>(v));
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ struct Converter<Tuple, 1> {
|
|||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
type::tuple<Args...>& operator>> (
|
type::tuple<Args...>& operator>> (
|
||||||
object o,
|
object const& o,
|
||||||
type::tuple<Args...>& v) {
|
type::tuple<Args...>& v) {
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
if(o.via.array.size < sizeof...(Args)) { throw type_error(); }
|
if(o.via.array.size < sizeof...(Args)) { throw type_error(); }
|
||||||
|
@ -125,22 +125,22 @@ 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>
|
template <typename T>
|
||||||
bool operator==(const object x, const T& y);
|
bool operator==(const object& x, const T& y);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator==(const T& y, const object x);
|
bool operator==(const T& y, const object& x);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator!=(const object x, const T& y);
|
bool operator!=(const object& x, const T& y);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool operator!=(const T& y, const object x);
|
bool operator!=(const T& y, const object& x);
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream& s, const object o);
|
std::ostream& operator<< (std::ostream& s, const object& o);
|
||||||
|
|
||||||
|
|
||||||
// serialize operator
|
// serialize operator
|
||||||
@ -149,7 +149,7 @@ packer<Stream>& operator<< (packer<Stream>& o, const T& v);
|
|||||||
|
|
||||||
// convert operator
|
// convert operator
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T& operator>> (object o, T& v);
|
T& operator>> (object const& o, T& v);
|
||||||
|
|
||||||
// deconvert operator
|
// deconvert operator
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -157,7 +157,7 @@ void operator<< (object::with_zone& o, const T& v);
|
|||||||
|
|
||||||
|
|
||||||
struct object::implicit_type {
|
struct object::implicit_type {
|
||||||
implicit_type(object o) : obj(o) { }
|
implicit_type(object const& o) : obj(o) { }
|
||||||
~implicit_type() { }
|
~implicit_type() { }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -184,7 +184,7 @@ public:
|
|||||||
o << static_cast<const msgpack_type&>(*this);
|
o << static_cast<const msgpack_type&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgpack_unpack(object o)
|
void msgpack_unpack(object const& o)
|
||||||
{
|
{
|
||||||
o >> static_cast<msgpack_type&>(*this);
|
o >> static_cast<msgpack_type&>(*this);
|
||||||
}
|
}
|
||||||
@ -199,14 +199,14 @@ inline packer<Stream>& packer<Stream>::pack(const T& v)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline object& operator>> (object o, object& v)
|
inline object& operator>> (object const& o, object& v)
|
||||||
{
|
{
|
||||||
v = o;
|
v = o;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T& operator>> (object o, T& v)
|
inline T& operator>> (object const& o, T& v)
|
||||||
{
|
{
|
||||||
v.msgpack_unpack(o.convert());
|
v.msgpack_unpack(o.convert());
|
||||||
return v;
|
return v;
|
||||||
@ -235,20 +235,82 @@ void operator<< (object::with_zone& o, const T& v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool operator==(const object x, const object y)
|
inline bool operator==(const object& x, const object& y)
|
||||||
{
|
{
|
||||||
return msgpack_object_equal(x, y);
|
if(x.type != y.type) { return false; }
|
||||||
|
|
||||||
|
switch(x.type) {
|
||||||
|
case type::NIL:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case type::BOOLEAN:
|
||||||
|
return x.via.boolean == y.via.boolean;
|
||||||
|
|
||||||
|
case type::POSITIVE_INTEGER:
|
||||||
|
return x.via.u64 == y.via.u64;
|
||||||
|
|
||||||
|
case type::NEGATIVE_INTEGER:
|
||||||
|
return x.via.i64 == y.via.i64;
|
||||||
|
|
||||||
|
case type::DOUBLE:
|
||||||
|
return x.via.dec == y.via.dec;
|
||||||
|
|
||||||
|
case type::RAW:
|
||||||
|
return x.via.raw.size == y.via.raw.size &&
|
||||||
|
memcmp(x.via.raw.ptr, y.via.raw.ptr, x.via.raw.size) == 0;
|
||||||
|
|
||||||
|
case type::ARRAY:
|
||||||
|
if(x.via.array.size != y.via.array.size) {
|
||||||
|
return false;
|
||||||
|
} else if(x.via.array.size == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
object* px = x.via.array.ptr;
|
||||||
|
object* const pxend = x.via.array.ptr + x.via.array.size;
|
||||||
|
object* py = y.via.array.ptr;
|
||||||
|
do {
|
||||||
|
if(!(*px == *py)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++px;
|
||||||
|
++py;
|
||||||
|
} while(px < pxend);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case type::MAP:
|
||||||
|
if(x.via.map.size != y.via.map.size) {
|
||||||
|
return false;
|
||||||
|
} else if(x.via.map.size == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
object_kv* px = x.via.map.ptr;
|
||||||
|
object_kv* const pxend = x.via.map.ptr + x.via.map.size;
|
||||||
|
object_kv* py = y.via.map.ptr;
|
||||||
|
do {
|
||||||
|
if(!(px->key == py->key) || !(px->val == py->val)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++px;
|
||||||
|
++py;
|
||||||
|
} while(px < pxend);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator==(const object x, const T& y)
|
inline bool operator==(const object& x, const T& y)
|
||||||
try {
|
try {
|
||||||
return x == object(y);
|
return x == object(y);
|
||||||
} catch (msgpack::type_error&) {
|
} catch (msgpack::type_error&) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
template <typename T>
|
||||||
@ -256,11 +318,11 @@ inline bool operator==(const T& y, const object x)
|
|||||||
{ return x == y; }
|
{ return x == y; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator!=(const object x, const T& y)
|
inline bool operator!=(const object& x, const T& y)
|
||||||
{ return !(x == y); }
|
{ return !(x == y); }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool operator!=(const T& y, const object x)
|
inline bool operator!=(const T& y, const object& x)
|
||||||
{ return x != y; }
|
{ return x != y; }
|
||||||
|
|
||||||
|
|
||||||
@ -335,7 +397,7 @@ inline object::operator msgpack_object() const
|
|||||||
|
|
||||||
// obsolete
|
// obsolete
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void convert(T& v, object o)
|
inline void convert(T& v, object const& o)
|
||||||
{
|
{
|
||||||
o.convert(&v);
|
o.convert(&v);
|
||||||
}
|
}
|
||||||
@ -412,7 +474,7 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream& s, const object o)
|
std::ostream& operator<< (std::ostream& s, const object& o)
|
||||||
{
|
{
|
||||||
switch(o.type) {
|
switch(o.type) {
|
||||||
case type::NIL:
|
case type::NIL:
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
{ \
|
{ \
|
||||||
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
||||||
} \
|
} \
|
||||||
void msgpack_unpack(msgpack::object o) \
|
void msgpack_unpack(msgpack::object const& o) \
|
||||||
{ \
|
{ \
|
||||||
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
||||||
}\
|
}\
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#define MSGPACK_ADD_ENUM(enum) \
|
#define MSGPACK_ADD_ENUM(enum) \
|
||||||
namespace msgpack { \
|
namespace msgpack { \
|
||||||
template <> \
|
template <> \
|
||||||
inline enum& operator>> (object o, enum& v) \
|
inline enum& operator>> (object const& o, enum& v) \
|
||||||
{ \
|
{ \
|
||||||
int tmp; \
|
int tmp; \
|
||||||
o >> tmp; \
|
o >> tmp; \
|
||||||
@ -78,7 +78,7 @@ struct define<> {
|
|||||||
{
|
{
|
||||||
pk.pack_array(0);
|
pk.pack_array(0);
|
||||||
}
|
}
|
||||||
void msgpack_unpack(msgpack::object o)
|
void msgpack_unpack(msgpack::object const& o)
|
||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
|||||||
<%0.upto(i) {|j|%>
|
<%0.upto(i) {|j|%>
|
||||||
pk.pack(a<%=j%>);<%}%>
|
pk.pack(a<%=j%>);<%}%>
|
||||||
}
|
}
|
||||||
void msgpack_unpack(msgpack::object o)
|
void msgpack_unpack(msgpack::object const& o)
|
||||||
{
|
{
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
const size_t size = o.via.array.size;
|
const size_t size = o.via.array.size;
|
||||||
|
@ -92,7 +92,7 @@ private:
|
|||||||
template <>
|
template <>
|
||||||
struct tuple<> {
|
struct tuple<> {
|
||||||
tuple() {}
|
tuple() {}
|
||||||
tuple(object o) { o.convert(this); }
|
tuple(object const& o) { o.convert(this); }
|
||||||
typedef tuple<> value_type;
|
typedef tuple<> value_type;
|
||||||
};
|
};
|
||||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||||
@ -102,7 +102,7 @@ struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
|||||||
tuple() {}
|
tuple() {}
|
||||||
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
||||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||||
tuple(object o) { o.convert(this); }
|
tuple(object const& o) { o.convert(this); }
|
||||||
template <int N> typename tuple_element<value_type, N>::reference get()
|
template <int N> typename tuple_element<value_type, N>::reference get()
|
||||||
{ return tuple_element<value_type, N>(*this).get(); }
|
{ return tuple_element<value_type, N>(*this).get(); }
|
||||||
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
|
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
|
||||||
@ -134,7 +134,7 @@ tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::tr
|
|||||||
} // namespace type
|
} // namespace type
|
||||||
|
|
||||||
inline type::tuple<>& operator>> (
|
inline type::tuple<>& operator>> (
|
||||||
object o,
|
object const& o,
|
||||||
type::tuple<>& v) {
|
type::tuple<>& v) {
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
return v;
|
return v;
|
||||||
@ -142,7 +142,7 @@ inline type::tuple<>& operator>> (
|
|||||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& operator>> (
|
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& operator>> (
|
||||||
object o,
|
object const& o,
|
||||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||||
if(o.type != type::ARRAY) { throw type_error(); }
|
if(o.type != type::ARRAY) { throw type_error(); }
|
||||||
if(o.via.array.size < <%=i+1%>) { throw type_error(); }
|
if(o.via.array.size < <%=i+1%>) { throw type_error(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user