Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello_message_pack
vector_bool.hpp
00001 // 00002 // MessagePack for C++ static resolution routine 00003 // 00004 // Copyright (C) 2015 KONDO Takatoshi 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // (See accompanying file LICENSE_1_0.txt or copy at 00008 // http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 #ifndef MSGPACK_TYPE_VECTOR_BOOL_HPP 00011 #define MSGPACK_TYPE_VECTOR_BOOL_HPP 00012 00013 #include "msgpack/versioning.hpp" 00014 #include "msgpack/object_fwd.hpp" 00015 #include <vector> 00016 00017 namespace msgpack { 00018 00019 /// @cond 00020 MSGPACK_API_VERSION_NAMESPACE(v1) { 00021 /// @endcond 00022 00023 namespace adaptor { 00024 00025 template <typename Alloc> 00026 struct convert<std::vector<bool, Alloc> > { 00027 msgpack::object const& operator()(msgpack::object const& o, std::vector<bool, Alloc>& v) const { 00028 if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 00029 if (o.via.array.size > 0) { 00030 v.resize(o.via.array.size); 00031 msgpack::object* p = o.via.array.ptr; 00032 for (typename std::vector<bool, Alloc>::iterator it = v.begin(), end = v.end(); 00033 it != end; 00034 ++it) { 00035 *it = p->as<bool>(); 00036 ++p; 00037 } 00038 } 00039 return o; 00040 } 00041 }; 00042 00043 template <typename Alloc> 00044 struct pack<std::vector<bool, Alloc> > { 00045 template <typename Stream> 00046 msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const std::vector<bool, Alloc>& v) const { 00047 uint32_t size = checked_get_container_size(v.size()); 00048 o.pack_array(size); 00049 for(typename std::vector<bool, Alloc>::const_iterator it(v.begin()), it_end(v.end()); 00050 it != it_end; ++it) { 00051 o.pack(static_cast<bool>(*it)); 00052 } 00053 return o; 00054 } 00055 }; 00056 00057 template <typename Alloc> 00058 struct object_with_zone<std::vector<bool, Alloc> > { 00059 void operator()(msgpack::object::with_zone& o, const std::vector<bool, Alloc>& v) const { 00060 o.type = msgpack::type::ARRAY; 00061 if(v.empty()) { 00062 o.via.array.ptr = nullptr; 00063 o.via.array.size = 0; 00064 } else { 00065 uint32_t size = checked_get_container_size(v.size()); 00066 msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size)); 00067 msgpack::object* const pend = p + size; 00068 o.via.array.ptr = p; 00069 o.via.array.size = size; 00070 typename std::vector<bool, Alloc>::const_iterator it(v.begin()); 00071 do { 00072 *p = msgpack::object(static_cast<bool>(*it), o.zone); 00073 ++p; 00074 ++it; 00075 } while(p < pend); 00076 } 00077 } 00078 }; 00079 00080 } // namespace adaptor 00081 00082 /// @cond 00083 } // MSGPACK_API_VERSION_NAMESPACE(v1) 00084 /// @endcond 00085 00086 } // namespace msgpack 00087 00088 #endif // MSGPACK_TYPE_VECTOR_BOOL_HPP
Generated on Tue Jul 12 2022 22:51:46 by
1.7.2