10 #ifndef MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP 11 #define MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP 13 #if defined(MSGPACK_USE_BOOST) 31 #include <boost/variant.hpp> 32 #include <boost/operators.hpp> 43 template <
typename STR,
typename BIN,
typename EXT>
44 struct basic_variant :
52 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
54 #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 59 boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >,
60 boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >,
61 boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >
63 private boost::totally_ordered<basic_variant<STR, BIN, EXT> > {
64 typedef boost::variant<
71 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 73 #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 78 boost::recursive_wrapper<std::vector<basic_variant<STR, BIN, EXT> > >,
79 boost::recursive_wrapper<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >,
80 boost::recursive_wrapper<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >
84 basic_variant(T
const& t):base(t) {}
85 basic_variant(
char const* p):base(std::string(p)) {}
86 basic_variant(
char v) {
89 basic_variant(
signed char v) {
92 basic_variant(
unsigned char v):base(uint64_t(v)) {}
93 basic_variant(
signed int v) {
96 basic_variant(
unsigned int v):base(uint64_t(v)) {}
97 basic_variant(
signed long v) {
100 basic_variant(
unsigned long v):base(uint64_t(v)) {}
101 basic_variant(
signed long long v) {
104 basic_variant(
unsigned long long v):base(uint64_t(v)) {}
106 bool is_nil()
const {
107 return boost::get<msgpack::type::nil_t>(
this);
109 bool is_bool()
const {
110 return boost::get<bool>(
this);
112 bool is_int64_t()
const {
113 return boost::get<int64_t>(
this);
115 bool is_uint64_t()
const {
116 return boost::get<uint64_t>(
this);
118 bool is_double()
const {
119 return boost::get<double>(
this);
121 bool is_string()
const {
122 return boost::get<std::string>(
this);
124 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 125 bool is_boost_string_ref()
const {
126 return boost::get<boost::string_ref>(
this);
128 #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 129 bool is_vector_char()
const {
130 return boost::get<std::vector<char> >(
this);
132 bool is_vector_char() {
133 return boost::get<std::vector<char> >(
this);
135 bool is_raw_ref()
const {
136 return boost::get<raw_ref>(
this);
138 bool is_ext()
const {
139 return boost::get<ext>(
this);
141 bool is_ext_ref()
const {
142 return boost::get<ext_ref>(
this);
144 bool is_vector()
const {
145 return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(
this);
147 bool is_map()
const {
148 return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(
this);
150 bool is_multimap()
const {
151 return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(
this);
154 bool as_bool()
const {
155 return boost::get<bool>(*this);
157 int64_t as_int64_t()
const {
158 return boost::get<int64_t>(*this);
160 int64_t& as_int64_t() {
161 return boost::get<int64_t>(*this);
163 uint64_t as_uint64_t()
const {
164 return boost::get<uint64_t>(*this);
166 uint64_t& as_uint64_t() {
167 return boost::get<uint64_t>(*this);
169 double as_double()
const {
170 return boost::get<double>(*this);
172 double& as_double() {
173 return boost::get<double>(*this);
175 std::string
const& as_string()
const {
176 return boost::get<std::string>(*this);
178 std::string& as_string() {
179 return boost::get<std::string>(*this);
181 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 182 boost::string_ref
const& as_boost_string_ref()
const {
183 return boost::get<boost::string_ref>(*this);
185 boost::string_ref& as_boost_string_ref() {
186 return boost::get<boost::string_ref>(*this);
188 #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 189 std::vector<char>
const& as_vector_char()
const {
190 return boost::get<std::vector<char> >(*this);
192 std::vector<char>& as_vector_char() {
193 return boost::get<std::vector<char> >(*this);
195 raw_ref
const& as_raw_ref()
const {
196 return boost::get<raw_ref>(*this);
198 ext
const& as_ext()
const {
199 return boost::get<ext>(*this);
202 return boost::get<ext>(*this);
204 ext_ref
const& as_ext_ref()
const {
205 return boost::get<ext_ref>(*this);
207 std::vector<basic_variant<STR, BIN, EXT> >
const& as_vector()
const {
208 return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
210 std::vector<basic_variant<STR, BIN, EXT> >& as_vector() {
211 return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
213 std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >
const& as_map()
const {
214 return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
216 std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_map() {
217 return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
219 std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >
const& as_multimap()
const {
220 return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
222 std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_multimap() {
223 return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
226 template <
typename T>
229 static_cast<base&
>(*this) = int64_t(v);
232 static_cast<base&
>(*this) = uint64_t(v);
237 template <
typename STR,
typename BIN,
typename EXT>
238 inline bool operator<(basic_variant<STR, BIN, EXT>
const& lhs, basic_variant<STR, BIN, EXT>
const& rhs) {
240 static_cast<typename basic_variant<STR, BIN, EXT>::base const&
>(lhs) <
241 static_cast<typename basic_variant<STR, BIN, EXT>::base const&
>(rhs);
244 template <
typename STR,
typename BIN,
typename EXT>
245 inline bool operator==(basic_variant<STR, BIN, EXT>
const& lhs, basic_variant<STR, BIN, EXT>
const& rhs) {
247 static_cast<typename basic_variant<STR, BIN, EXT>::base const&
>(lhs) ==
248 static_cast<typename basic_variant<STR, BIN, EXT>::base const&
>(rhs);
251 typedef basic_variant<std::string, std::vector<char>, ext> variant;
252 typedef basic_variant<
253 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 255 #else // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 257 #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 258 raw_ref, ext_ref> variant_ref;
264 #if !defined (MSGPACK_USE_CPP03) 266 template <
typename STR,
typename BIN,
typename EXT>
267 struct as<type::basic_variant<STR, BIN, EXT> > {
268 type::basic_variant<STR, BIN, EXT> operator()(
msgpack::object const& o)
const {
275 return o.
as<uint64_t>();
277 return o.
as<int64_t>();
279 return o.
as<
double>();
287 return o.
as<std::vector<type::basic_variant<STR, BIN, EXT> > >();
289 return o.
as<std::multimap<type::basic_variant<STR, BIN, EXT>, type::basic_variant<STR, BIN, EXT> > >();
293 return type::basic_variant<STR, BIN, EXT>();
297 #endif // !defined (MSGPACK_USE_CPP03) 300 template <
typename STR,
typename BIN,
typename EXT>
301 struct convert<type::basic_variant<STR, BIN, EXT> > {
304 type::basic_variant<STR, BIN, EXT>& v)
const {
313 v = o.
as<uint64_t>();
331 v = o.
as<std::vector<type::basic_variant<STR, BIN, EXT> > >();
334 v = o.
as<std::multimap<type::basic_variant<STR, BIN, EXT>, type::basic_variant<STR, BIN, EXT> > >();
345 template <
typename Stream>
346 struct pack_imp : boost::static_visitor<void> {
347 template <
typename T>
348 void operator()(T
const& value)
const {
349 pack<T>()(o_, value);
351 pack_imp(packer<Stream>& o):o_(o) {}
357 template <
typename STR,
typename BIN,
typename EXT>
358 struct pack<type::basic_variant<STR, BIN, EXT> > {
359 template <
typename Stream>
361 boost::apply_visitor(detail::pack_imp<Stream>(o), v);
368 struct object_imp : boost::static_visitor<void> {
370 object<msgpack::type::nil_t>()(o_, v);
372 void operator()(
bool const& v)
const {
373 object<bool>()(o_, v);
375 void operator()(uint64_t
const& v)
const {
376 object<uint64_t>()(o_, v);
378 void operator()(int64_t
const& v)
const {
379 object<int64_t>()(o_, v);
381 void operator()(
double const& v)
const {
382 object<double>()(o_, v);
384 template <
typename T>
385 void operator()(T
const&)
const {
394 template <
typename STR,
typename BIN,
typename EXT>
395 struct object<type::basic_variant<STR, BIN, EXT> > {
396 void operator()(
msgpack::object& o,
const type::basic_variant<STR, BIN, EXT>& v)
const {
397 boost::apply_visitor(detail::object_imp(o), v);
403 struct object_with_zone_imp : boost::static_visitor<void> {
404 template <
typename T>
405 void operator()(T
const& v)
const {
406 object_with_zone<T>()(o_, v);
414 template <
typename STR,
typename BIN,
typename EXT>
415 struct object_with_zone<type::basic_variant<STR, BIN, EXT> > {
417 boost::apply_visitor(detail::object_with_zone_imp(o), v);
429 #endif // MSGPACK_USE_BOOST 430 #endif // MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP Definition: object_fwd_decl.hpp:37
Definition: object_fwd_decl.hpp:30
Definition: object_fwd_decl.hpp:38
Definition: adaptor_base.hpp:15
Definition: object_fwd_decl.hpp:33
void convert(T &v, msgpack::object const &o)
Definition: object.hpp:640
Definition: object.hpp:34
Definition: object_fwd_decl.hpp:29
Definition: object_fwd_decl.hpp:32
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition: object.hpp:567
Definition: object_fwd.hpp:222
Definition: object_fwd_decl.hpp:41
void pack(msgpack::packer< Stream > &o, const T &v)
Definition: object.hpp:647
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::type::object_type type
Definition: object_fwd.hpp:91
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
Definition: object_fwd_decl.hpp:39
Definition: object_fwd_decl.hpp:40
bool operator==(nil_t const &lhs, nil_t const &rhs)
Definition: nil.hpp:29
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:23
Definition: object_fwd_decl.hpp:31