Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/console/Value.h
Go to the documentation of this file.
00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  *
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #ifndef _QPID_CONSOLE_VALUE_H_
00022 #define _QPID_CONSOLE_VALUE_H_
00023 
00024 #include "qpid/Exception.h"
00025 #include "qpid/framing/Uuid.h"
00026 #include "qpid/framing/FieldTable.h"
00027 #include "qpid/console/ObjectId.h"
00028 #include <boost/shared_ptr.hpp>
00029 
00030 namespace qpid {
00031 namespace framing {
00032     class Buffer;
00033 }
00034 namespace console {
00035 
00039     class Value {
00040 
00041     public:
00042         typedef boost::shared_ptr<Value> Ptr;
00043         virtual ~Value() {}
00044         virtual std::string str() const = 0;
00045 
00046         virtual bool isNull() const { return false; }
00047         virtual bool isObjectId() const { return false; }
00048         virtual bool isUint() const { return false; }
00049         virtual bool isInt() const { return false; }
00050         virtual bool isUint64() const { return false; }
00051         virtual bool isInt64() const { return false; }
00052         virtual bool isString() const { return false; }
00053         virtual bool isBool() const { return false; }
00054         virtual bool isFloat() const { return false; }
00055         virtual bool isDouble() const { return false; }
00056         virtual bool isUuid() const { return false; }
00057         virtual bool isMap() const { return false; }
00058 
00059         virtual ObjectId asObjectId() const { incompatible(); return ObjectId(); }
00060         virtual uint32_t asUint() const { incompatible(); return 0; }
00061         virtual int32_t asInt() const { incompatible(); return 0; }
00062         virtual uint64_t asUint64() const { incompatible(); return 0; }
00063         virtual int64_t asInt64() const { incompatible(); return 0; }
00064         virtual std::string asString() const { incompatible(); return std::string(); }
00065         virtual bool asBool() const { incompatible(); return false; }
00066         virtual float asFloat() const { incompatible(); return 0.0; }
00067         virtual double asDouble() const { incompatible(); return 0.0; }
00068         virtual framing::Uuid asUuid() const { incompatible(); return framing::Uuid(); }
00069         virtual framing::FieldTable asMap() const { incompatible(); return framing::FieldTable(); }
00070 
00071     private:
00072         void incompatible() const {
00073             throw Exception("Incompatible Type");
00074         }
00075     };
00076 
00077     class NullValue : public Value {
00078     public:
00079         NullValue() {}
00080         std::string str() const;
00081         bool isNull() const { return true; }
00082     };
00083 
00084     class RefValue : public Value {
00085     public:
00086         RefValue(ObjectId v) : value(v) {}
00087         RefValue(framing::Buffer& buffer);
00088         std::string str() const;
00089         bool isObjectId() const { return true; }
00090         ObjectId asObjectId() const { return value; }
00091     private:
00092         ObjectId value;
00093     };
00094 
00095     class UintValue : public Value {
00096     public:
00097         UintValue(uint32_t v) : value(v) {}
00098         std::string str() const;
00099         bool isUint() const { return true; }
00100         uint32_t asUint() const { return value; }
00101         bool isUint64() const { return true; }
00102         uint64_t asUint64() const { return (uint64_t) value; }
00103     private:
00104         uint32_t value;
00105     };
00106 
00107     class IntValue : public Value {
00108     public:
00109         IntValue(int32_t v) : value(v) {}
00110         std::string str() const;
00111         bool isInt() const { return true; }
00112         int32_t asInt() const { return value; }
00113         bool isInt64() const { return true; }
00114         int64_t asInt64() const { return (int64_t) value; }
00115     private:
00116         int32_t value;
00117     };
00118 
00119     class Uint64Value : public Value {
00120     public:
00121         Uint64Value(uint64_t v) : value(v) {}
00122         std::string str() const;
00123         bool isUint64() const { return true; }
00124         uint64_t asUint64() const { return value; }
00125     private:
00126         uint64_t value;
00127     };
00128 
00129     class Int64Value : public Value {
00130     public:
00131         Int64Value(int64_t v) : value(v) {}
00132         std::string str() const;
00133         bool isInt64() const { return true; }
00134         int64_t asInt64() const { return value; }
00135     private:
00136         int64_t value;
00137     };
00138 
00139     class StringValue : public Value {
00140     public:
00141         StringValue(const std::string& v) : value(v) {}
00142         StringValue(framing::Buffer& buffer, int tc);
00143         std::string str() const { return value; }
00144         bool isString() const { return true; }
00145         std::string asString() const { return value; }
00146     private:
00147         std::string value;
00148     };
00149 
00150     class BoolValue : public Value {
00151     public:
00152         BoolValue(bool v) : value(v) {}
00153         BoolValue(uint8_t v) : value(v != 0) {}
00154         std::string str() const;
00155         bool isBool() const { return true; }
00156         bool asBool() const { return value; }
00157     private:
00158         bool value;
00159     };
00160 
00161     class FloatValue : public Value {
00162     public:
00163         FloatValue(float v) : value(v) {}
00164         std::string str() const;
00165         bool isFloat() const { return true; }
00166         float asFloat() const { return value; }
00167         bool isDouble() const { return true; }
00168         double asDouble() const { return (double) value; }
00169     private:
00170         float value;
00171     };
00172 
00173     class DoubleValue : public Value {
00174     public:
00175         DoubleValue(double v) : value(v) {}
00176         std::string str() const;
00177         bool isDouble() const { return true; }
00178         double asDouble() const { return value; }
00179     private:
00180         double value;
00181     };
00182 
00183     class UuidValue : public Value {
00184     public:
00185         UuidValue(const framing::Uuid& v) : value(v) {}
00186         UuidValue(framing::Buffer& buffer);
00187         std::string str() const { return value.str(); }
00188         bool isUuid() const { return true; }
00189         framing::Uuid asUuid() const { return value; }
00190     private:
00191         framing::Uuid value;
00192     };
00193 
00194     class MapValue : public Value {
00195     public:
00196         MapValue(const framing::FieldTable& v) : value(v) {}
00197         MapValue(framing::Buffer& buffer);
00198         std::string str() const;
00199         bool isMap() const { return true; }
00200         framing::FieldTable asMap() const { return value; }
00201     private:
00202         framing::FieldTable value;
00203     };
00204 
00205     class ValueFactory {
00206     public:
00207         static Value::Ptr newValue(int typeCode, framing::Buffer& buffer);
00208         static void encodeValue(int typeCode, Value::Ptr value, framing::Buffer& buffer);
00209     };
00210 }
00211 }
00212 
00213 #endif

Qpid C++ API Reference
Generated on Mon Aug 22 2011 for Qpid C++ Client API by doxygen 1.7.4