Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/framing/FieldTable.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 <iostream>
00022 #include <vector>
00023 #include <boost/shared_ptr.hpp>
00024 #include <map>
00025 #include "qpid/framing/amqp_types.h"
00026 #include "qpid/CommonImportExport.h"
00027 
00028 #ifndef _FieldTable_
00029 #define _FieldTable_
00030 
00031 namespace qpid {
00036 namespace framing {
00037 
00038 class Array;
00039 class FieldValue;
00040 class Buffer;
00041 
00048 class FieldTable
00049 {
00050   public:
00051     typedef boost::shared_ptr<FieldValue> ValuePtr;
00052     typedef std::map<std::string, ValuePtr> ValueMap;
00053     typedef ValueMap::iterator iterator;
00054     typedef ValueMap::const_iterator const_iterator;
00055     typedef ValueMap::const_reference const_reference;
00056     typedef ValueMap::reference reference;
00057     typedef ValueMap::value_type value_type;
00058 
00059     QPID_COMMON_INLINE_EXTERN FieldTable() {};
00060     QPID_COMMON_EXTERN FieldTable(const FieldTable& ft);
00061     QPID_COMMON_EXTERN ~FieldTable();
00062     QPID_COMMON_EXTERN FieldTable& operator=(const FieldTable& ft);
00063     QPID_COMMON_EXTERN uint32_t encodedSize() const;
00064     QPID_COMMON_EXTERN void encode(Buffer& buffer) const;
00065     QPID_COMMON_EXTERN void decode(Buffer& buffer);
00066 
00067     QPID_COMMON_EXTERN int count() const;
00068     QPID_COMMON_EXTERN size_t size() const { return values.size(); }
00069     QPID_COMMON_EXTERN bool empty() { return size() == 0; }
00070     QPID_COMMON_EXTERN void set(const std::string& name, const ValuePtr& value);
00071     QPID_COMMON_EXTERN ValuePtr get(const std::string& name) const;
00072     QPID_COMMON_INLINE_EXTERN bool isSet(const std::string& name) const { return get(name).get() != 0; }
00073 
00074     QPID_COMMON_EXTERN void setString(const std::string& name, const std::string& value);
00075     QPID_COMMON_EXTERN void setInt(const std::string& name, const int value);
00076     QPID_COMMON_EXTERN void setInt64(const std::string& name, const int64_t value);
00077     QPID_COMMON_EXTERN void setTimestamp(const std::string& name, const uint64_t value);
00078     QPID_COMMON_EXTERN void setUInt64(const std::string& name, const uint64_t value);
00079     QPID_COMMON_EXTERN void setTable(const std::string& name, const FieldTable& value);
00080     QPID_COMMON_EXTERN void setArray(const std::string& name, const Array& value);
00081     QPID_COMMON_EXTERN void setFloat(const std::string& name, const float value);
00082     QPID_COMMON_EXTERN void setDouble(const std::string& name, const double value);
00083     //void setDecimal(string& name, xxx& value);
00084 
00085     QPID_COMMON_EXTERN int getAsInt(const std::string& name) const;
00086     QPID_COMMON_EXTERN uint64_t getAsUInt64(const std::string& name) const;
00087     QPID_COMMON_EXTERN int64_t getAsInt64(const std::string& name) const;
00088     QPID_COMMON_EXTERN std::string getAsString(const std::string& name) const;
00089 
00090     QPID_COMMON_EXTERN bool getTable(const std::string& name, FieldTable& value) const;
00091     QPID_COMMON_EXTERN bool getArray(const std::string& name, Array& value) const;
00092     QPID_COMMON_EXTERN bool getFloat(const std::string& name, float& value) const;
00093     QPID_COMMON_EXTERN bool getDouble(const std::string& name, double& value) const;
00094     //bool getTimestamp(const std::string& name, uint64_t& value) const;
00095     //bool getDecimal(string& name, xxx& value);
00096     QPID_COMMON_EXTERN void erase(const std::string& name);
00097 
00098 
00099     QPID_COMMON_EXTERN bool operator==(const FieldTable& other) const;
00100 
00101     // Map-like interface.
00102     ValueMap::const_iterator begin() const { return values.begin(); }
00103     ValueMap::const_iterator end() const { return values.end(); }
00104     ValueMap::const_iterator find(const std::string& s) const { return values.find(s); }
00105 
00106     ValueMap::iterator begin() { return values.begin(); }
00107     ValueMap::iterator end() { return values.end(); }
00108     ValueMap::iterator find(const std::string& s) { return values.find(s); }
00109 
00110     QPID_COMMON_EXTERN std::pair <ValueMap::iterator, bool> insert(const ValueMap::value_type&);
00111     QPID_COMMON_EXTERN ValueMap::iterator insert(ValueMap::iterator, const ValueMap::value_type&);
00112     void clear() { values.clear(); }
00113 
00114     // ### Hack Alert
00115 
00116     ValueMap::iterator getValues() { return values.begin(); }
00117 
00118   private:
00119     ValueMap values;
00120 
00121     QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body);
00122 };
00123 
00124 //class FieldNotFoundException{};
00125 //class UnknownFieldName : public FieldNotFoundException{};
00126 //class IncorrectFieldType : public FieldNotFoundException{};
00127 }
00128 }
00129 
00130 
00131 #endif

Qpid C++ API Reference
Generated on Mon Aug 22 2011 for Qpid C++ Client API by doxygen 1.7.4