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 #ifndef _FieldTable_
00002 #define _FieldTable_
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  *
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include "qpid/framing/amqp_types.h"
00026 #include "qpid/sys/Mutex.h"
00027 
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/shared_array.hpp>
00030 
00031 #include <iosfwd>
00032 #include <map>
00033 
00034 #include "qpid/CommonImportExport.h"
00035 
00036 namespace qpid {
00041 namespace framing {
00042 
00043 class Array;
00044 class FieldValue;
00045 class Buffer;
00046 
00053 class FieldTable
00054 {
00055   public:
00056     typedef boost::shared_ptr<FieldValue> ValuePtr;
00057     typedef std::map<std::string, ValuePtr> ValueMap;
00058     typedef ValueMap::iterator iterator;
00059     typedef ValueMap::const_iterator const_iterator;
00060     typedef ValueMap::const_reference const_reference;
00061     typedef ValueMap::reference reference;
00062     typedef ValueMap::value_type value_type;
00063 
00064     QPID_COMMON_EXTERN FieldTable();
00065     QPID_COMMON_EXTERN FieldTable(const FieldTable&);
00066     QPID_COMMON_EXTERN FieldTable& operator=(const FieldTable&);
00067     // Compiler default destructor fine
00068     QPID_COMMON_EXTERN uint32_t encodedSize() const;
00069     QPID_COMMON_EXTERN void encode(Buffer& buffer) const;
00070     QPID_COMMON_EXTERN void decode(Buffer& buffer);
00071 
00072     QPID_COMMON_EXTERN int count() const;
00073     QPID_COMMON_INLINE_EXTERN size_t size() const { return values.size(); }
00074     QPID_COMMON_INLINE_EXTERN bool empty() { return size() == 0; }
00075     QPID_COMMON_EXTERN void set(const std::string& name, const ValuePtr& value);
00076     QPID_COMMON_EXTERN ValuePtr get(const std::string& name) const;
00077     QPID_COMMON_INLINE_EXTERN bool isSet(const std::string& name) const { return get(name).get() != 0; }
00078 
00079     QPID_COMMON_EXTERN void setString(const std::string& name, const std::string& value);
00080     QPID_COMMON_EXTERN void setInt(const std::string& name, const int value);
00081     QPID_COMMON_EXTERN void setInt64(const std::string& name, const int64_t value);
00082     QPID_COMMON_EXTERN void setTimestamp(const std::string& name, const uint64_t value);
00083     QPID_COMMON_EXTERN void setUInt64(const std::string& name, const uint64_t value);
00084     QPID_COMMON_EXTERN void setTable(const std::string& name, const FieldTable& value);
00085     QPID_COMMON_EXTERN void setArray(const std::string& name, const Array& value);
00086     QPID_COMMON_EXTERN void setFloat(const std::string& name, const float value);
00087     QPID_COMMON_EXTERN void setDouble(const std::string& name, const double value);
00088     //void setDecimal(string& name, xxx& value);
00089 
00090     QPID_COMMON_EXTERN int getAsInt(const std::string& name) const;
00091     QPID_COMMON_EXTERN uint64_t getAsUInt64(const std::string& name) const;
00092     QPID_COMMON_EXTERN int64_t getAsInt64(const std::string& name) const;
00093     QPID_COMMON_EXTERN std::string getAsString(const std::string& name) const;
00094 
00095     QPID_COMMON_EXTERN bool getTable(const std::string& name, FieldTable& value) const;
00096     QPID_COMMON_EXTERN bool getArray(const std::string& name, Array& value) const;
00097     QPID_COMMON_EXTERN bool getFloat(const std::string& name, float& value) const;
00098     QPID_COMMON_EXTERN bool getDouble(const std::string& name, double& value) const;
00099     //QPID_COMMON_EXTERN bool getTimestamp(const std::string& name, uint64_t& value) const;
00100     //QPID_COMMON_EXTERN bool getDecimal(string& name, xxx& value);
00101     QPID_COMMON_EXTERN void erase(const std::string& name);
00102 
00103 
00104     QPID_COMMON_EXTERN bool operator==(const FieldTable& other) const;
00105 
00106     // Map-like interface.
00107     QPID_COMMON_EXTERN ValueMap::const_iterator begin() const;
00108     QPID_COMMON_EXTERN ValueMap::const_iterator end() const;
00109     QPID_COMMON_EXTERN ValueMap::const_iterator find(const std::string& s) const;
00110 
00111     QPID_COMMON_EXTERN ValueMap::iterator begin();
00112     QPID_COMMON_EXTERN ValueMap::iterator end();
00113     QPID_COMMON_EXTERN ValueMap::iterator find(const std::string& s);
00114 
00115     QPID_COMMON_EXTERN std::pair <ValueMap::iterator, bool> insert(const ValueMap::value_type&);
00116     QPID_COMMON_EXTERN ValueMap::iterator insert(ValueMap::iterator, const ValueMap::value_type&);
00117     QPID_COMMON_EXTERN void clear();
00118 
00119   private:
00120     void realDecode() const;
00121     void flushRawCache();
00122 
00123     mutable qpid::sys::Mutex lock;
00124     mutable ValueMap values;
00125     mutable boost::shared_array<uint8_t> cachedBytes;
00126     mutable uint32_t cachedSize; // if = 0 then non cached size as 0 is not a legal size
00127     mutable bool newBytes;
00128 
00129     QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body);
00130 };
00131 
00132 //class FieldNotFoundException{};
00133 //class UnknownFieldName : public FieldNotFoundException{};
00134 //class IncorrectFieldType : public FieldNotFoundException{};
00135 }
00136 }
00137 
00138 
00139 #endif

Qpid C++ API Reference
Generated on Thu Aug 23 2012 for Qpid C++ Client API by doxygen 1.7.5