10 #ifndef MSGPACK_V1_OBJECT_HPP
11 #define MSGPACK_V1_OBJECT_HPP
57 msgpack::unique_ptr<msgpack::zone> z
59 msgpack::unique_ptr<msgpack::zone>&& z
62 m_obj(obj), m_zone(
msgpack::move(z)) { }
90 msgpack::unique_ptr<msgpack::zone>&
zone()
97 const msgpack::unique_ptr<msgpack::zone>&
zone()
const
100 #if defined(MSGPACK_USE_CPP03)
101 struct object_handle_ref {
108 m_zone(
msgpack::move(other.m_zone)) {
112 m_obj(ref.m_oh->m_obj),
113 m_zone(
msgpack::move(ref.m_oh->m_zone)) {
118 m_zone = msgpack::move(other.m_zone);
123 m_obj = ref.m_oh->m_obj;
124 m_zone = msgpack::move(ref.m_oh->m_zone);
128 operator object_handle_ref() {
129 return object_handle_ref(
this);
135 msgpack::unique_ptr<msgpack::zone> m_zone;
140 template <std::
size_t N>
160 : rest(r), is_map(
false), is_key(
false) {
165 : rest(r), is_map(
true), is_key(
true) {
172 return as.kv_ptr->key;
175 return as.kv_ptr->val;
183 template <
typename Visitor>
184 next_ret next(Visitor& v) {
187 if (!v.end_map())
return abort;
190 if (!v.end_array())
return abort;
197 if (!v.end_map_key())
return abort;
198 if (!v.start_map_value())
return abort;
202 if (!v.end_map_value())
return abort;
205 if (!v.end_map())
return abort;
208 if (!v.start_map_key())
return abort;
214 if (!v.end_array_item())
return abort;
217 if (!v.end_array())
return abort;
220 if (!v.start_array_item())
return abort;
237 template <
typename Visitor>
240 bool start_collection =
false;
241 switch(m_current->
type) {
243 if (!v.visit_nil())
return;
246 if (!v.visit_boolean(m_current->
via.
boolean))
return;
249 if (!v.visit_positive_integer(m_current->
via.
u64))
return;
252 if (!v.visit_negative_integer(m_current->
via.
i64))
return;
255 if (!v.visit_float32(
static_cast<float>(m_current->
via.
f64)))
return;
258 if (!v.visit_float64(m_current->
via.
f64))
return;
267 msgpack::detail::check_container_size<sizeof(std::size_t)>(m_current->
via.
ext.
size);
274 if (start_collection) {
275 if (!v.start_array_item())
return;
279 if (!v.start_map(m_current->
via.
map.
size))
return;
281 start_collection = m_current->
via.
map.
size != 0;
282 if (start_collection) {
283 if (!v.start_map_key())
return;
290 if (m_ctx.empty())
return;
291 if (!start_collection) {
293 next_ret r = m_ctx.back().next(v);
296 if (m_ctx.empty())
return;
298 else if (r == cont) {
307 m_current = &m_ctx.back().get();
312 std::vector<elem> m_ctx;
315 template <
typename Stream>
324 if (v) m_packer.pack_true();
325 else m_packer.pack_false();
329 m_packer.pack_uint64(v);
333 m_packer.pack_int64(v);
337 m_packer.pack_float(v);
341 m_packer.pack_double(v);
345 m_packer.pack_str(
size);
346 m_packer.pack_str_body(v,
size);
350 m_packer.pack_bin(
size);
351 m_packer.pack_bin_body(v,
size);
355 m_packer.pack_ext(
size - 1,
static_cast<int8_t
>(*v));
356 m_packer.pack_ext_body(v + 1,
size - 1);
360 m_packer.pack_array(num_elements);
373 m_packer.pack_map(num_kv_pairs);
404 if (v) m_os <<
"true";
405 else m_os <<
"false";
426 for (uint32_t i = 0; i <
size; ++i) {
454 unsigned int code =
static_cast<unsigned int>(c);
455 if (code < 0x20 || code == 0x7f) {
456 std::ios::fmtflags flags(m_os.flags());
457 m_os <<
"\\u" << std::hex << std::setw(4) << std::setfill(
'0') << (code & 0xff);
470 (m_os <<
'"').write(v,
static_cast<std::streamsize
>(
size)) <<
'"';
478 m_current_size.push_back(num_elements);
486 --m_current_size.back();
487 if (m_current_size.back() != 0) {
493 m_current_size.pop_back();
498 m_current_size.push_back(num_kv_pairs);
513 --m_current_size.back();
514 if (m_current_size.back() != 0) {
520 m_current_size.pop_back();
526 std::vector<uint32_t> m_current_size;
624 template <
typename T>
625 inline object::implicit_type::operator T() {
return obj.as<T>(); }
628 template <
typename Stream,
typename T>
638 template <
typename T,
typename Enabler>
646 template <
typename T,
typename Enabler>
647 template <
typename Stream>
654 template <
typename T,
typename Enabler>
674 template <
typename Stream>
685 object_with_zone_visitor vis(o);
689 struct object_with_zone_visitor {
691 :m_zone(owz.
zone), m_ptr(&owz) {
692 m_objs.push_back(&owz);
698 bool visit_boolean(
bool v) {
700 m_ptr->via.boolean = v;
703 bool visit_positive_integer(uint64_t v) {
708 bool visit_negative_integer(int64_t v) {
713 bool visit_float32(
float v) {
718 bool visit_float64(
double v) {
723 bool visit_str(
const char* v, uint32_t
size) {
725 m_ptr->via.str.size =
size;
727 m_ptr->via.str.ptr = ptr;
728 std::memcpy(ptr, v,
size);
731 bool visit_bin(
const char* v, uint32_t
size) {
733 m_ptr->via.bin.size =
size;
735 m_ptr->via.bin.ptr = ptr;
736 std::memcpy(ptr, v,
size);
739 bool visit_ext(
const char* v, uint32_t
size) {
744 m_ptr->via.ext.size =
size - 1;
747 m_ptr->via.ext.ptr = ptr;
748 std::memcpy(ptr, v,
size);
751 bool start_array(uint32_t num_elements) {
754 m_zone.allocate_align(
757 m_objs.push_back(elem(m_ptr->via.array.ptr));
760 bool start_array_item() {
761 m_ptr = m_objs.back().get_item();
764 bool end_array_item() {
765 ++m_objs.back().
as.obj;
772 bool start_map(uint32_t num_kv_pairs) {
776 m_ptr->via.map.size = num_kv_pairs;
777 m_objs.push_back(elem(m_ptr->via.map.ptr));
780 bool start_map_key() {
781 m_ptr = m_objs.back().get_key();
787 bool start_map_value() {
788 m_ptr = m_objs.back().get_val();
791 bool end_map_value() {
792 ++m_objs.back().as.kv;
824 std::vector<elem> m_objs;
837 o << static_cast<msgpack::object const&>(v);
846 template <
typename Type>
854 template <
typename Packer>
857 msgpack::operator<<(o, static_cast<const msgpack_type&>(*
this));
868 template <
typename Stream>
869 template <
typename T>
878 :m_ptr(&obj), m_result(result) {}
958 m_ptr = m_objs.back().get_item();
962 ++m_objs.back().as.obj;
975 m_objs.push_back(elem(m_ptr->
via.
map.
ptr));
979 m_ptr = m_objs.back().get_key();
986 m_ptr = m_objs.back().get_val();
990 ++m_objs.back().as.kv;
1022 std::vector<elem> m_objs;
1029 if(x.
type != y.
type) {
return false; }
1036 template <
typename T>
1045 {
return !(x == y); }
1047 template <
typename T>
1051 template <
typename T>
1053 {
return !(x == y); }
1055 template <
typename T>
1065 template <
typename T>
1067 typename msgpack::enable_if<
1068 !msgpack::is_array<T>::value && !msgpack::is_pointer<T>::value,
1077 template <
typename T, std::
size_t N>
1084 #if !defined(MSGPACK_DISABLE_LEGACY_CONVERT)
1085 template <
typename T>
1087 typename msgpack::enable_if<
1088 msgpack::is_pointer<T>::value,
1098 template <
typename T>
1108 #if defined(MSGPACK_USE_CPP03)
1110 template <
typename T>
1120 template <
typename T>
1121 inline typename std::enable_if<msgpack::has_as<T>::value, T>::type
object::as()
const {
1125 template <
typename T>
1126 inline typename std::enable_if<!msgpack::has_as<T>::value, T>::type
object::as()
const {
1139 template <
typename T>
1145 template <
typename T>
1152 template <
typename T>
1161 template <
typename T>
1172 template <
typename T>
1179 template <
typename Stream,
typename T>
1186 template <
typename Stream,
typename T>
1192 template <
typename Stream>
1195 object_pack_visitor<Stream> vis(o);
1200 template <
typename Stream>
1203 return o << static_cast<msgpack::object>(v);
Definition: object.hpp:847
define()
Definition: object.hpp:851
define(const msgpack_type &v)
Definition: object.hpp:852
void msgpack_pack(Packer &o) const
Definition: object.hpp:855
void msgpack_unpack(object const &o)
Definition: object.hpp:860
define< Type > define_type
Definition: object.hpp:850
Type msgpack_type
Definition: object.hpp:849
The class holds object and zone.
Definition: object.hpp:44
object_handle(msgpack::object const &obj, msgpack::unique_ptr< msgpack::zone > &&z)
Constructor that creates an object_handle holding object obj and zone z.
Definition: object.hpp:54
const msgpack::object & get() const
Get object reference.
Definition: object.hpp:71
const msgpack::unique_ptr< msgpack::zone > & zone() const
Get unique_ptr const reference of zone.
Definition: object.hpp:97
const msgpack::object * operator->() const
Definition: object.hpp:83
const msgpack::object & operator*() const
Definition: object.hpp:77
msgpack::unique_ptr< msgpack::zone > & zone()
Get unique_ptr reference of zone.
Definition: object.hpp:90
void set(msgpack::object const &obj)
Definition: object.hpp:64
object_handle()
Constructor that creates nil object and null zone.
Definition: object.hpp:47
Definition: object.hpp:151
void parse(Visitor &v)
Definition: object.hpp:238
object_parser(msgpack::object const &obj)
Definition: object.hpp:236
The class template that supports continuous packing.
Definition: pack.hpp:33
packer< Stream > & pack(const T &v)
Packing function template.
Definition: object_fwd.hpp:231
Definition: cpp03_zone.hpp:31
#define MSGPACK_USE_CPP03
Definition: cpp_version.hpp:9
std::size_t add_ext_type_size< 4 >(std::size_t size)
Definition: object.hpp:146
std::size_t add_ext_type_size(std::size_t size)
Definition: object.hpp:141
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
@ EXT
Definition: object_fwd_decl.hpp:42
@ FLOAT64
Definition: object_fwd_decl.hpp:33
@ BOOLEAN
Definition: object_fwd_decl.hpp:29
@ MAP
Definition: object_fwd_decl.hpp:41
@ NIL
Definition: object_fwd_decl.hpp:28
@ STR
Definition: object_fwd_decl.hpp:38
@ ARRAY
Definition: object_fwd_decl.hpp:40
@ BIN
Definition: object_fwd_decl.hpp:39
@ POSITIVE_INTEGER
Definition: object_fwd_decl.hpp:30
@ NEGATIVE_INTEGER
Definition: object_fwd_decl.hpp:31
@ FLOAT32
Definition: object_fwd_decl.hpp:32
Definition: adaptor_base.hpp:15
void pack(msgpack::packer< Stream > &o, const T &v)
Definition: object.hpp:1180
bool operator==(const msgpack::object &x, const msgpack::object &y)
Definition: object.hpp:1027
std::size_t aligned_size(std::size_t size, std::size_t align)
Definition: cpp03_zone.hpp:354
msgpack::enable_if< !is_array< T >::value, msgpack::packer< Stream > & >::type operator<<(msgpack::packer< Stream > &o, T const &v)
Definition: adaptor_base.hpp:72
void pack_copy(msgpack::packer< Stream > &o, T v)
Definition: object.hpp:1187
object_handle clone(msgpack::object const &obj)
clone object
Definition: object.hpp:617
std::size_t aligned_zone_size(msgpack::object const &obj)
Definition: object.hpp:602
void convert(T &v, msgpack::object const &o)
Definition: object.hpp:1173
bool operator!=(const msgpack::object &x, const msgpack::object &y)
Definition: object.hpp:1044
msgpack::enable_if< !is_array< T >::value, msgpack::object const & >::type operator>>(msgpack::object const &o, T &v)
Definition: adaptor_base.hpp:57
Definition: object_fwd_decl.hpp:61
msgpack::object const & operator()(msgpack::object const &o, msgpack::object &v) const
Definition: object.hpp:666
Definition: adaptor_base.hpp:27
msgpack::object const & operator()(msgpack::object const &o, T &v) const
Definition: object.hpp:641
void operator()(msgpack::object::with_zone &o, msgpack::object const &v) const
Definition: object.hpp:684
void operator()(msgpack::object::with_zone &o, msgpack::object::with_zone const &v) const
Definition: object.hpp:834
Definition: adaptor_base.hpp:43
void operator()(msgpack::object::with_zone &o, T const &v) const
Definition: object.hpp:657
Definition: adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, msgpack::object const &v) const
Definition: object.hpp:675
Definition: adaptor_base.hpp:32
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, T const &v) const
Definition: object.hpp:650
Definition: object.hpp:529
bool visit_nil()
Definition: object.hpp:532
bool start_map(uint32_t num_kv_pairs)
Definition: object.hpp:577
bool end_map()
Definition: object.hpp:595
bool visit_ext(const char *, uint32_t size)
Definition: object.hpp:558
bool start_map_key()
Definition: object.hpp:583
bool start_map_value()
Definition: object.hpp:589
bool visit_bin(const char *, uint32_t size)
Definition: object.hpp:554
bool visit_float32(float)
Definition: object.hpp:544
bool end_array()
Definition: object.hpp:574
aligned_zone_size_visitor(std::size_t &s)
Definition: object.hpp:530
bool start_array(uint32_t num_elements)
Definition: object.hpp:562
bool visit_boolean(bool)
Definition: object.hpp:535
bool start_array_item()
Definition: object.hpp:568
bool visit_negative_integer(int64_t)
Definition: object.hpp:541
bool visit_str(const char *, uint32_t size)
Definition: object.hpp:550
bool end_array_item()
Definition: object.hpp:571
bool end_map_key()
Definition: object.hpp:586
bool end_map_value()
Definition: object.hpp:592
bool visit_float64(double)
Definition: object.hpp:547
bool visit_positive_integer(uint64_t)
Definition: object.hpp:538
Definition: object.hpp:629
static msgpack::packer< Stream > & pack(msgpack::packer< Stream > &o, const T &v)
Definition: object.hpp:630
Definition: object_fwd.hpp:233
Definition: object.hpp:35
with_zone(msgpack::zone &z)
Definition: object.hpp:36
msgpack::zone & zone
Definition: object.hpp:37
uint32_t size
Definition: object_fwd.hpp:23
msgpack::object * ptr
Definition: object_fwd.hpp:24
uint32_t size
Definition: object_fwd.hpp:38
const char * ptr
Definition: object_fwd.hpp:39
Definition: object.hpp:876
bool start_map_key()
Definition: object.hpp:978
bool visit_ext(const char *v, uint32_t size)
Definition: object.hpp:939
bool end_array_item()
Definition: object.hpp:961
bool visit_str(const char *v, uint32_t size)
Definition: object.hpp:921
bool visit_boolean(bool v)
Definition: object.hpp:886
bool visit_bin(const char *v, uint32_t size)
Definition: object.hpp:930
bool start_map_value()
Definition: object.hpp:985
bool start_array_item()
Definition: object.hpp:957
bool visit_nil()
Definition: object.hpp:879
bool visit_negative_integer(int64_t v)
Definition: object.hpp:900
bool visit_positive_integer(uint64_t v)
Definition: object.hpp:893
bool end_map_value()
Definition: object.hpp:989
bool visit_float64(double v)
Definition: object.hpp:914
bool start_map(uint32_t num_kv_pairs)
Definition: object.hpp:969
bool start_array(uint32_t num_elements)
Definition: object.hpp:948
bool visit_float32(float v)
Definition: object.hpp:907
object_equal_visitor(msgpack::object const &obj, bool &result)
Definition: object.hpp:877
bool end_map_key()
Definition: object.hpp:982
bool end_array()
Definition: object.hpp:965
bool end_map()
Definition: object.hpp:993
const char * ptr
Definition: object_fwd.hpp:46
uint32_t size
Definition: object_fwd.hpp:45
Definition: object.hpp:30
msgpack::object val
Definition: object.hpp:32
msgpack::object key
Definition: object.hpp:31
uint32_t size
Definition: object_fwd.hpp:28
msgpack::object_kv * ptr
Definition: object_fwd.hpp:29
Definition: object.hpp:316
bool start_map_value()
Definition: object.hpp:382
object_pack_visitor(msgpack::packer< Stream > &pk)
Definition: object.hpp:317
bool visit_float32(float v)
Definition: object.hpp:336
bool start_array_item()
Definition: object.hpp:363
bool visit_float64(double v)
Definition: object.hpp:340
bool end_map_key()
Definition: object.hpp:379
bool end_map()
Definition: object.hpp:388
bool end_map_value()
Definition: object.hpp:385
bool visit_boolean(bool v)
Definition: object.hpp:323
bool end_array()
Definition: object.hpp:369
bool visit_negative_integer(int64_t v)
Definition: object.hpp:332
bool start_map(uint32_t num_kv_pairs)
Definition: object.hpp:372
bool start_map_key()
Definition: object.hpp:376
bool end_array_item()
Definition: object.hpp:366
bool visit_bin(const char *v, uint32_t size)
Definition: object.hpp:349
bool start_array(uint32_t num_elements)
Definition: object.hpp:359
bool visit_positive_integer(uint64_t v)
Definition: object.hpp:328
bool visit_ext(const char *v, uint32_t size)
Definition: object.hpp:354
bool visit_nil()
Definition: object.hpp:319
bool visit_str(const char *v, uint32_t size)
Definition: object.hpp:344
const char * ptr
Definition: object_fwd.hpp:34
uint32_t size
Definition: object_fwd.hpp:33
Definition: object.hpp:396
bool end_map_value()
Definition: object.hpp:512
bool start_array(uint32_t num_elements)
Definition: object.hpp:477
bool start_map_value()
Definition: object.hpp:509
bool visit_str(const char *v, uint32_t size)
Definition: object.hpp:424
bool end_array()
Definition: object.hpp:492
bool start_map(uint32_t num_kv_pairs)
Definition: object.hpp:497
bool visit_boolean(bool v)
Definition: object.hpp:403
bool visit_ext(const char *, uint32_t)
Definition: object.hpp:473
bool visit_negative_integer(int64_t v)
Definition: object.hpp:412
bool visit_float32(float v)
Definition: object.hpp:416
object_stringize_visitor(std::ostream &os)
Definition: object.hpp:397
bool end_array_item()
Definition: object.hpp:485
bool start_map_key()
Definition: object.hpp:502
bool end_map()
Definition: object.hpp:519
bool visit_bin(const char *v, uint32_t size)
Definition: object.hpp:469
bool visit_float64(double v)
Definition: object.hpp:420
bool end_map_key()
Definition: object.hpp:505
bool visit_positive_integer(uint64_t v)
Definition: object.hpp:408
bool start_array_item()
Definition: object.hpp:482
bool visit_nil()
Definition: object.hpp:399
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
object()
Default constructor. The object is set to nil.
Definition: object.hpp:1134
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition: object.hpp:1121
implicit_type convert() const
Definition: object.hpp:1060
union_type via
Definition: object_fwd.hpp:93
msgpack::enable_if< !msgpack::is_array< T >::value &&!msgpack::is_pointer< T >::value, T & >::type convert(T &v) const
Convert the object.
Definition: object.hpp:1071
bool convert_if_not_nil(T &v) const
Convert the object if not nil.
Definition: object.hpp:1099
msgpack::type::object_type type
Definition: object_fwd.hpp:92
bool is_nil() const
Cheking nil.
Definition: object_fwd.hpp:99
object & operator=(const T &v)
Definition: object.hpp:1146
bool boolean
Definition: object_fwd.hpp:77
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::object_ext ext
Definition: object_fwd.hpp:89
msgpack::object_str str
Definition: object_fwd.hpp:87
uint64_t u64
Definition: object_fwd.hpp:78
int64_t i64
Definition: object_fwd.hpp:79
msgpack::object_bin bin
Definition: object_fwd.hpp:88
double f64
Definition: object_fwd.hpp:84
msgpack::object_map map
Definition: object_fwd.hpp:86
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66