summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/RefCountedBuffer.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-09-06 14:10:08 +0000
committerAlan Conway <aconway@apache.org>2008-09-06 14:10:08 +0000
commit028745dbc3c47bd6561310678f82f15bd45678d9 (patch)
tree036ac009b7ccbcafcf4b6c2aa375bb19237f5a0e /cpp/src/qpid/RefCountedBuffer.h
parent3bb7782cb0904f0abf61b7fb28da7bce905ceb08 (diff)
downloadqpid-python-028745dbc3c47bd6561310678f82f15bd45678d9.tar.gz
RefCountedBuffer improvements, centralize cluster encoding/decoding in Event.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@692654 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/RefCountedBuffer.h')
-rw-r--r--cpp/src/qpid/RefCountedBuffer.h27
1 files changed, 24 insertions, 3 deletions
diff --git a/cpp/src/qpid/RefCountedBuffer.h b/cpp/src/qpid/RefCountedBuffer.h
index af46cbb92a..c332325378 100644
--- a/cpp/src/qpid/RefCountedBuffer.h
+++ b/cpp/src/qpid/RefCountedBuffer.h
@@ -27,7 +27,7 @@
#include <boost/intrusive_ptr.hpp>
namespace qpid {
-
+// FIXME aconway 2008-09-06: easy to add alignment
/**
* Reference-counted byte buffer.
* No alignment guarantees.
@@ -39,11 +39,32 @@ class RefCountedBuffer : boost::noncopyable {
char* addr() const;
public:
+ /** Smart char pointer to a reference counted buffer */
+ class pointer {
+ boost::intrusive_ptr<RefCountedBuffer> p;
+ char* cp() const;
+ pointer(RefCountedBuffer* x);
+ friend class RefCountedBuffer;
- typedef boost::intrusive_ptr<RefCountedBuffer> intrusive_ptr;
+ public:
+ pointer();
+ pointer(const pointer&);
+ ~pointer();
+ pointer& operator=(const pointer&);
+
+ char* get() { return cp(); }
+ operator char*() { return cp(); }
+ char& operator*() { return *cp(); }
+ char& operator[](size_t i) { return cp()[i]; }
+ const char* get() const { return cp(); }
+ operator const char*() const { return cp(); }
+ const char& operator*() const { return *cp(); }
+ const char& operator[](size_t i) const { return cp()[i]; }
+ };
+
/** Create a reference counted buffer of size n */
- static intrusive_ptr create(size_t n);
+ static pointer create(size_t n);
/** Get a pointer to the start of the buffer. */
char* get() { return addr(); }