Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
Value.h
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 #ifndef _QPID_CONSOLE_VALUE_H_
22 #define _QPID_CONSOLE_VALUE_H_
23 
24 #include "qpid/Exception.h"
25 #include "qpid/framing/Uuid.h"
27 #include "qpid/console/ObjectId.h"
28 #include <boost/shared_ptr.hpp>
29 
30 namespace qpid {
31 namespace framing {
32  class Buffer;
33 }
34 namespace console {
35 
39  class Value {
40 
41  public:
42  typedef boost::shared_ptr<Value> Ptr;
43  virtual ~Value() {}
44  virtual std::string str() const = 0;
45 
46  virtual bool isNull() const { return false; }
47  virtual bool isObjectId() const { return false; }
48  virtual bool isUint() const { return false; }
49  virtual bool isInt() const { return false; }
50  virtual bool isUint64() const { return false; }
51  virtual bool isInt64() const { return false; }
52  virtual bool isString() const { return false; }
53  virtual bool isBool() const { return false; }
54  virtual bool isFloat() const { return false; }
55  virtual bool isDouble() const { return false; }
56  virtual bool isUuid() const { return false; }
57  virtual bool isMap() const { return false; }
58 
59  virtual ObjectId asObjectId() const { incompatible(); return ObjectId(); }
60  virtual uint32_t asUint() const { incompatible(); return 0; }
61  virtual int32_t asInt() const { incompatible(); return 0; }
62  virtual uint64_t asUint64() const { incompatible(); return 0; }
63  virtual int64_t asInt64() const { incompatible(); return 0; }
64  virtual std::string asString() const { incompatible(); return std::string(); }
65  virtual bool asBool() const { incompatible(); return false; }
66  virtual float asFloat() const { incompatible(); return 0.0; }
67  virtual double asDouble() const { incompatible(); return 0.0; }
68  virtual framing::Uuid asUuid() const { incompatible(); return framing::Uuid(); }
69  virtual framing::FieldTable asMap() const { incompatible(); return framing::FieldTable(); }
70 
71  private:
72  void incompatible() const {
73  throw Exception("Incompatible Type");
74  }
75  };
76 
77  class NullValue : public Value {
78  public:
79  NullValue() {}
80  std::string str() const;
81  bool isNull() const { return true; }
82  };
83 
84  class RefValue : public Value {
85  public:
86  RefValue(ObjectId v) : value(v) {}
87  RefValue(framing::Buffer& buffer);
88  std::string str() const;
89  bool isObjectId() const { return true; }
90  ObjectId asObjectId() const { return value; }
91  private:
92  ObjectId value;
93  };
94 
95  class UintValue : public Value {
96  public:
97  UintValue(uint32_t v) : value(v) {}
98  std::string str() const;
99  bool isUint() const { return true; }
100  uint32_t asUint() const { return value; }
101  bool isUint64() const { return true; }
102  uint64_t asUint64() const { return (uint64_t) value; }
103  private:
104  uint32_t value;
105  };
106 
107  class IntValue : public Value {
108  public:
109  IntValue(int32_t v) : value(v) {}
110  std::string str() const;
111  bool isInt() const { return true; }
112  int32_t asInt() const { return value; }
113  bool isInt64() const { return true; }
114  int64_t asInt64() const { return (int64_t) value; }
115  private:
116  int32_t value;
117  };
118 
119  class Uint64Value : public Value {
120  public:
121  Uint64Value(uint64_t v) : value(v) {}
122  std::string str() const;
123  bool isUint64() const { return true; }
124  uint64_t asUint64() const { return value; }
125  private:
126  uint64_t value;
127  };
128 
129  class Int64Value : public Value {
130  public:
131  Int64Value(int64_t v) : value(v) {}
132  std::string str() const;
133  bool isInt64() const { return true; }
134  int64_t asInt64() const { return value; }
135  private:
136  int64_t value;
137  };
138 
139  class StringValue : public Value {
140  public:
141  StringValue(const std::string& v) : value(v) {}
142  StringValue(framing::Buffer& buffer, int tc);
143  std::string str() const { return value; }
144  bool isString() const { return true; }
145  std::string asString() const { return value; }
146  private:
147  std::string value;
148  };
149 
150  class BoolValue : public Value {
151  public:
152  BoolValue(bool v) : value(v) {}
153  BoolValue(uint8_t v) : value(v != 0) {}
154  std::string str() const;
155  bool isBool() const { return true; }
156  bool asBool() const { return value; }
157  private:
158  bool value;
159  };
160 
161  class FloatValue : public Value {
162  public:
163  FloatValue(float v) : value(v) {}
164  std::string str() const;
165  bool isFloat() const { return true; }
166  float asFloat() const { return value; }
167  bool isDouble() const { return true; }
168  double asDouble() const { return (double) value; }
169  private:
170  float value;
171  };
172 
173  class DoubleValue : public Value {
174  public:
175  DoubleValue(double v) : value(v) {}
176  std::string str() const;
177  bool isDouble() const { return true; }
178  double asDouble() const { return value; }
179  private:
180  double value;
181  };
182 
183  class UuidValue : public Value {
184  public:
185  UuidValue(const framing::Uuid& v) : value(v) {}
186  UuidValue(framing::Buffer& buffer);
187  std::string str() const { return value.str(); }
188  bool isUuid() const { return true; }
189  framing::Uuid asUuid() const { return value; }
190  private:
191  framing::Uuid value;
192  };
193 
194  class MapValue : public Value {
195  public:
196  MapValue(const framing::FieldTable& v) : value(v) {}
197  MapValue(framing::Buffer& buffer);
198  std::string str() const;
199  bool isMap() const { return true; }
200  framing::FieldTable asMap() const { return value; }
201  private:
202  framing::FieldTable value;
203  };
204 
205  class ValueFactory {
206  public:
207  static Value::Ptr newValue(int typeCode, framing::Buffer& buffer);
208  static void encodeValue(int typeCode, Value::Ptr value, framing::Buffer& buffer);
209  };
210 }
211 }
212 
213 #endif
double asDouble() const
Definition: Value.h:178
static void encodeValue(int typeCode, Value::Ptr value, framing::Buffer &buffer)
bool asBool() const
Definition: Value.h:156
bool isNull() const
Definition: Value.h:81
virtual bool isString() const
Definition: Value.h:52
virtual float asFloat() const
Definition: Value.h:66
uint64_t asUint64() const
Definition: Value.h:124
bool isUuid() const
Definition: Value.h:188
int32_t asInt() const
Definition: Value.h:112
std::string str() const
virtual bool isDouble() const
Definition: Value.h:55
UuidValue(const framing::Uuid &v)
Definition: Value.h:185
virtual bool asBool() const
Definition: Value.h:65
virtual bool isInt() const
Definition: Value.h:49
virtual bool isUint() const
Definition: Value.h:48
int64_t asInt64() const
Definition: Value.h:114
BoolValue(uint8_t v)
Definition: Value.h:153
boost::shared_ptr< Value > Ptr
Definition: Value.h:42
virtual uint32_t asUint() const
Definition: Value.h:60
virtual bool isNull() const
Definition: Value.h:46
virtual bool isBool() const
Definition: Value.h:53
virtual uint64_t asUint64() const
Definition: Value.h:62
bool isDouble() const
Definition: Value.h:177
std::string str() const
virtual std::string str() const =0
Int64Value(int64_t v)
Definition: Value.h:131
TypeCode typeCode(uint8_t)
Throw exception if not a valid TypeCode.
bool isMap() const
Definition: Value.h:199
bool isDouble() const
Definition: Value.h:167
int int32_t
Definition: IntegerTypes.h:28
RefValue(ObjectId v)
Definition: Value.h:86
std::string str() const
Definition: Value.h:143
Base class for Qpid runtime exceptions.
Definition: Exception.h:39
uint64_t asUint64() const
Definition: Value.h:102
double asDouble() const
Definition: Value.h:168
virtual std::string asString() const
Definition: Value.h:64
IntValue(int32_t v)
Definition: Value.h:109
bool isUint() const
Definition: Value.h:99
virtual int64_t asInt64() const
Definition: Value.h:63
int64_t asInt64() const
Definition: Value.h:134
UintValue(uint32_t v)
Definition: Value.h:97
unsigned int uint32_t
Definition: IntegerTypes.h:27
bool isObjectId() const
Definition: Value.h:89
static Value::Ptr newValue(int typeCode, framing::Buffer &buffer)
std::string str() const
virtual bool isUuid() const
Definition: Value.h:56
ObjectId asObjectId() const
Definition: Value.h:90
unsigned char uint8_t
Definition: IntegerTypes.h:24
virtual double asDouble() const
Definition: Value.h:67
std::string str() const
String value in format 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb.
bool isInt() const
Definition: Value.h:111
framing::Uuid asUuid() const
Definition: Value.h:189
A UUID is represented as a boost::array of 16 bytes.
Definition: Uuid.h:44
std::string asString() const
Definition: Value.h:145
virtual framing::Uuid asUuid() const
Definition: Value.h:68
std::string str() const
Definition: Value.h:187
std::string str() const
bool isString() const
Definition: Value.h:144
StringValue(const std::string &v)
Definition: Value.h:141
virtual bool isUint64() const
Definition: Value.h:50
bool isInt64() const
Definition: Value.h:113
bool isInt64() const
Definition: Value.h:133
virtual bool isMap() const
Definition: Value.h:57
virtual framing::FieldTable asMap() const
Definition: Value.h:69
bool isBool() const
Definition: Value.h:155
virtual ObjectId asObjectId() const
Definition: Value.h:59
std::string str() const
virtual ~Value()
Definition: Value.h:43
std::string str() const
virtual int32_t asInt() const
Definition: Value.h:61
uint32_t asUint() const
Definition: Value.h:100
MapValue(const framing::FieldTable &v)
Definition: Value.h:196
std::string str() const
framing::FieldTable asMap() const
Definition: Value.h:200
A set of name-value pairs.
Definition: FieldTable.h:53
std::string str() const
bool isFloat() const
Definition: Value.h:165
std::string str() const
virtual bool isFloat() const
Definition: Value.h:54
std::string str() const
virtual bool isInt64() const
Definition: Value.h:51
float asFloat() const
Definition: Value.h:166
Uint64Value(uint64_t v)
Definition: Value.h:121
virtual bool isObjectId() const
Definition: Value.h:47
bool isUint64() const
Definition: Value.h:123
bool isUint64() const
Definition: Value.h:101

Qpid C++ API Reference
Generated on Wed Aug 27 2014 for Qpid C++ Client API by doxygen 1.8.6