1 #ifndef PROTON_VALUE_HPP
2 #define PROTON_VALUE_HPP
27 #include "./internal/type_traits.hpp"
31 #include <proton/type_compat.h>
45 internal::data& data();
48 friend class codec::encoder;
49 friend class codec::decoder;
57 class value :
public internal::value_base,
private internal::comparable<value> {
60 template<
class T,
class U=
void>
struct assignable :
61 public internal::enable_if<codec::is_encodable<T>::value, U> {};
62 template<
class U>
struct assignable<value, U> {};
66 PN_CPP_EXTERN
value();
70 PN_CPP_EXTERN
value(
const value&);
71 PN_CPP_EXTERN value& operator=(
const value&);
72 #if PN_CPP_HAS_RVALUE_REFERENCES
73 PN_CPP_EXTERN
value(value&&);
74 PN_CPP_EXTERN value& operator=(value&&);
79 template <
class T>
value(
const T& x,
typename assignable<T>::type* = 0) { *
this = x; }
82 template <
class T>
typename assignable<T, value&>::type
operator=(
const T& x) {
92 PN_CPP_EXTERN
bool empty()
const;
95 PN_CPP_EXTERN
void clear();
98 template<
class T> PN_CPP_DEPRECATED(
"Use 'proton::get'") void
get(T &t) const;
99 template<class T> PN_CPP_DEPRECATED("Use 'proton::
get'") T
get() const;
103 friend PN_CPP_EXTERN
void swap(value&, value&);
107 friend PN_CPP_EXTERN
bool operator==(const value& x, const value& y);
108 friend PN_CPP_EXTERN
bool operator<(const value& x, const value& y);
115 friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const value&);
120 void reset(pn_data_t* d = 0);
126 template<class T> T
get(const value& v) { T x;
get(v, x);
return x; }
133 template<
class T>
void get(
const value& v, T& x) {
codec::decoder d(v,
true); d >> x; }
136 template<
class T,
class U>
inline void get(
const U& u, T& x) {
const value v(u);
get(v, x); }
140 template<
class T> T
coerce(
const value& v) { T x;
coerce(v, x);
return x; }
147 template<
class T>
void coerce(
const value& v, T& x) {
150 if (type_id_is_scalar(v.
type())) {
152 x = internal::coerce<T>(s);
159 template<>
inline void get<null>(
const value& v, null&) {
164 PN_CPP_EXTERN std::string
to_string(
const value& x);
167 template<
class T>
void value::get(T &x)
const { x = proton::get<T>(*this); }
168 template<
class T> T
value::get()
const {
return proton::get<T>(*this); }
173 #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:126
The null type, contains no data.
Definition: type_id.hpp:38
void get< null >(const value &v, null &)
Special case for get<null>(), just checks that value contains NULL.
Definition: value.hpp:159
Unsettled API - A stream-like encoder from C++ values to AMQP bytes.
Definition: encoder.hpp:50
value()
Create a null value.
assignable< T, value & >::type operator=(const T &x)
Assign from any allowed type T.
Definition: value.hpp:82
friend void swap(value &, value &)
swap values
value(const T &x, typename assignable< T >::type *=0)
Copy from any allowed type T.
Definition: value.hpp:79
bool empty() const
True if the value is null.
std::string to_string(const scalar_base &x)
Return a readable string representation of x for display purposes.
type_id
An identifier for AMQP types.
Definition: type_id.hpp:37
T coerce(const value &v)
Coerce the contained value to type T.
Definition: value.hpp:140
Forward declarations for Proton types used to represent AMQP types.
Unsettled API - A stream-like decoder from AMQP bytes to C++ values.
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
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...
Unsettled API - A stream-like encoder from C++ values to AMQP bytes.
void clear()
Reset the value to null/empty.
A holder for an instance of any scalar AMQP type.
type_id type() const
Get the type ID for the current value.
Unsettled API - A stream-like decoder from AMQP bytes to C++ values.
Definition: decoder.hpp:56