Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/framing/Buffer.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #include "amqp_types.h"
00022 #include "qpid/Exception.h"
00023 #include <boost/iterator/iterator_facade.hpp>
00024 
00025 #ifndef _Buffer_
00026 #define _Buffer_
00027 
00028 namespace qpid {
00029 namespace framing {
00030 
00031 struct OutOfBounds : qpid::Exception {
00032     OutOfBounds() : qpid::Exception(std::string("Out of Bounds")) {}
00033 };
00034 
00035 class Content;
00036 class FieldTable;
00037 
00038 class Buffer
00039 {
00040     uint32_t size;
00041     char* data;
00042     uint32_t position;
00043     uint32_t r_position;
00044 
00045     void checkAvailable(uint32_t count) { if (position + count > size) throw OutOfBounds(); }
00046 
00047   public:
00048     
00052     class Iterator  : public boost::iterator_facade<
00053       Iterator, char, boost::random_access_traversal_tag>
00054     {
00055       public:
00056         Iterator(Buffer& b) : buffer(&b) {}
00057 
00058       private:
00059       friend class boost::iterator_core_access;
00060         char& dereference() const { return buffer->data[buffer->position]; }
00061         void increment() { ++buffer->position; }
00062         bool equal(const Iterator& x) const { return buffer == x.buffer; }
00063 
00064         Buffer* buffer;
00065     };
00066     
00067   friend class Iterator;
00068     
00069     Buffer(char* data=0, uint32_t size=0);
00070 
00071     void record();
00072     void restore(bool reRecord = false);
00073     void reset();
00074 
00075     uint32_t available() { return size - position; }
00076     uint32_t getSize() { return size; }
00077     uint32_t getPosition() { return position; }
00078     Iterator getIterator() { return Iterator(*this); }
00079     char* getPointer() { return data; }
00080         
00081     void putOctet(uint8_t i);
00082     void putShort(uint16_t i);
00083     void putLong(uint32_t i);
00084     void putLongLong(uint64_t i);
00085     void putInt8(int8_t i);
00086     void putInt16(int16_t i);
00087     void putInt32(int32_t i);
00088     void putInt64(int64_t i);
00089     void putFloat(float f);
00090     void putDouble(double f);
00091     void putBin128(uint8_t* b);
00092 
00093     uint8_t  getOctet();
00094     uint16_t getShort(); 
00095     uint32_t getLong();
00096     uint64_t getLongLong();
00097     int8_t   getInt8();
00098     int16_t  getInt16();
00099     int32_t  getInt32();
00100     int64_t  getInt64();
00101     float    getFloat();
00102     double   getDouble();
00103     
00104     template <int n>
00105     uint64_t getUInt();
00106 
00107     template <int n>
00108     void putUInt(uint64_t);
00109 
00110     void putShortString(const string& s);
00111     void putMediumString(const string& s);
00112     void putLongString(const string& s);
00113     void getShortString(string& s);
00114     void getMediumString(string& s);
00115     void getLongString(string& s);
00116     void getBin128(uint8_t* b);
00117 
00118     void putRawData(const string& s);
00119     void getRawData(string& s, uint32_t size);
00120 
00121     void putRawData(const uint8_t* data, size_t size);
00122     void getRawData(uint8_t* data, size_t size);
00123 
00124     template <class T> void put(const T& data) { data.encode(*this); }
00125     template <class T> void get(T& data) { data.decode(*this); }
00126 
00127     void dump(std::ostream&) const;
00128 };
00129 
00130 std::ostream& operator<<(std::ostream&, const Buffer&);
00131 
00132 }} // namespace qpid::framing
00133 
00134 
00135 #endif

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:36 2009 for Qpid C++ Client API by doxygen 1.4.7