]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
operator[] on buffers
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 1 Nov 2006 21:54:15 +0000 (21:54 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 1 Nov 2006 21:54:15 +0000 (21:54 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@955 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/include/buffer.h

index bffd5cb920e9bf519b910738f1a6cdcf147cfa64..7d786881ba650c729c3ec28d0531fcb17dce89dc 100644 (file)
@@ -248,6 +248,16 @@ public:
     unsigned length() const { return _len; }
     unsigned offset() const { return _off; }
     unsigned unused_tail_length() const { return _raw->len - (_off+_len); }
+    const char& operator[](unsigned n) const { 
+      assert(_raw); 
+      assert(n < _len);
+      return _raw->data[_off + n];
+    }
+    char& operator[](unsigned n) { 
+      assert(_raw); 
+      assert(n < _len);
+      return _raw->data[_off + n];
+    }
 
     const char *raw_c_str() const { assert(_raw); return _raw->data; }
     unsigned raw_length() const { assert(_raw); return _raw->len; }
@@ -520,6 +530,23 @@ public:
     }
     
     
+    /*
+     * get a char
+     */
+    const char& operator[](unsigned n) {
+      assert(n < _len);
+      for (std::list<ptr>::iterator p = _buffers.begin();
+          p != _buffers.end();
+          p++) {
+       if (n >= p->length()) {
+         n -= p->length();
+         continue;
+       }
+       return (*p)[n];
+      }
+      assert(0);
+    }
+
     /*
      * return a contiguous ptr to whole bufferlist contents.
      */