From a80f66c2f220b037c50021497aac0fb09788b7aa Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 29 Feb 2008 23:18:51 +0000 Subject: - Added Buffer::Iterator so amqp_0_10::Codec can use a Buffer - AMQBody wrappers for amqp_0_10::Command and Control - Extended AMQBody for CommandBody and ControlBody. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@632490 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/Buffer.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'cpp/src/qpid/framing/Buffer.h') diff --git a/cpp/src/qpid/framing/Buffer.h b/cpp/src/qpid/framing/Buffer.h index d0ca41f82b..9c0d403462 100644 --- a/cpp/src/qpid/framing/Buffer.h +++ b/cpp/src/qpid/framing/Buffer.h @@ -20,6 +20,7 @@ */ #include "amqp_types.h" #include "qpid/Exception.h" +#include #ifndef _Buffer_ #define _Buffer_ @@ -41,8 +42,28 @@ class Buffer void checkAvailable(uint32_t count) { if (position + count > size) throw OutOfBounds(); } -public: - + public: + + /** Buffer input/output iterator. + * Supports using an amqp_0_10::Codec with a framing::Buffer. + */ + class Iterator : public boost::iterator_facade< + Iterator, char, boost::random_access_traversal_tag> + { + public: + Iterator(Buffer& b) : buffer(&b) {} + + private: + friend class boost::iterator_core_access; + char& dereference() const { return buffer->data[buffer->position]; } + void increment() { ++buffer->position; } + bool equal(const Iterator& x) const { return buffer == x.buffer; } + + Buffer* buffer; + }; + + friend class Iterator; + Buffer(char* data=0, uint32_t size=0); void record(); @@ -52,6 +73,7 @@ public: uint32_t available() { return size - position; } uint32_t getSize() { return size; } uint32_t getPosition() { return position; } + Iterator getIterator() { return Iterator(*this); } void putOctet(uint8_t i); void putShort(uint16_t i); -- cgit v1.2.1