Go to the documentation of this file.00001 #ifndef _FieldTable_
00002 #define _FieldTable_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
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
00100
00101 QPID_COMMON_EXTERN void erase(const std::string& name);
00102
00103
00104 QPID_COMMON_EXTERN bool operator==(const FieldTable& other) const;
00105
00106
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;
00127 mutable bool newBytes;
00128
00129 QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body);
00130 };
00131
00132
00133
00134
00135 }
00136 }
00137
00138
00139 #endif