1 #ifndef PROTON_VALUE_HPP
2 #define PROTON_VALUE_HPP
25 #include "./codec/encoder.hpp"
26 #include "./codec/decoder.hpp"
27 #include "./internal/type_traits.hpp"
28 #include "./scalar.hpp"
41 PN_CPP_EXTERN
type_id type()
const;
44 PN_CPP_EXTERN
bool empty()
const;
47 internal::data& data();
50 friend class value_ref;
51 friend class codec::encoder;
52 friend class codec::decoder;
60 class value :
public internal::value_base,
private internal::comparable<value> {
63 template<
class T,
class U=
void>
struct assignable :
64 public internal::enable_if<codec::is_encodable<T>::value, U> {};
65 template<
class U>
struct assignable<value, U> {};
69 PN_CPP_EXTERN
value();
73 PN_CPP_EXTERN
value(
const value&);
74 PN_CPP_EXTERN value& operator=(
const value&);
75 #if PN_CPP_HAS_RVALUE_REFERENCES
76 PN_CPP_EXTERN
value(value&&);
77 PN_CPP_EXTERN value& operator=(value&&);
82 template <
class T>
value(
const T& x,
typename assignable<T>::type* = 0) { *
this = x; }
85 template <
class T>
typename assignable<T, value&>::type
operator=(
const T& x) {
92 PN_CPP_EXTERN
void clear();
95 template<
class T>
void get(T &t)
const;
96 template<
class T> T
get()
const;
97 PN_CPP_EXTERN int64_t as_int()
const;
98 PN_CPP_EXTERN uint64_t as_uint()
const;
99 PN_CPP_EXTERN
double as_double()
const;
100 PN_CPP_EXTERN std::string as_string()
const;
104 friend PN_CPP_EXTERN
void swap(value&, value&);
108 friend PN_CPP_EXTERN
bool operator==(
const value& x,
const value& y);
109 friend PN_CPP_EXTERN
bool operator<(
const value& x,
const value& y);
112 friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&,
const value&);
124 class value_ref :
public value {
126 value_ref(pn_data_t* = 0);
127 value_ref(
const internal::data&);
128 value_ref(
const value_base&);
131 void refer(pn_data_t*);
132 void refer(
const internal::data&);
133 void refer(
const value_base&);
139 template <
class T> value_ref& operator=(
const T& x) {
140 static_cast<value&
>(*this) = x;
150 template<
class T> T
get(
const value& v) { T x;
get(v, x);
return x; }
170 if (type_id_is_scalar(v.type())) {
173 x = internal::coerce<T>(s);
185 PN_CPP_EXTERN std::string
to_string(
const value& x);
188 template<
class T>
void value::get(T &x)
const { x = proton::get<T>(*this); }
189 template<
class T> T
value::get()
const {
return proton::get<T>(*this); }
190 inline int64_t value::as_int()
const {
return proton::coerce<int64_t>(*this); }
191 inline uint64_t value::as_uint()
const {
return proton::coerce<uint64_t>(*this); }
192 inline double value::as_double()
const {
return proton::coerce<double>(*this); }
193 inline std::string value::as_string()
const {
return proton::coerce<std::string>(*this); }
198 #endif // PROTON_VALUE_HPP
A holder for an instance of any scalar AMQP type.
Definition: scalar.hpp:35
T get(const value &v)
Get a contained value of type T.
Definition: value.hpp:150
The null type, contains no data.
Definition: type_id.hpp:39
void get< null >(const value &v, null &)
Special case for get<null>(), just checks that value contains NULL.
Definition: value.hpp:180
Experimental - Stream-like encoder from AMQP bytes to C++ values.
Definition: encoder.hpp:45
value()
Create a null value.
assignable< T, value & >::type operator=(const T &x)
Assign from any allowed type T.
Definition: value.hpp:85
friend void swap(value &, value &)
swap values
value(const T &x, typename assignable< T >::type *=0)
Construct from any allowed type T.
Definition: value.hpp:82
void coerce(const value &v, T &x)
Like coerce(const value&) but assigns the value to a reference instead of returning it...
Definition: value.hpp:168
std::string to_string(const internal::scalar_base &x)
Return a readable string representation of x for display purposes.
type_id
An identifier for AMQP types.
Definition: type_id.hpp:38
T coerce(const value &v)
Coerce the contained value to type T.
Definition: value.hpp:161
Forward declarations for all the C++ types used by Proton to represent AMQP types.
A holder for any AMQP value, simple or complex.
Definition: value.hpp:60
void assert_type_equal(type_id want, type_id got)
Throw a conversion_error if want != got with a message including the names of the types...
void clear()
Reset the value to null.
Experimental - Stream-like decoder from AMQP bytes to C++ values.
Definition: decoder.hpp:51