From 7312c5fd3b74fd9cad485121bc31fc501accd355 Mon Sep 17 00:00:00 2001 From: Peter Iannucci Date: Fri, 20 Sep 2013 15:11:11 -0400 Subject: [PATCH] More clean-ups --- rpc/marshall.h | 73 ++++++++++++-------------------------------------------- 1 file changed, 15 insertions(+), 58 deletions(-) diff --git a/rpc/marshall.h b/rpc/marshall.h index bd45c02..fbec77b 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; } @@ -244,44 +225,20 @@ 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; } -- 1.7.9.5