diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/object.hpp | 41 | ||||
-rw-r--r-- | cpp/test.cpp | 4 | ||||
-rw-r--r-- | cpp/type/array.hpp | 2 | ||||
-rw-r--r-- | cpp/type/boolean.hpp | 4 | ||||
-rw-r--r-- | cpp/type/integer.hpp | 18 | ||||
-rw-r--r-- | cpp/type/map.hpp | 12 | ||||
-rw-r--r-- | cpp/type/tuple.hpp.erb | 2 | ||||
-rw-r--r-- | cpp/unpack.hpp | 2 |
8 files changed, 38 insertions, 47 deletions
diff --git a/cpp/object.hpp b/cpp/object.hpp index 8cce14c..77d55bb 100644 --- a/cpp/object.hpp +++ b/cpp/object.hpp @@ -83,51 +83,44 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v); -namespace type { - template <typename T> - inline T& operator>> (object o, T& v) - { - v.msgpack_unpack(o); - return v; - } - - template <typename Stream, typename T> - inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) - { - pack_copy(v.msgpack_pack(), o); - return o; - } +template <typename T> +inline T& operator>> (object o, T& v) +{ + v.msgpack_unpack(o); + return v; +} + +template <typename Stream, typename T> +inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) +{ + o << v.msgpack_pack(); + return o; } template <typename T> inline void convert(T& v, object o) { - using namespace type; o >> v; } - template <typename Stream, typename T> -inline void pack(T& v, packer<Stream>& o) +inline void pack(packer<Stream>& o, const T& v) { - using namespace type; o << v; } - template <typename Stream, typename T> -inline void pack(T& v, Stream& s) +inline void pack(Stream& s, const T& v) { packer<Stream> pk(s); - pack(v, pk); + pack(pk, v); } - template <typename Stream, typename T> -inline void pack_copy(T v, packer<Stream>& o) +inline void pack_copy(packer<Stream>& o, T v) { - pack(v, o); + pack(o, v); } diff --git a/cpp/test.cpp b/cpp/test.cpp index c632ec5..02d461c 100644 --- a/cpp/test.cpp +++ b/cpp/test.cpp @@ -26,7 +26,7 @@ public: try { std::stringstream s; - pack(should, s); + pack(s, should); std::string str(s.str()); object ro = unpack(str.data(), str.size(), m_zone); std::cout << ro << std::endl; @@ -139,7 +139,7 @@ int main(void) // send message { for(unsigned i=0; i < TASK_REPEAT; ++i) { - pack(task, stream); + pack(stream, task); } std::cout << "send " << stream.str().size() << " bytes" << std::endl; } diff --git a/cpp/type/array.hpp b/cpp/type/array.hpp index 703ac55..0522d4c 100644 --- a/cpp/type/array.hpp +++ b/cpp/type/array.hpp @@ -45,7 +45,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v) o.pack_array(v.size()); for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) { - pack(*it, o); + pack(o, *it); } return o; } diff --git a/cpp/type/boolean.hpp b/cpp/type/boolean.hpp index e958478..60f1714 100644 --- a/cpp/type/boolean.hpp +++ b/cpp/type/boolean.hpp @@ -22,12 +22,11 @@ #include <vector> namespace msgpack { -namespace type { inline bool& operator>> (object o, bool& v) { - if(o.type != BOOLEAN) { throw type_error(); } + if(o.type != type::BOOLEAN) { throw type_error(); } v = o.via.boolean; return v; } @@ -42,7 +41,6 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v) } -} // namespace type } // namespace msgpack #endif /* msgpack/type/bool.hpp */ diff --git a/cpp/type/integer.hpp b/cpp/type/integer.hpp index f5841a6..3fd57b4 100644 --- a/cpp/type/integer.hpp +++ b/cpp/type/integer.hpp @@ -70,19 +70,19 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 1, true> { - static inline void pack(T v, packer<Stream>& o) + static inline void pack(packer<Stream>& o, T v) { o.pack_int8(v); } }; template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 1, false> { - static inline void pack(T v, packer<Stream>& o) + static inline void pack(packer<Stream>& o, T v) { o.pack_uint8(v); } }; template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 2, true> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (int16_t)v <= (int16_t)std::numeric_limits<int8_t>::max() && (int16_t)v >= (int16_t)std::numeric_limits<int8_t>::min()) { o.pack_int8(v); } @@ -92,7 +92,7 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 2, false> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (uint16_t)v <= (uint16_t)std::numeric_limits<uint8_t>::max()) { o.pack_uint8(v); } else { o.pack_uint16(v); } @@ -101,7 +101,7 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 4, true> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (int32_t)v <= (int32_t)std::numeric_limits<int8_t>::max() && (int32_t)v >= (int32_t)std::numeric_limits<int8_t>::min()) { o.pack_int8(v); } @@ -114,7 +114,7 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 4, false> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (uint32_t)v <= (uint32_t)std::numeric_limits<uint8_t>::max()) { o.pack_uint8(v); } else if( (uint32_t)v <= (uint32_t)std::numeric_limits<uint16_t>::max()) @@ -125,7 +125,7 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 8, true> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (int64_t)v <= (int64_t)std::numeric_limits<int8_t>::max() && (int64_t)v >= (int64_t)std::numeric_limits<int8_t>::min()) { o.pack_int8(v); } @@ -141,7 +141,7 @@ namespace detail { template <typename T, typename Stream> struct pack_integer_size_sign<T, Stream, 8, false> { - static inline void pack(T v, packer<Stream>& o) { + static inline void pack(packer<Stream>& o, T v) { if( (uint64_t)v <= (uint64_t)std::numeric_limits<uint8_t>::max()) { o.pack_uint8(v); } else if( (uint64_t)v <= (uint64_t)std::numeric_limits<uint16_t>::max()) @@ -156,7 +156,7 @@ namespace detail { template <typename T, typename Stream> static inline void pack_integer(T v, packer<Stream>& o) { - pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack(v, o); + pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack(o, v); } } // namespace detail diff --git a/cpp/type/map.hpp b/cpp/type/map.hpp index 1d5e054..3b544df 100644 --- a/cpp/type/map.hpp +++ b/cpp/type/map.hpp @@ -63,8 +63,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K o.pack_map(v.size()); for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) { - pack(it->first, o); - pack(it->second, o); + pack(o, it->first); + pack(o, it->second); } return o; } @@ -97,8 +97,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v) o.pack_map(v.size()); for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) { - pack(it->first, o); - pack(it->second, o); + pack(o, it->first); + pack(o, it->second); } return o; } @@ -125,8 +125,8 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>& o.pack_multimap(v.size()); for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) { - pack(it->first, o); - pack(it->second, o); + pack(o, it->first); + pack(o, it->second); } return o; } diff --git a/cpp/type/tuple.hpp.erb b/cpp/type/tuple.hpp.erb index c54739a..397f660 100644 --- a/cpp/type/tuple.hpp.erb +++ b/cpp/type/tuple.hpp.erb @@ -142,7 +142,7 @@ const packer<Stream>& operator<< ( const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) { o.pack_array(<%=i+1%>); <%0.upto(i) {|j|%> - pack(v.template get<<%=j%>>(), o);<%}%> + pack(o, v.template get<<%=j%>>());<%}%> return o; } <%}%> diff --git a/cpp/unpack.hpp b/cpp/unpack.hpp index de613a4..ffee60d 100644 --- a/cpp/unpack.hpp +++ b/cpp/unpack.hpp @@ -81,7 +81,7 @@ public: // // // 2. // ssize_t bytes = - // read(the_source, pac.buffer, pac.buffer_capacity()); + // read(the_source, pac.buffer(), pac.buffer_capacity()); // // // error handling ... // |