Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/types/Variant.h
Go to the documentation of this file.
00001 #ifndef QPID_TYPES_VARIANT_H
00002 #define QPID_TYPES_VARIANT_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
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/types/ImportExport.h"
00032 
00033 namespace qpid {
00034 namespace types {
00035 
00039 struct QPID_TYPES_CLASS_EXTERN 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 QPID_TYPES_EXTERN std::string getTypeName(VariantType type);
00064 
00065 QPID_TYPES_EXTERN bool isIntegerType(VariantType type);
00066 
00067 class VariantImpl;
00068 
00072 class QPID_TYPES_CLASS_EXTERN Variant
00073 {
00074   public:
00075     typedef std::map<std::string, Variant> Map;
00076     typedef std::list<Variant> List;
00077 
00078     QPID_TYPES_EXTERN Variant();
00079     QPID_TYPES_EXTERN Variant(bool);
00080     QPID_TYPES_EXTERN Variant(uint8_t);
00081     QPID_TYPES_EXTERN Variant(uint16_t);
00082     QPID_TYPES_EXTERN Variant(uint32_t);
00083     QPID_TYPES_EXTERN Variant(uint64_t);
00084     QPID_TYPES_EXTERN Variant(int8_t);
00085     QPID_TYPES_EXTERN Variant(int16_t);
00086     QPID_TYPES_EXTERN Variant(int32_t);
00087     QPID_TYPES_EXTERN Variant(int64_t);
00088     QPID_TYPES_EXTERN Variant(float);
00089     QPID_TYPES_EXTERN Variant(double);
00090     QPID_TYPES_EXTERN Variant(const std::string&);
00091     QPID_TYPES_EXTERN Variant(const char*);
00092     QPID_TYPES_EXTERN Variant(const Map&);
00093     QPID_TYPES_EXTERN Variant(const List&);
00094     QPID_TYPES_EXTERN Variant(const Variant&);
00095     QPID_TYPES_EXTERN Variant(const Uuid&);
00096 
00097     QPID_TYPES_EXTERN ~Variant();
00098 
00099     QPID_TYPES_EXTERN VariantType getType() const;
00100     QPID_TYPES_EXTERN bool isVoid() const;
00101     
00102     QPID_TYPES_EXTERN Variant& operator=(bool);
00103     QPID_TYPES_EXTERN Variant& operator=(uint8_t);
00104     QPID_TYPES_EXTERN Variant& operator=(uint16_t);
00105     QPID_TYPES_EXTERN Variant& operator=(uint32_t);
00106     QPID_TYPES_EXTERN Variant& operator=(uint64_t);
00107     QPID_TYPES_EXTERN Variant& operator=(int8_t);
00108     QPID_TYPES_EXTERN Variant& operator=(int16_t);
00109     QPID_TYPES_EXTERN Variant& operator=(int32_t);
00110     QPID_TYPES_EXTERN Variant& operator=(int64_t);
00111     QPID_TYPES_EXTERN Variant& operator=(float);
00112     QPID_TYPES_EXTERN Variant& operator=(double);
00113     QPID_TYPES_EXTERN Variant& operator=(const std::string&);
00114     QPID_TYPES_EXTERN Variant& operator=(const char*);
00115     QPID_TYPES_EXTERN Variant& operator=(const Map&);
00116     QPID_TYPES_EXTERN Variant& operator=(const List&);
00117     QPID_TYPES_EXTERN Variant& operator=(const Variant&);
00118     QPID_TYPES_EXTERN Variant& operator=(const Uuid&);
00119 
00124     QPID_TYPES_EXTERN Variant& parse(const std::string&);
00125 
00126     QPID_TYPES_EXTERN bool asBool() const;
00127     QPID_TYPES_EXTERN uint8_t asUint8() const;
00128     QPID_TYPES_EXTERN uint16_t asUint16() const;
00129     QPID_TYPES_EXTERN uint32_t asUint32() const;
00130     QPID_TYPES_EXTERN uint64_t asUint64() const;
00131     QPID_TYPES_EXTERN int8_t asInt8() const;
00132     QPID_TYPES_EXTERN int16_t asInt16() const;
00133     QPID_TYPES_EXTERN int32_t asInt32() const;
00134     QPID_TYPES_EXTERN int64_t asInt64() const;
00135     QPID_TYPES_EXTERN float asFloat() const;
00136     QPID_TYPES_EXTERN double asDouble() const;
00137     QPID_TYPES_EXTERN std::string asString() const;
00138     QPID_TYPES_EXTERN Uuid asUuid() const;
00139 
00140     QPID_TYPES_EXTERN operator bool() const;
00141     QPID_TYPES_EXTERN operator uint8_t() const;
00142     QPID_TYPES_EXTERN operator uint16_t() const;
00143     QPID_TYPES_EXTERN operator uint32_t() const;
00144     QPID_TYPES_EXTERN operator uint64_t() const;
00145     QPID_TYPES_EXTERN operator int8_t() const;
00146     QPID_TYPES_EXTERN operator int16_t() const;
00147     QPID_TYPES_EXTERN operator int32_t() const;
00148     QPID_TYPES_EXTERN operator int64_t() const;
00149     QPID_TYPES_EXTERN operator float() const;
00150     QPID_TYPES_EXTERN operator double() const;
00151     QPID_TYPES_EXTERN operator std::string() const;
00152     QPID_TYPES_EXTERN operator Uuid() const;
00153 
00154     QPID_TYPES_EXTERN const Map& asMap() const;
00155     QPID_TYPES_EXTERN Map& asMap();
00156     QPID_TYPES_EXTERN const List& asList() const;
00157     QPID_TYPES_EXTERN List& asList();
00162     QPID_TYPES_EXTERN const std::string& getString() const;
00163     QPID_TYPES_EXTERN std::string& getString();
00164 
00165     QPID_TYPES_EXTERN void setEncoding(const std::string&);
00166     QPID_TYPES_EXTERN const std::string& getEncoding() const;
00167 
00168     QPID_TYPES_EXTERN bool isEqualTo(const Variant& a) const;
00169 
00170     QPID_TYPES_EXTERN void reset();
00171   private:
00172     VariantImpl* impl;
00173 };
00174 
00175 #ifndef SWIG
00176 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& value);
00177 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map);
00178 QPID_TYPES_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list);
00179 QPID_TYPES_EXTERN bool operator==(const Variant& a, const Variant& b);
00180 #endif
00181 }} // namespace qpid::types
00182 
00183 #endif  

Qpid C++ API Reference
Generated on Thu Aug 23 2012 for Qpid C++ Client API by doxygen 1.7.5