00001 #ifndef QPID_TYPES_VARIANT_H
00002 #define QPID_TYPES_VARIANT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <list>
00025 #include <map>
00026 #include <ostream>
00027 #include <string>
00028 #include "Uuid.h"
00029 #include "qpid/types/Exception.h"
00030 #include "qpid/sys/IntegerTypes.h"
00031 #include "qpid/CommonImportExport.h"
00032
00033 namespace qpid {
00034 namespace types {
00035
00039 struct InvalidConversion : public Exception
00040 {
00041 InvalidConversion(const std::string& msg);
00042 };
00043
00044 enum VariantType {
00045 VAR_VOID = 0,
00046 VAR_BOOL,
00047 VAR_UINT8,
00048 VAR_UINT16,
00049 VAR_UINT32,
00050 VAR_UINT64,
00051 VAR_INT8,
00052 VAR_INT16,
00053 VAR_INT32,
00054 VAR_INT64,
00055 VAR_FLOAT,
00056 VAR_DOUBLE,
00057 VAR_STRING,
00058 VAR_MAP,
00059 VAR_LIST,
00060 VAR_UUID
00061 };
00062
00063 class VariantImpl;
00064
00068 class Variant
00069 {
00070 public:
00071 typedef std::map<std::string, Variant> Map;
00072 typedef std::list<Variant> List;
00073
00074 QPID_COMMON_EXTERN Variant();
00075 QPID_COMMON_EXTERN Variant(bool);
00076 QPID_COMMON_EXTERN Variant(uint8_t);
00077 QPID_COMMON_EXTERN Variant(uint16_t);
00078 QPID_COMMON_EXTERN Variant(uint32_t);
00079 QPID_COMMON_EXTERN Variant(uint64_t);
00080 QPID_COMMON_EXTERN Variant(int8_t);
00081 QPID_COMMON_EXTERN Variant(int16_t);
00082 QPID_COMMON_EXTERN Variant(int32_t);
00083 QPID_COMMON_EXTERN Variant(int64_t);
00084 QPID_COMMON_EXTERN Variant(float);
00085 QPID_COMMON_EXTERN Variant(double);
00086 QPID_COMMON_EXTERN Variant(const std::string&);
00087 QPID_COMMON_EXTERN Variant(const char*);
00088 QPID_COMMON_EXTERN Variant(const Map&);
00089 QPID_COMMON_EXTERN Variant(const List&);
00090 QPID_COMMON_EXTERN Variant(const Variant&);
00091 QPID_COMMON_EXTERN Variant(const Uuid&);
00092
00093 QPID_COMMON_EXTERN ~Variant();
00094
00095 QPID_COMMON_EXTERN VariantType getType() const;
00096 QPID_COMMON_EXTERN bool isVoid() const;
00097
00098 QPID_COMMON_EXTERN Variant& operator=(bool);
00099 QPID_COMMON_EXTERN Variant& operator=(uint8_t);
00100 QPID_COMMON_EXTERN Variant& operator=(uint16_t);
00101 QPID_COMMON_EXTERN Variant& operator=(uint32_t);
00102 QPID_COMMON_EXTERN Variant& operator=(uint64_t);
00103 QPID_COMMON_EXTERN Variant& operator=(int8_t);
00104 QPID_COMMON_EXTERN Variant& operator=(int16_t);
00105 QPID_COMMON_EXTERN Variant& operator=(int32_t);
00106 QPID_COMMON_EXTERN Variant& operator=(int64_t);
00107 QPID_COMMON_EXTERN Variant& operator=(float);
00108 QPID_COMMON_EXTERN Variant& operator=(double);
00109 QPID_COMMON_EXTERN Variant& operator=(const std::string&);
00110 QPID_COMMON_EXTERN Variant& operator=(const char*);
00111 QPID_COMMON_EXTERN Variant& operator=(const Map&);
00112 QPID_COMMON_EXTERN Variant& operator=(const List&);
00113 QPID_COMMON_EXTERN Variant& operator=(const Variant&);
00114 QPID_COMMON_EXTERN Variant& operator=(const Uuid&);
00115
00116 QPID_COMMON_EXTERN bool asBool() const;
00117 QPID_COMMON_EXTERN uint8_t asUint8() const;
00118 QPID_COMMON_EXTERN uint16_t asUint16() const;
00119 QPID_COMMON_EXTERN uint32_t asUint32() const;
00120 QPID_COMMON_EXTERN uint64_t asUint64() const;
00121 QPID_COMMON_EXTERN int8_t asInt8() const;
00122 QPID_COMMON_EXTERN int16_t asInt16() const;
00123 QPID_COMMON_EXTERN int32_t asInt32() const;
00124 QPID_COMMON_EXTERN int64_t asInt64() const;
00125 QPID_COMMON_EXTERN float asFloat() const;
00126 QPID_COMMON_EXTERN double asDouble() const;
00127 QPID_COMMON_EXTERN std::string asString() const;
00128 QPID_COMMON_EXTERN Uuid asUuid() const;
00129
00130 QPID_COMMON_EXTERN operator bool() const;
00131 QPID_COMMON_EXTERN operator uint8_t() const;
00132 QPID_COMMON_EXTERN operator uint16_t() const;
00133 QPID_COMMON_EXTERN operator uint32_t() const;
00134 QPID_COMMON_EXTERN operator uint64_t() const;
00135 QPID_COMMON_EXTERN operator int8_t() const;
00136 QPID_COMMON_EXTERN operator int16_t() const;
00137 QPID_COMMON_EXTERN operator int32_t() const;
00138 QPID_COMMON_EXTERN operator int64_t() const;
00139 QPID_COMMON_EXTERN operator float() const;
00140 QPID_COMMON_EXTERN operator double() const;
00141 QPID_COMMON_EXTERN operator std::string() const;
00142 QPID_COMMON_EXTERN operator Uuid() const;
00143
00144 QPID_COMMON_EXTERN const Map& asMap() const;
00145 QPID_COMMON_EXTERN Map& asMap();
00146 QPID_COMMON_EXTERN const List& asList() const;
00147 QPID_COMMON_EXTERN List& asList();
00152 QPID_COMMON_EXTERN const std::string& getString() const;
00153 QPID_COMMON_EXTERN std::string& getString();
00154
00155 QPID_COMMON_EXTERN void setEncoding(const std::string&);
00156 QPID_COMMON_EXTERN const std::string& getEncoding() const;
00157
00158 QPID_COMMON_EXTERN bool isEqualTo(const Variant& a) const;
00159
00160 QPID_COMMON_EXTERN void reset();
00161 private:
00162 VariantImpl* impl;
00163 };
00164
00165 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& value);
00166 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map);
00167 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list);
00168 QPID_COMMON_EXTERN bool operator==(const Variant& a, const Variant& b);
00169 }}
00170
00171 #endif