- Timestamp:
- 09/28/08 22:05:11 (5 years ago)
- Location:
- lang/c/msgpack/trunk/cpp
- Files:
-
- 8 modified
-
object.hpp (modified) (2 diffs)
-
test.cpp (modified) (2 diffs)
-
type/array.hpp (modified) (1 diff)
-
type/boolean.hpp (modified) (2 diffs)
-
type/integer.hpp (modified) (9 diffs)
-
type/map.hpp (modified) (3 diffs)
-
type/tuple.hpp.erb (modified) (1 diff)
-
unpack.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/msgpack/trunk/cpp/object.hpp
r20114 r20167 84 84 85 85 86 namespace type { 87 template <typename T> 88 inline T& operator>> (object o, T& v) 89 { 90 v.msgpack_unpack(o); 91 return v; 92 } 93 94 template <typename Stream, typename T> 95 inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) 96 { 97 pack_copy(v.msgpack_pack(), o); 98 return o; 99 } 86 template <typename T> 87 inline T& operator>> (object o, T& v) 88 { 89 v.msgpack_unpack(o); 90 return v; 91 } 92 93 template <typename Stream, typename T> 94 inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) 95 { 96 o << v.msgpack_pack(); 97 return o; 100 98 } 101 99 … … 104 102 inline void convert(T& v, object o) 105 103 { 106 using namespace type;107 104 o >> v; 108 105 } 109 106 110 111 template <typename Stream, typename T> 112 inline void pack(T& v, packer<Stream>& o) 113 { 114 using namespace type; 107 template <typename Stream, typename T> 108 inline void pack(packer<Stream>& o, const T& v) 109 { 115 110 o << v; 116 111 } 117 112 118 119 template <typename Stream, typename T> 120 inline void pack(T& v, Stream& s) 113 template <typename Stream, typename T> 114 inline void pack(Stream& s, const T& v) 121 115 { 122 116 packer<Stream> pk(s); 123 pack(v, pk); 124 } 125 126 127 template <typename Stream, typename T> 128 inline void pack_copy(T v, packer<Stream>& o) 129 { 130 pack(v, o); 117 pack(pk, v); 118 } 119 120 template <typename Stream, typename T> 121 inline void pack_copy(packer<Stream>& o, T v) 122 { 123 pack(o, v); 131 124 } 132 125 -
lang/c/msgpack/trunk/cpp/test.cpp
r19275 r20167 27 27 try { 28 28 std::stringstream s; 29 pack(s hould, s);29 pack(s, should); 30 30 std::string str(s.str()); 31 31 object ro = unpack(str.data(), str.size(), m_zone); … … 140 140 { 141 141 for(unsigned i=0; i < TASK_REPEAT; ++i) { 142 pack( task, stream);142 pack(stream, task); 143 143 } 144 144 std::cout << "send " << stream.str().size() << " bytes" << std::endl; -
lang/c/msgpack/trunk/cpp/type/array.hpp
r20114 r20167 46 46 for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end()); 47 47 it != it_end; ++it) { 48 pack( *it, o);48 pack(o, *it); 49 49 } 50 50 return o; -
lang/c/msgpack/trunk/cpp/type/boolean.hpp
r20114 r20167 23 23 24 24 namespace msgpack { 25 namespace type {26 25 27 26 28 27 inline bool& operator>> (object o, bool& v) 29 28 { 30 if(o.type != BOOLEAN) { throw type_error(); }29 if(o.type != type::BOOLEAN) { throw type_error(); } 31 30 v = o.via.boolean; 32 31 return v; … … 43 42 44 43 45 } // namespace type46 44 } // namespace msgpack 47 45 -
lang/c/msgpack/trunk/cpp/type/integer.hpp
r20114 r20167 71 71 template <typename T, typename Stream> 72 72 struct pack_integer_size_sign<T, Stream, 1, true> { 73 static inline void pack( T v, packer<Stream>& o)73 static inline void pack(packer<Stream>& o, T v) 74 74 { o.pack_int8(v); } 75 75 }; … … 77 77 template <typename T, typename Stream> 78 78 struct pack_integer_size_sign<T, Stream, 1, false> { 79 static inline void pack( T v, packer<Stream>& o)79 static inline void pack(packer<Stream>& o, T v) 80 80 { o.pack_uint8(v); } 81 81 }; … … 83 83 template <typename T, typename Stream> 84 84 struct pack_integer_size_sign<T, Stream, 2, true> { 85 static inline void pack( T v, packer<Stream>& o) {85 static inline void pack(packer<Stream>& o, T v) { 86 86 if( (int16_t)v <= (int16_t)std::numeric_limits<int8_t>::max() && 87 87 (int16_t)v >= (int16_t)std::numeric_limits<int8_t>::min()) … … 93 93 template <typename T, typename Stream> 94 94 struct pack_integer_size_sign<T, Stream, 2, false> { 95 static inline void pack( T v, packer<Stream>& o) {95 static inline void pack(packer<Stream>& o, T v) { 96 96 if( (uint16_t)v <= (uint16_t)std::numeric_limits<uint8_t>::max()) 97 97 { o.pack_uint8(v); } … … 102 102 template <typename T, typename Stream> 103 103 struct pack_integer_size_sign<T, Stream, 4, true> { 104 static inline void pack( T v, packer<Stream>& o) {104 static inline void pack(packer<Stream>& o, T v) { 105 105 if( (int32_t)v <= (int32_t)std::numeric_limits<int8_t>::max() && 106 106 (int32_t)v >= (int32_t)std::numeric_limits<int8_t>::min()) … … 115 115 template <typename T, typename Stream> 116 116 struct pack_integer_size_sign<T, Stream, 4, false> { 117 static inline void pack( T v, packer<Stream>& o) {117 static inline void pack(packer<Stream>& o, T v) { 118 118 if( (uint32_t)v <= (uint32_t)std::numeric_limits<uint8_t>::max()) 119 119 { o.pack_uint8(v); } … … 126 126 template <typename T, typename Stream> 127 127 struct pack_integer_size_sign<T, Stream, 8, true> { 128 static inline void pack( T v, packer<Stream>& o) {128 static inline void pack(packer<Stream>& o, T v) { 129 129 if( (int64_t)v <= (int64_t)std::numeric_limits<int8_t>::max() && 130 130 (int64_t)v >= (int64_t)std::numeric_limits<int8_t>::min()) … … 142 142 template <typename T, typename Stream> 143 143 struct pack_integer_size_sign<T, Stream, 8, false> { 144 static inline void pack( T v, packer<Stream>& o) {144 static inline void pack(packer<Stream>& o, T v) { 145 145 if( (uint64_t)v <= (uint64_t)std::numeric_limits<uint8_t>::max()) 146 146 { o.pack_uint8(v); } … … 157 157 static inline void pack_integer(T v, packer<Stream>& o) 158 158 { 159 pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack( v, o);159 pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack(o, v); 160 160 } 161 161 -
lang/c/msgpack/trunk/cpp/type/map.hpp
r20114 r20167 64 64 for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end()); 65 65 it != it_end; ++it) { 66 pack( it->first, o);67 pack( it->second, o);66 pack(o, it->first); 67 pack(o, it->second); 68 68 } 69 69 return o; … … 98 98 for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end()); 99 99 it != it_end; ++it) { 100 pack( it->first, o);101 pack( it->second, o);100 pack(o, it->first); 101 pack(o, it->second); 102 102 } 103 103 return o; … … 126 126 for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end()); 127 127 it != it_end; ++it) { 128 pack( it->first, o);129 pack( it->second, o);128 pack(o, it->first); 129 pack(o, it->second); 130 130 } 131 131 return o; -
lang/c/msgpack/trunk/cpp/type/tuple.hpp.erb
r20114 r20167 143 143 o.pack_array(<%=i+1%>); 144 144 <%0.upto(i) {|j|%> 145 pack( v.template get<<%=j%>>(), o);<%}%>145 pack(o, v.template get<<%=j%>>());<%}%> 146 146 return o; 147 147 } -
lang/c/msgpack/trunk/cpp/unpack.hpp
r20114 r20167 82 82 // // 2. 83 83 // ssize_t bytes = 84 // read(the_source, pac.buffer , pac.buffer_capacity());84 // read(the_source, pac.buffer(), pac.buffer_capacity()); 85 85 // 86 86 // // error handling ...
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)