]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
* buffer: deque map<t,deque<u>>
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 26 Mar 2007 20:41:56 +0000 (20:41 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 26 Mar 2007 20:41:56 +0000 (20:41 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1305 29311d96-e01e-0410-9327-a35deaab8ce9

branches/aleung/security1/ceph/include/buffer.h

index 4634c2f5b590e6b22c3bac99accf21f71cacef7f..9c6576deeb4153f23f36dafc8df4cd343f2d5b0a 100644 (file)
@@ -799,6 +799,7 @@ inline void _decode(bufferlist& s, bufferlist& bl, int& off)
 
 
 #include <set>
+#include <deque>
 #include <map>
 #include <vector>
 #include <string>
@@ -889,6 +890,37 @@ inline void _decode(std::set<T>& s, bufferlist& bl, int& off)
   assert(s.size() == (unsigned)n);
 }
 
+// deque<T>
+template<class T>
+inline void _encode(const std::deque<T>& s, bufferlist& bl)
+{
+  int n = s.size();
+  bl.append((char*)&n, sizeof(n));
+  for (typename std::deque<T>::const_iterator it = s.begin();
+       it != s.end();
+       it++) {
+    T v = *it;
+    bl.append((char*)&v, sizeof(v));
+    n--;
+  }
+  assert(n==0);
+}
+template<class T>
+inline void _decode(std::deque<T>& s, bufferlist& bl, int& off) 
+{
+  s.clear();
+  int n;
+  bl.copy(off, sizeof(n), (char*)&n);
+  off += sizeof(n);
+  for (int i=0; i<n; i++) {
+    T v;
+    bl.copy(off, sizeof(v), (char*)&v);
+    off += sizeof(v);
+    s.push_back(v);
+  }
+  assert(s.size() == (unsigned)n);
+}
+
 // vector<T>
 template<class T>
 inline void _encode(std::vector<T>& s, bufferlist& bl)
@@ -1141,6 +1173,38 @@ inline void _decode(std::map<T, std::set<U> >& s, bufferlist& bl, int& off)
   assert(s.size() == (unsigned)n);
 }
 
+// map<T,deque<U>>
+template<class T, class U>
+inline void _encode(const std::map<T, std::deque<U> >& s, bufferlist& bl)
+{
+  int n = s.size();
+  bl.append((char*)&n, sizeof(n));
+  for (typename std::map<T, std::deque<U> >::const_iterator it = s.begin();
+       it != s.end();
+       it++) {
+    T k = it->first;
+    bl.append((char*)&k, sizeof(k));
+    ::_encode(it->second, bl);
+    n--;
+  }
+  assert(n==0);
+}
+template<class T, class U>
+inline void _decode(std::map<T, std::deque<U> >& s, bufferlist& bl, int& off) 
+{
+  s.clear();
+  int n;
+  bl.copy(off, sizeof(n), (char*)&n);
+  off += sizeof(n);
+  for (int i=0; i<n; i++) {
+    T k;
+    bl.copy(off, sizeof(k), (char*)&k);
+    off += sizeof(k);
+    ::_decode(s[k], bl, off);
+  }
+  assert(s.size() == (unsigned)n);
+}
+
 
 // map<T,U>
 template<class T, class U>