X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/b86bce0900f88c530f23dd602a8f2ef9ce008f8a..eeab3e6cade87c1fe0a5f3d93522e12ccb9ec2ab:/rpc/marshall.h?ds=sidebyside diff --git a/rpc/marshall.h b/rpc/marshall.h index bd45c02..7a85d6b 100644 --- a/rpc/marshall.h +++ b/rpc/marshall.h @@ -123,30 +123,11 @@ marshall& operator<<(marshall &, short); marshall& operator<<(marshall &, unsigned long long); marshall& operator<<(marshall &, const std::string &); -template marshall & -operator<<(marshall &m, std::vector v) -{ - m << (unsigned int) v.size(); - for(unsigned i = 0; i < v.size(); i++) - m << v[i]; - return m; -} - -template marshall & -operator<<(marshall &m, const std::map &d) { - typename std::map::const_iterator i; - - m << (unsigned int) d.size(); - - for (i = d.begin(); i != d.end(); i++) { - m << i->first << i->second; - } - return m; -} - template marshall & -operator<<(marshall &m, const std::list &d) { - m << std::vector(d.begin(), d.end()); +operator<<(marshall &m, const A &x) { + m << (unsigned int) x.size(); + for (const auto &a : x) + m << a; return m; } @@ -234,54 +215,20 @@ class unmarshall { } }; -unmarshall& operator>>(unmarshall &, bool &); -unmarshall& operator>>(unmarshall &, unsigned char &); -unmarshall& operator>>(unmarshall &, char &); -unmarshall& operator>>(unmarshall &, unsigned short &); -unmarshall& operator>>(unmarshall &, short &); -unmarshall& operator>>(unmarshall &, unsigned int &); -unmarshall& operator>>(unmarshall &, int &); -unmarshall& operator>>(unmarshall &, unsigned long long &); -unmarshall& operator>>(unmarshall &, std::string &); - -template unmarshall & -operator>>(unmarshall &u, std::vector &v) -{ - unsigned n; - u >> n; - v.clear(); - while (n--) { - C c; - u >> c; - v.push_back(c); - } - return u; -} - -template unmarshall & -operator>>(unmarshall &u, std::map &d) { - unsigned n; - u >> n; - d.clear(); - while (n--) { - A a; - B b; - u >> a >> b; - d[a] = b; - } +template unmarshall & operator>>(unmarshall &u, A &x) { + unsigned n = u.grab(); + x.clear(); + while (n--) + x.emplace_back(u.grab()); return u; } -template unmarshall & -operator>>(unmarshall &u, std::list &l) { - unsigned n; - u >> n; - l.clear(); - while (n--) { - C c; - u >> c; - l.push_back(c); - } +template unmarshall & +operator>>(unmarshall &u, std::map &x) { + unsigned n = u.grab(); + x.clear(); + while (n--) + x.emplace(u.grab>()); return u; }