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