Qpid C++ Messaging API  0.26
 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  QPID_TYPES_EXTERN InvalidConversion(const std::string& msg);
42  QPID_TYPES_EXTERN ~InvalidConversion() throw();
43 };
44 
46  VAR_VOID = 0,
62 };
63 
64 QPID_TYPES_EXTERN std::string getTypeName(VariantType type);
65 
67 
68 class VariantImpl;
69 
74 {
75  public:
76  typedef std::map<std::string, Variant> Map;
77  typedef std::list<Variant> List;
78 
81  QPID_TYPES_EXTERN Variant(uint8_t);
82  QPID_TYPES_EXTERN Variant(uint16_t);
83  QPID_TYPES_EXTERN Variant(uint32_t);
84  QPID_TYPES_EXTERN Variant(uint64_t);
85  QPID_TYPES_EXTERN Variant(int8_t);
86  QPID_TYPES_EXTERN Variant(int16_t);
87  QPID_TYPES_EXTERN Variant(int32_t);
88  QPID_TYPES_EXTERN Variant(int64_t);
90  QPID_TYPES_EXTERN Variant(double);
91  QPID_TYPES_EXTERN Variant(const std::string&);
92  QPID_TYPES_EXTERN Variant(const char*);
97 
99 
100  QPID_TYPES_EXTERN VariantType getType() const;
101  QPID_TYPES_EXTERN bool isVoid() const;
102 
103  QPID_TYPES_EXTERN Variant& operator=(bool);
104  QPID_TYPES_EXTERN Variant& operator=(uint8_t);
105  QPID_TYPES_EXTERN Variant& operator=(uint16_t);
106  QPID_TYPES_EXTERN Variant& operator=(uint32_t);
107  QPID_TYPES_EXTERN Variant& operator=(uint64_t);
108  QPID_TYPES_EXTERN Variant& operator=(int8_t);
109  QPID_TYPES_EXTERN Variant& operator=(int16_t);
110  QPID_TYPES_EXTERN Variant& operator=(int32_t);
111  QPID_TYPES_EXTERN Variant& operator=(int64_t);
112  QPID_TYPES_EXTERN Variant& operator=(float);
113  QPID_TYPES_EXTERN Variant& operator=(double);
114  QPID_TYPES_EXTERN Variant& operator=(const std::string&);
115  QPID_TYPES_EXTERN Variant& operator=(const char*);
116  QPID_TYPES_EXTERN Variant& operator=(const Map&);
117  QPID_TYPES_EXTERN Variant& operator=(const List&);
118  QPID_TYPES_EXTERN Variant& operator=(const Variant&);
119  QPID_TYPES_EXTERN Variant& operator=(const Uuid&);
120 
125  QPID_TYPES_EXTERN Variant& parse(const std::string&);
126 
127  QPID_TYPES_EXTERN bool asBool() const;
128  QPID_TYPES_EXTERN uint8_t asUint8() const;
129  QPID_TYPES_EXTERN uint16_t asUint16() const;
130  QPID_TYPES_EXTERN uint32_t asUint32() const;
131  QPID_TYPES_EXTERN uint64_t asUint64() const;
132  QPID_TYPES_EXTERN int8_t asInt8() const;
133  QPID_TYPES_EXTERN int16_t asInt16() const;
134  QPID_TYPES_EXTERN int32_t asInt32() const;
135  QPID_TYPES_EXTERN int64_t asInt64() const;
136  QPID_TYPES_EXTERN float asFloat() const;
137  QPID_TYPES_EXTERN double asDouble() const;
138  QPID_TYPES_EXTERN std::string asString() const;
139  QPID_TYPES_EXTERN Uuid asUuid() const;
140 
141  QPID_TYPES_EXTERN operator bool() const;
142  QPID_TYPES_EXTERN operator uint8_t() const;
143  QPID_TYPES_EXTERN operator uint16_t() const;
144  QPID_TYPES_EXTERN operator uint32_t() const;
145  QPID_TYPES_EXTERN operator uint64_t() const;
146  QPID_TYPES_EXTERN operator int8_t() const;
147  QPID_TYPES_EXTERN operator int16_t() const;
148  QPID_TYPES_EXTERN operator int32_t() const;
149  QPID_TYPES_EXTERN operator int64_t() const;
150  QPID_TYPES_EXTERN operator float() const;
151  QPID_TYPES_EXTERN operator double() const;
152  QPID_TYPES_EXTERN operator std::string() const;
153  QPID_TYPES_EXTERN operator Uuid() const;
154 
155  QPID_TYPES_EXTERN const Map& asMap() const;
156  QPID_TYPES_EXTERN Map& asMap();
157  QPID_TYPES_EXTERN const List& asList() const;
158  QPID_TYPES_EXTERN List& asList();
163  QPID_TYPES_EXTERN const std::string& getString() const;
164  QPID_TYPES_EXTERN std::string& getString();
165 
166  QPID_TYPES_EXTERN void setEncoding(const std::string&);
167  QPID_TYPES_EXTERN const std::string& getEncoding() const;
168 
169  QPID_TYPES_EXTERN bool isEqualTo(const Variant& a) const;
170 
171  QPID_TYPES_EXTERN void reset();
172  private:
173  VariantImpl* impl;
174 };
175 
176 #ifndef SWIG
177 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& value);
178 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map);
179 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list);
180 QPID_TYPES_EXTERN bool operator==(const Variant& a, const Variant& b);
181 QPID_TYPES_EXTERN bool operator!=(const Variant& a, const Variant& b);
182 #endif
183 }} // namespace qpid::types
184 
185 #endif
Definition: Exception.h:31
Definition: Variant.h:53
Definition: Variant.h:73
QPID_TYPES_EXTERN bool operator==(const Uuid &, const Uuid &)
Definition: Variant.h:51
Definition: Uuid.h:32
Definition: Variant.h:58
Definition: Variant.h:60
Definition: Variant.h:54
Definition: Variant.h:49
Definition: Variant.h:52
QPID_TYPES_EXTERN bool operator!=(const Uuid &, const Uuid &)
Definition: Variant.h:46
Definition: Variant.h:39
Definition: Variant.h:55
VariantType
Definition: Variant.h:45
Definition: Variant.h:56
#define QPID_TYPES_CLASS_EXTERN
Definition: ImportExport.h:31
std::list< Variant > List
Definition: Variant.h:77
Definition: Variant.h:57
#define QPID_TYPES_EXTERN
Definition: ImportExport.h:30
Definition: Variant.h:61
Definition: Variant.h:47
Definition: Variant.h:50
Definition: Variant.h:59
QPID_TYPES_EXTERN std::string getTypeName(VariantType type)
std::map< std::string, Variant > Map
Definition: Variant.h:76
Definition: Variant.h:48
QPID_TYPES_EXTERN bool isIntegerType(VariantType type)
QPID_TYPES_EXTERN std::ostream & operator<<(std::ostream &, Uuid)