lang/c/msgpack: C++ binding: reexamined global operators

git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@72 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
frsyuki
2009-02-15 09:09:58 +00:00
parent f4a6d7faa1
commit 2c7f0b2b1a
10 changed files with 241 additions and 209 deletions

View File

@@ -22,13 +22,12 @@
#include <vector>
namespace msgpack {
namespace type {
template <typename T>
inline std::vector<T> operator<< (std::vector<T>& v, object o)
inline std::vector<T> operator>> (object o, std::vector<T>& v)
{
if(o.type != ARRAY) { throw type_error(); }
if(o.type != type::ARRAY) { throw type_error(); }
v.resize(o.via.container.size);
object* p(o.via.container.ptr);
object* const pend(o.via.container.ptr + o.via.container.size);
@@ -41,18 +40,17 @@ inline std::vector<T> operator<< (std::vector<T>& v, object o)
template <typename Stream, typename T>
inline const std::vector<T>& operator>> (const std::vector<T>& v, packer<Stream>& o)
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);
}
return v;
return o;
}
} // namespace type
} // namespace msgpack
#endif /* msgpack/type/array.hpp */