Qpid Proton C++ API
0.33.0
|
|
Go to the documentation of this file. 1 #ifndef PROTON_SCALAR_BASE_HPP
2 #define PROTON_SCALAR_BASE_HPP
28 #include "./internal/comparable.hpp"
29 #include "./internal/export.hpp"
30 #include "./internal/type_traits.hpp"
37 #include <proton/type_compat.h>
56 template<
class T> T
get(
const scalar_base& s);
60 class scalar_base :
private internal::comparable<scalar_base> {
66 PN_CPP_EXTERN
bool empty()
const;
81 PN_CPP_EXTERN
void put_(
bool);
82 PN_CPP_EXTERN
void put_(uint8_t);
83 PN_CPP_EXTERN
void put_(int8_t);
84 PN_CPP_EXTERN
void put_(uint16_t);
85 PN_CPP_EXTERN
void put_(int16_t);
86 PN_CPP_EXTERN
void put_(uint32_t);
87 PN_CPP_EXTERN
void put_(int32_t);
88 PN_CPP_EXTERN
void put_(uint64_t);
89 PN_CPP_EXTERN
void put_(int64_t);
90 PN_CPP_EXTERN
void put_(
wchar_t);
91 PN_CPP_EXTERN
void put_(
float);
92 PN_CPP_EXTERN
void put_(
double);
94 PN_CPP_EXTERN
void put_(
const decimal32&);
95 PN_CPP_EXTERN
void put_(
const decimal64&);
97 PN_CPP_EXTERN
void put_(
const uuid&);
98 PN_CPP_EXTERN
void put_(
const std::string&);
99 PN_CPP_EXTERN
void put_(
const symbol&);
100 PN_CPP_EXTERN
void put_(
const binary&);
101 PN_CPP_EXTERN
void put_(
const char* s);
102 PN_CPP_EXTERN
void put_(
const null&);
103 #if PN_CPP_HAS_NULLPTR
104 PN_CPP_EXTERN
void put_(decltype(
nullptr));
107 template<
class T>
void put(
const T& x) { putter<T>::put(*
this, x); }
110 PN_CPP_EXTERN
void get_(
bool&)
const;
111 PN_CPP_EXTERN
void get_(uint8_t&)
const;
112 PN_CPP_EXTERN
void get_(int8_t&)
const;
113 PN_CPP_EXTERN
void get_(uint16_t&)
const;
114 PN_CPP_EXTERN
void get_(int16_t&)
const;
115 PN_CPP_EXTERN
void get_(uint32_t&)
const;
116 PN_CPP_EXTERN
void get_(int32_t&)
const;
117 PN_CPP_EXTERN
void get_(uint64_t&)
const;
118 PN_CPP_EXTERN
void get_(int64_t&)
const;
119 PN_CPP_EXTERN
void get_(
wchar_t&)
const;
120 PN_CPP_EXTERN
void get_(
float&)
const;
121 PN_CPP_EXTERN
void get_(
double&)
const;
122 PN_CPP_EXTERN
void get_(
timestamp&)
const;
123 PN_CPP_EXTERN
void get_(
decimal32&)
const;
124 PN_CPP_EXTERN
void get_(
decimal64&)
const;
126 PN_CPP_EXTERN
void get_(
uuid&)
const;
127 PN_CPP_EXTERN
void get_(std::string&)
const;
128 PN_CPP_EXTERN
void get_(
symbol&)
const;
129 PN_CPP_EXTERN
void get_(
binary&)
const;
130 PN_CPP_EXTERN
void get_(
null&)
const;
131 #if PN_CPP_HAS_NULLPTR
132 PN_CPP_EXTERN
void get_(decltype(
nullptr)&)
const;
137 template <
class T,
class Enable=
void>
struct putter {
138 static void put(
scalar_base& s,
const T& x) { s.put_(x); }
141 struct putter<T, typename internal::enable_if<internal::is_unknown_integer<T>::value>
::type> {
142 static void put(scalar_base& s,
const T& x) {
143 s.put_(
static_cast<typename internal::known_integer<T>::type
>(x));
146 template <
class T,
class Enable=
void>
148 static T
get(
const scalar_base& s) { T x; s.get_(x);
return x; }
151 struct getter<T, typename internal::enable_if<internal::is_unknown_integer<T>::value>
::type> {
152 static T
get(
const scalar_base& s) {
153 typename internal::known_integer<T>::type x; s.get_(x);
return x;
157 void ok(pn_type_t)
const;
158 void set(
const pn_atom_t&);
159 void set(
const binary& x, pn_type_t t);
165 friend class message;
166 friend class codec::encoder;
167 friend class codec::decoder;
168 template<
class T>
friend T internal::get(
const scalar_base& s);
174 template<
class T> T
get(
const scalar_base& s) {
175 return scalar_base::getter<T>::get(s);
178 template <
class R,
class F> R visit(
const scalar_base& s, F f) {
180 case BOOLEAN:
return f(internal::get<bool>(s));
181 case UBYTE:
return f(internal::get<uint8_t>(s));
182 case BYTE:
return f(internal::get<int8_t>(s));
183 case USHORT:
return f(internal::get<uint16_t>(s));
184 case SHORT:
return f(internal::get<int16_t>(s));
185 case UINT:
return f(internal::get<uint32_t>(s));
186 case INT:
return f(internal::get<int32_t>(s));
187 case CHAR:
return f(internal::get<wchar_t>(s));
189 case LONG:
return f(internal::get<int64_t>(s));
190 case TIMESTAMP:
return f(internal::get<timestamp>(s));
191 case FLOAT:
return f(internal::get<float>(s));
192 case DOUBLE:
return f(internal::get<double>(s));
193 case DECIMAL32:
return f(internal::get<decimal32>(s));
194 case DECIMAL64:
return f(internal::get<decimal64>(s));
195 case DECIMAL128:
return f(internal::get<decimal128>(s));
198 case STRING:
return f(internal::get<std::string>(s));
200 default:
throw conversion_error(
"invalid scalar type "+
type_name(s.type()));
204 PN_CPP_EXTERN conversion_error make_coercion_error(
const char* cpp_type,
type_id amqp_type);
206 template<
class T>
struct coerce_op {
208 typename enable_if<is_convertible<U, T>::value, T>::type operator()(
const U& x) {
209 return static_cast<T
>(x);
212 typename enable_if<!is_convertible<U, T>::value, T>::type operator()(
const U&) {
213 throw make_coercion_error(
typeid(T).name(), type_id_of<U>::value);
217 template <
class T> T
coerce(
const scalar_base& s) {
return visit<T>(s, coerce_op<T>()); }
225 #endif // PROTON_SCALAR_BASE_HPP
symbol get< symbol >(const annotation_key &x)
Get the symbol value or throw conversion_error.
Definition: annotation_key.hpp:77
A 32-bit decimal floating-point value.
Definition: decimal.hpp:46
@ TIMESTAMP
Signed 64-bit milliseconds since the epoch.
Definition: type_id.hpp:49
friend bool operator<(const scalar_base &x, const scalar_base &y)
Compare.
A string that represents the AMQP symbol type.
The base class for scalar types.
Definition: scalar_base.hpp:60
@ UBYTE
Unsigned 8-bit integer.
Definition: type_id.hpp:40
@ DECIMAL128
128-bit decimal floating point.
Definition: type_id.hpp:54
Type IDs for AMQP data types.
@ BOOLEAN
Boolean true or false.
Definition: type_id.hpp:39
A 64-bit decimal floating-point value.
Definition: decimal.hpp:49
@ INT
Signed 32-bit integer.
Definition: type_id.hpp:45
A 16-byte universally unique identifier.
binary get< binary >(const message_id &x)
Get the binary value or throw conversion_error.
Definition: message_id.hpp:85
@ UINT
Unsigned 32-bit integer.
Definition: type_id.hpp:44
@ ULONG
Unsigned 64-bit integer.
Definition: type_id.hpp:47
@ FLOAT
32-bit binary floating point.
Definition: type_id.hpp:50
type_id type() const
AMQP type of data stored in the scalar.
std::string to_string(const message &)
Human readable string representation.
@ UUID
16-byte UUID.
Definition: type_id.hpp:55
@ DECIMAL32
32-bit decimal floating point.
Definition: type_id.hpp:52
@ USHORT
Unsigned 16-bit integer.
Definition: type_id.hpp:42
@ BYTE
Signed 8-bit integer.
Definition: type_id.hpp:41
friend bool operator==(const scalar_base &x, const scalar_base &y)
Compare.
type_id
An identifier for AMQP types.
Definition: type_id.hpp:37
T coerce(const annotation_key &x)
Get the binary value or throw conversion_error.
Definition: annotation_key.hpp:83
A string that represents the AMQP symbol type.
Definition: symbol.hpp:35
@ LONG
Signed 64-bit integer.
Definition: type_id.hpp:48
T get(const scalar &s)
Get a contained value of type T.
Definition: scalar.hpp:60
friend std::ostream & operator<<(std::ostream &o, const scalar_base &x)
Print the contained value.
uint64_t get< uint64_t >(const annotation_key &x)
Get the uint64_t value or throw conversion_error.
Definition: annotation_key.hpp:72
@ BINARY
Variable-length sequence of bytes.
Definition: type_id.hpp:56
@ SHORT
Signed 16-bit integer.
Definition: type_id.hpp:43
bool empty() const
True if there is no value, i.e. type() == NULL_TYPE.
@ CHAR
32-bit unicode character.
Definition: type_id.hpp:46
uuid get< uuid >(const message_id &x)
Get the uuid value or throw conversion_error.
Definition: message_id.hpp:83
A 16-byte universally unique identifier.
Definition: uuid.hpp:37
@ DOUBLE
64-bit binary floating point.
Definition: type_id.hpp:51
The main Proton namespace.
Definition: annotation_key.hpp:33
A 64-bit timestamp in milliseconds since the Unix epoch.
std::string type_name(type_id)
Get the name of the AMQP type.
@ STRING
Variable-length utf8-encoded string.
Definition: type_id.hpp:57
A 128-bit decimal floating-point value.
Definition: decimal.hpp:52
@ SYMBOL
Variable-length encoded string.
Definition: type_id.hpp:58
@ DECIMAL64
64-bit decimal floating point.
Definition: type_id.hpp:53
Arbitrary binary data.
Definition: binary.hpp:40
A 64-bit timestamp in milliseconds since the Unix epoch.
Definition: timestamp.hpp:35
Forward declarations for Proton types used to represent AMQP types.