Qpid C++ Messaging API  0.24
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Variant.h
Go to the documentation of this file.
1 #ifndef QPID_TYPES_VARIANT_H
2 #define QPID_TYPES_VARIANT_H
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 #include <list>
25 #include <map>
26 #include <ostream>
27 #include <string>
28 #include "Uuid.h"
29 #include "qpid/types/Exception.h"
30 #include "qpid/sys/IntegerTypes.h"
32 
33 namespace qpid {
34 namespace types {
35 
40 {
41  InvalidConversion(const std::string& msg);
42 };
43 
45  VAR_VOID = 0,
61 };
62 
63 QPID_TYPES_EXTERN std::string getTypeName(VariantType type);
64 
66 
67 class VariantImpl;
68 
73 {
74  public:
75  typedef std::map<std::string, Variant> Map;
76  typedef std::list<Variant> List;
77 
80  QPID_TYPES_EXTERN Variant(uint8_t);
81  QPID_TYPES_EXTERN Variant(uint16_t);
82  QPID_TYPES_EXTERN Variant(uint32_t);
83  QPID_TYPES_EXTERN Variant(uint64_t);
84  QPID_TYPES_EXTERN Variant(int8_t);
85  QPID_TYPES_EXTERN Variant(int16_t);
86  QPID_TYPES_EXTERN Variant(int32_t);
87  QPID_TYPES_EXTERN Variant(int64_t);
89  QPID_TYPES_EXTERN Variant(double);
90  QPID_TYPES_EXTERN Variant(const std::string&);
91  QPID_TYPES_EXTERN Variant(const char*);
96 
98 
99  QPID_TYPES_EXTERN VariantType getType() const;
100  QPID_TYPES_EXTERN bool isVoid() const;
101 
102  QPID_TYPES_EXTERN Variant& operator=(bool);
103  QPID_TYPES_EXTERN Variant& operator=(uint8_t);
104  QPID_TYPES_EXTERN Variant& operator=(uint16_t);
105  QPID_TYPES_EXTERN Variant& operator=(uint32_t);
106  QPID_TYPES_EXTERN Variant& operator=(uint64_t);
107  QPID_TYPES_EXTERN Variant& operator=(int8_t);
108  QPID_TYPES_EXTERN Variant& operator=(int16_t);
109  QPID_TYPES_EXTERN Variant& operator=(int32_t);
110  QPID_TYPES_EXTERN Variant& operator=(int64_t);
111  QPID_TYPES_EXTERN Variant& operator=(float);
112  QPID_TYPES_EXTERN Variant& operator=(double);
113  QPID_TYPES_EXTERN Variant& operator=(const std::string&);
114  QPID_TYPES_EXTERN Variant& operator=(const char*);
115  QPID_TYPES_EXTERN Variant& operator=(const Map&);
116  QPID_TYPES_EXTERN Variant& operator=(const List&);
117  QPID_TYPES_EXTERN Variant& operator=(const Variant&);
118  QPID_TYPES_EXTERN Variant& operator=(const Uuid&);
119 
124  QPID_TYPES_EXTERN Variant& parse(const std::string&);
125 
126  QPID_TYPES_EXTERN bool asBool() const;
127  QPID_TYPES_EXTERN uint8_t asUint8() const;
128  QPID_TYPES_EXTERN uint16_t asUint16() const;
129  QPID_TYPES_EXTERN uint32_t asUint32() const;
130  QPID_TYPES_EXTERN uint64_t asUint64() const;
131  QPID_TYPES_EXTERN int8_t asInt8() const;
132  QPID_TYPES_EXTERN int16_t asInt16() const;
133  QPID_TYPES_EXTERN int32_t asInt32() const;
134  QPID_TYPES_EXTERN int64_t asInt64() const;
135  QPID_TYPES_EXTERN float asFloat() const;
136  QPID_TYPES_EXTERN double asDouble() const;
137  QPID_TYPES_EXTERN std::string asString() const;
138  QPID_TYPES_EXTERN Uuid asUuid() const;
139 
140  QPID_TYPES_EXTERN operator bool() const;
141  QPID_TYPES_EXTERN operator uint8_t() const;
142  QPID_TYPES_EXTERN operator uint16_t() const;
143  QPID_TYPES_EXTERN operator uint32_t() const;
144  QPID_TYPES_EXTERN operator uint64_t() const;
145  QPID_TYPES_EXTERN operator int8_t() const;
146  QPID_TYPES_EXTERN operator int16_t() const;
147  QPID_TYPES_EXTERN operator int32_t() const;
148  QPID_TYPES_EXTERN operator int64_t() const;
149  QPID_TYPES_EXTERN operator float() const;
150  QPID_TYPES_EXTERN operator double() const;
151  QPID_TYPES_EXTERN operator std::string() const;
152  QPID_TYPES_EXTERN operator Uuid() const;
153 
154  QPID_TYPES_EXTERN const Map& asMap() const;
155  QPID_TYPES_EXTERN Map& asMap();
156  QPID_TYPES_EXTERN const List& asList() const;
157  QPID_TYPES_EXTERN List& asList();
162  QPID_TYPES_EXTERN const std::string& getString() const;
163  QPID_TYPES_EXTERN std::string& getString();
164 
165  QPID_TYPES_EXTERN void setEncoding(const std::string&);
166  QPID_TYPES_EXTERN const std::string& getEncoding() const;
167 
168  QPID_TYPES_EXTERN bool isEqualTo(const Variant& a) const;
169 
170  QPID_TYPES_EXTERN void reset();
171  private:
172  VariantImpl* impl;
173 };
174 
175 #ifndef SWIG
176 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& value);
177 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map);
178 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list);
179 QPID_TYPES_EXTERN bool operator==(const Variant& a, const Variant& b);
180 QPID_TYPES_EXTERN bool operator!=(const Variant& a, const Variant& b);
181 #endif
182 }} // namespace qpid::types
183 
184 #endif