From 028745dbc3c47bd6561310678f82f15bd45678d9 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Sat, 6 Sep 2008 14:10:08 +0000 Subject: 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 --- cpp/src/qpid/RefCountedBuffer.h | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'cpp/src/qpid/RefCountedBuffer.h') 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 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 p; + char* cp() const; + pointer(RefCountedBuffer* x); + friend class RefCountedBuffer; - typedef boost::intrusive_ptr 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(); } -- cgit v1.2.1