More clean-ups
authorPeter Iannucci <iannucci@mit.edu>
Fri, 20 Sep 2013 19:11:11 +0000 (15:11 -0400)
committerPeter Iannucci <iannucci@mit.edu>
Wed, 25 Sep 2013 01:50:45 +0000 (21:50 -0400)
rpc/marshall.h

index bd45c02..fbec77b 100644 (file)
@@ -123,30 +123,11 @@ marshall& operator<<(marshall &, short);
 marshall& operator<<(marshall &, unsigned long long);
 marshall& operator<<(marshall &, const std::string &);
 
-template <class C> marshall &
-operator<<(marshall &m, std::vector<C> v)
-{
-    m << (unsigned int) v.size();
-    for(unsigned i = 0; i < v.size(); i++)
-        m << v[i];
-    return m;
-}
-
-template <class A, class B> marshall &
-operator<<(marshall &m, const std::map<A,B> &d) {
-    typename std::map<A,B>::const_iterator i;
-
-    m << (unsigned int) d.size();
-
-    for (i = d.begin(); i != d.end(); i++) {
-        m << i->first << i->second;
-    }
-    return m;
-}
-
 template <class A> marshall &
-operator<<(marshall &m, const std::list<A> &d) {
-    m << std::vector<A>(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 <class C> unmarshall &
-operator>>(unmarshall &u, std::vector<C> &v)
-{
-    unsigned n;
-    u >> n;
-    v.clear();
-    while (n--) {
-        C c;
-        u >> c;
-        v.push_back(c);
-    }
-       return u;
-}
-
-template <class A, class B> unmarshall &
-operator>>(unmarshall &u, std::map<A,B> &d) {
-    unsigned n;
-    u >> n;
-    d.clear();
-    while (n--) {
-        A a;
-        B b;
-        u >> a >> b;
-        d[a] = b;
-    }
+template <class A> unmarshall & operator>>(unmarshall &u, A &x) {
+    unsigned n = u.grab<unsigned>();
+    x.clear();
+    while (n--)
+        x.emplace_back(u.grab<typename A::value_type>());
     return u;
 }
 
-template <class C> unmarshall &
-operator>>(unmarshall &u, std::list<C> &l) {
-    unsigned n;
-    u >> n;
-    l.clear();
-    while (n--) {
-        C c;
-        u >> c;
-        l.push_back(c);
-    }
+template <class A, class B> unmarshall &
+operator>>(unmarshall &u, std::map<A,B> &x) {
+    unsigned n = u.grab<unsigned>();
+    x.clear();
+    while (n--)
+        x.emplace(u.grab<std::pair<A,B>>());
     return u;
 }