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

qpid/framing/Array.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 "FieldValue.h"
00023 #include "qpid/framing/TypeCode.h"
00024 #include <boost/shared_ptr.hpp>
00025 #include <iostream>
00026 #include <vector>
00027 
00028 #ifndef _Array_
00029 #define _Array_
00030 
00031 namespace qpid {
00032 namespace framing {
00033 
00034 class Buffer;
00035 
00036 class Array
00037 {
00038   public:
00039     typedef boost::shared_ptr<FieldValue> ValuePtr;
00040     typedef std::vector<ValuePtr> ValueVector;
00041     typedef ValueVector::const_iterator const_iterator;
00042     typedef ValueVector::iterator iterator;
00043 
00044     uint32_t encodedSize() const;
00045     void encode(Buffer& buffer) const;
00046     void decode(Buffer& buffer);
00047 
00048     int count() const;
00049     bool operator==(const Array& other) const;
00050 
00051     Array();
00052     Array(TypeCode type);
00053     Array(uint8_t type);
00054     //creates a longstr array
00055     Array(const std::vector<std::string>& in);
00056 
00057     TypeCode getType() const { return type; }
00058     
00059     // std collection interface.
00060     const_iterator begin() const { return values.begin(); }
00061     const_iterator end() const { return values.end(); }
00062     iterator begin() { return values.begin(); }
00063     iterator end(){ return values.end(); }
00064 
00065     ValuePtr front() const { return values.front(); }
00066     ValuePtr back() const { return values.back(); }
00067     size_t size() const { return values.size(); }
00068 
00069     void insert(iterator i, ValuePtr value);
00070     void erase(iterator i) { values.erase(i); }
00071     void push_back(ValuePtr value) { values.insert(end(), value); }
00072     void pop_back() { values.pop_back(); }
00073     
00074     // Non-std interface
00075     void add(ValuePtr value) { push_back(value); }
00076 
00077     template <class T>
00078     void collect(std::vector<T>& out) const
00079     {
00080         for (ValueVector::const_iterator i = values.begin(); i != values.end(); ++i) {
00081             out.push_back((*i)->get<T>());
00082         }
00083     }
00084 
00085   private:
00086     TypeCode type;
00087     ValueVector values;
00088 
00089     friend std::ostream& operator<<(std::ostream& out, const Array& body);
00090 };
00091 
00092 }
00093 }
00094 
00095 
00096 #endif

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