Qpid Proton C++  0.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
value.hpp
1 #ifndef VALUE_H
2 #define VALUE_H
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
23 #include "proton/data.hpp"
24 #include "proton/types.hpp"
25 
26 namespace proton {
27 
33 class value : public comparable<value> {
34  public:
36  PN_CPP_EXTERN value();
37 
39  PN_CPP_EXTERN value(const value&);
40 
41 #if PN_HAS_CPP11
42  PN_CPP_EXTERN value(value&&);
43 #endif
44 
46  PN_CPP_EXTERN value& operator=(const value&);
47 
49  template <class T> explicit value(const T& x) : data_(proton::data::create()) { encode() << x; }
50 
52  value(const scalar& x) { encode() << x; }
53 
55  template <class T> value& operator=(const T& x) { encode() << x; return *this; }
56 
58  PN_CPP_EXTERN void clear();
59 
61  PN_CPP_EXTERN bool empty() const;
62 
64  PN_CPP_EXTERN type_id type() const;
65 
71 
73  template<class T> void get(T &t) const { decode() >> t; }
74 
76  template<class T> void get_map(T& t) const { decode() >> to_map(t); }
77 
79  template<class T> void get_pairs(T& t) const { decode() >> to_pairs(t); }
80 
82  template<class T> void get_sequence(T& t) const { decode() >> to_sequence(t); }
83 
85 
87  template<class T> T get() const { T t; get(t); return t; }
88 
95  PN_CPP_EXTERN int64_t as_int() const;
96  PN_CPP_EXTERN uint64_t as_uint() const;
97  PN_CPP_EXTERN double as_double() const;
98  PN_CPP_EXTERN std::string as_string() const;
99 
103  PN_CPP_EXTERN encoder encode();
104  PN_CPP_EXTERN decoder decode() const;
105  PN_CPP_EXTERN class data& data() const;
106 
108  private:
109  mutable class data data_;
110 
112  friend PN_CPP_EXTERN void swap(value&, value&);
113  friend PN_CPP_EXTERN bool operator==(const value& x, const value& y);
114  friend PN_CPP_EXTERN bool operator<(const value& x, const value& y);
115  friend PN_CPP_EXTERN class encoder operator<<(class encoder e, const value& dv);
116  friend PN_CPP_EXTERN class decoder operator>>(class decoder d, value& dv);
117  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const value& dv);
118  friend class message;
120 };
121 
122 }
123 
124 #endif // VALUE_H
A holder for an instance of any scalar AMQP type.
Definition: scalar.hpp:35
An AMQP message.
Definition: message.hpp:48
value()
Create an empty value.
value(const scalar &x)
Allow implicit conversion from a proton::scalar.
Definition: value.hpp:52
void get_sequence(T &t) const
Get an AMQP array or list as type T that satisfies the sequence concept. */.
Definition: value.hpp:82
value & operator=(const T &x)
Create a value from C++ type T.
Definition: value.hpp:55
bool empty() const
True if the value contains no data.
Defines C++ types representing AMQP types.
std::string as_string() const
Allowed if type_id_is_string_like(type())
value(const T &x)
Explicit conversion from from C++ type T.
Definition: value.hpp:49
int64_t as_int() const
Allowed if type_id_is_integral(type())
value & operator=(const value &)
Copy a value.
A holder for an AMQP value.
Definition: value.hpp:33
double as_double() const
Allowed if type_id_is_floating_point(type())
void get_pairs(T &t) const
Get a map as a as any type T that is a sequence pair-like types with first and second.
Definition: value.hpp:79
void get_map(T &t) const
Get an AMQP map as any type T that satisfies the map concept.
Definition: value.hpp:76
void clear()
Remove any contained data.
type_id type() const
Get the type of the current value.
uint64_t as_uint() const
Allowed if type_id_is_integral(type())