summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-08-27 20:52:40 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-08-27 20:52:40 +0900
commitc87f7cb9ac87525c9531ddf6b2fd16499535967c (patch)
treee5ef732578faafad99d5579a9d6eb760e9ebb854 /cpp/src
parent421bee38719ee66d79cd8c376c871678dbb55a1d (diff)
downloadmsgpack-python-c87f7cb9ac87525c9531ddf6b2fd16499535967c.tar.gz
cpp: fixes fix_int; updates test/fixint.cc
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/msgpack/type/fixint.hpp85
1 files changed, 84 insertions, 1 deletions
diff --git a/cpp/src/msgpack/type/fixint.hpp b/cpp/src/msgpack/type/fixint.hpp
index da58415..ebe2696 100644
--- a/cpp/src/msgpack/type/fixint.hpp
+++ b/cpp/src/msgpack/type/fixint.hpp
@@ -19,6 +19,7 @@
#define MSGPACK_TYPE_FIXINT_HPP__
#include "msgpack/object.hpp"
+#include "msgpack/type/int.hpp"
namespace msgpack {
@@ -29,10 +30,13 @@ template <typename T>
struct fix_int {
fix_int() : value(0) { }
fix_int(T value) : value(value) { }
+
operator T() const { return value; }
+
T get() const { return value; }
+
private:
- const T value;
+ T value;
};
@@ -50,6 +54,32 @@ typedef fix_int<int64_t> fix_int64;
} // namespace type
+inline type::fix_int8& operator>> (object o, type::fix_int8& v)
+ { v = type::detail::convert_integer<int8_t>(o); return v; }
+
+inline type::fix_int16& operator>> (object o, type::fix_int16& v)
+ { v = type::detail::convert_integer<int16_t>(o); return v; }
+
+inline type::fix_int32& operator>> (object o, type::fix_int32& v)
+ { v = type::detail::convert_integer<int32_t>(o); return v; }
+
+inline type::fix_int64& operator>> (object o, type::fix_int64& v)
+ { v = type::detail::convert_integer<int64_t>(o); return v; }
+
+
+inline type::fix_uint8& operator>> (object o, type::fix_uint8& v)
+ { v = type::detail::convert_integer<uint8_t>(o); return v; }
+
+inline type::fix_uint16& operator>> (object o, type::fix_uint16& v)
+ { v = type::detail::convert_integer<uint16_t>(o); return v; }
+
+inline type::fix_uint32& operator>> (object o, type::fix_uint32& v)
+ { v = type::detail::convert_integer<uint32_t>(o); return v; }
+
+inline type::fix_uint64& operator>> (object o, type::fix_uint64& v)
+ { v = type::detail::convert_integer<uint64_t>(o); return v; }
+
+
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int8& v)
{ o.pack_fix_int8(v); return o; }
@@ -66,6 +96,7 @@ template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v)
{ o.pack_fix_int64(v); return o; }
+
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v)
{ o.pack_fix_uint8(v); return o; }
@@ -83,6 +114,58 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
{ o.pack_fix_uint64(v); return o; }
+inline void operator<< (object& o, type::fix_int8 v)
+ { v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_int16 v)
+ { v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_int32 v)
+ { v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_int64 v)
+ { v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+
+inline void operator<< (object& o, type::fix_uint8 v)
+ { o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_uint16 v)
+ { o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_uint32 v)
+ { o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+inline void operator<< (object& o, type::fix_uint64 v)
+ { o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
+
+
+inline void operator<< (object::with_zone& o, type::fix_int8 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_int16 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_int32 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_int64 v)
+ { static_cast<object&>(o) << v; }
+
+
+inline void operator<< (object::with_zone& o, type::fix_uint8 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_uint16 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_uint32 v)
+ { static_cast<object&>(o) << v; }
+
+inline void operator<< (object::with_zone& o, type::fix_uint64 v)
+ { static_cast<object&>(o) << v; }
+
+
} // namespace msgpack
#endif /* msgpack/type/fixint.hpp */