Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
FieldTable.h
Go to the documentation of this file.
1 #ifndef _FieldTable_
2 #define _FieldTable_
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
26 #include "qpid/sys/Mutex.h"
27 
28 #include <boost/shared_ptr.hpp>
29 #include <boost/shared_array.hpp>
30 
31 #include <iosfwd>
32 #include <map>
33 
35 
36 namespace qpid {
41 namespace framing {
42 
43 class Array;
44 class FieldValue;
45 class Buffer;
46 
54 {
55  public:
56  typedef boost::shared_ptr<FieldValue> ValuePtr;
57  typedef std::map<std::string, ValuePtr> ValueMap;
58  typedef ValueMap::iterator iterator;
59  typedef ValueMap::const_iterator const_iterator;
60  typedef ValueMap::const_reference const_reference;
61  typedef ValueMap::reference reference;
62  typedef ValueMap::value_type value_type;
63 
67  // Compiler default destructor fine
69  QPID_COMMON_EXTERN void encode(Buffer& buffer) const;
70  QPID_COMMON_EXTERN void decode(Buffer& buffer);
71 
72  QPID_COMMON_EXTERN int count() const;
73  QPID_COMMON_INLINE_EXTERN size_t size() const { return values.size(); }
74  QPID_COMMON_INLINE_EXTERN bool empty() { return size() == 0; }
75  QPID_COMMON_EXTERN void set(const std::string& name, const ValuePtr& value);
76  QPID_COMMON_EXTERN ValuePtr get(const std::string& name) const;
77  QPID_COMMON_INLINE_EXTERN bool isSet(const std::string& name) const { return get(name).get() != 0; }
78 
79  QPID_COMMON_EXTERN void setString(const std::string& name, const std::string& value);
80  QPID_COMMON_EXTERN void setInt(const std::string& name, const int value);
81  QPID_COMMON_EXTERN void setInt64(const std::string& name, const int64_t value);
82  QPID_COMMON_EXTERN void setTimestamp(const std::string& name, const uint64_t value);
83  QPID_COMMON_EXTERN void setUInt64(const std::string& name, const uint64_t value);
84  QPID_COMMON_EXTERN void setTable(const std::string& name, const FieldTable& value);
85  QPID_COMMON_EXTERN void setArray(const std::string& name, const Array& value);
86  QPID_COMMON_EXTERN void setFloat(const std::string& name, const float value);
87  QPID_COMMON_EXTERN void setDouble(const std::string& name, const double value);
88  //void setDecimal(string& name, xxx& value);
89 
90  QPID_COMMON_EXTERN int getAsInt(const std::string& name) const;
91  QPID_COMMON_EXTERN uint64_t getAsUInt64(const std::string& name) const;
92  QPID_COMMON_EXTERN int64_t getAsInt64(const std::string& name) const;
93  QPID_COMMON_EXTERN std::string getAsString(const std::string& name) const;
94 
95  QPID_COMMON_EXTERN bool getTable(const std::string& name, FieldTable& value) const;
96  QPID_COMMON_EXTERN bool getArray(const std::string& name, Array& value) const;
97  QPID_COMMON_EXTERN bool getFloat(const std::string& name, float& value) const;
98  QPID_COMMON_EXTERN bool getDouble(const std::string& name, double& value) const;
99  //QPID_COMMON_EXTERN bool getTimestamp(const std::string& name, uint64_t& value) const;
100  //QPID_COMMON_EXTERN bool getDecimal(string& name, xxx& value);
101  QPID_COMMON_EXTERN void erase(const std::string& name);
102 
103 
104  QPID_COMMON_EXTERN bool operator==(const FieldTable& other) const;
105 
106  // Map-like interface.
107  QPID_COMMON_EXTERN ValueMap::const_iterator begin() const;
108  QPID_COMMON_EXTERN ValueMap::const_iterator end() const;
109  QPID_COMMON_EXTERN ValueMap::const_iterator find(const std::string& s) const;
110 
111  QPID_COMMON_EXTERN ValueMap::iterator begin();
112  QPID_COMMON_EXTERN ValueMap::iterator end();
113  QPID_COMMON_EXTERN ValueMap::iterator find(const std::string& s);
114 
115  QPID_COMMON_EXTERN std::pair <ValueMap::iterator, bool> insert(const ValueMap::value_type&);
116  QPID_COMMON_EXTERN ValueMap::iterator insert(ValueMap::iterator, const ValueMap::value_type&);
117  QPID_COMMON_EXTERN void clear();
118 
119  private:
120  void realDecode() const;
121  void flushRawCache();
122 
123  mutable qpid::sys::Mutex lock;
124  mutable ValueMap values;
125  mutable boost::shared_array<uint8_t> cachedBytes;
126  mutable uint32_t cachedSize; // if = 0 then non cached size as 0 is not a legal size
127  mutable bool newBytes;
128 
129  QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body);
130 };
131 
132 //class FieldNotFoundException{};
133 //class UnknownFieldName : public FieldNotFoundException{};
134 //class IncorrectFieldType : public FieldNotFoundException{};
135 }
136 }
137 
138 
139 #endif

Qpid C++ API Reference
Generated on Fri Aug 29 2014 for Qpid C++ Client API by doxygen 1.8.3.1