mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 23:42:40 +02:00
Added all template parameters support for containers.
e.g.) allocator. Added tests. Replaced variadic template parameters with individual template parameters on C++11 unordered containers.
This commit is contained in:
parent
0f0598a6b9
commit
298c97ec08
@ -33,11 +33,11 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct as<std::forward_list<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
struct as<std::forward_list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||||
std::forward_list<T> operator()(msgpack::object const& o) const {
|
std::forward_list<T, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
std::forward_list<T> v;
|
std::forward_list<T, Alloc> v;
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pend = o.via.array.ptr;
|
msgpack::object* const pend = o.via.array.ptr;
|
||||||
while (p != pend) {
|
while (p != pend) {
|
||||||
@ -48,9 +48,9 @@ struct as<std::forward_list<T>, typename std::enable_if<msgpack::has_as<T>::valu
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct convert<std::forward_list<T>> {
|
struct convert<std::forward_list<T, Alloc>> {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::forward_list<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::forward_list<T, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
v.resize(o.via.array.size);
|
v.resize(o.via.array.size);
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
@ -62,10 +62,10 @@ struct convert<std::forward_list<T>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct pack<std::forward_list<T>> {
|
struct pack<std::forward_list<T, Alloc>> {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::forward_list<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::forward_list<T, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(auto const& e : v) o.pack(e);
|
for(auto const& e : v) o.pack(e);
|
||||||
@ -73,9 +73,9 @@ struct pack<std::forward_list<T>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct object_with_zone<std::forward_list<T>> {
|
struct object_with_zone<std::forward_list<T, Alloc>> {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::forward_list<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::forward_list<T, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
|
@ -32,15 +32,15 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct as<
|
struct as<
|
||||||
std::unordered_map<K, V, OtherTypes...>,
|
std::unordered_map<K, V, Hash, Compare, Alloc>,
|
||||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||||
std::unordered_map<K, V, OtherTypes...> operator()(msgpack::object const& o) const {
|
std::unordered_map<K, V, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::unordered_map<K, V, OtherTypes...> v;
|
std::unordered_map<K, V, Hash, Compare, Alloc> v;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||||
}
|
}
|
||||||
@ -48,13 +48,13 @@ struct as<
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<std::unordered_map<K, V, OtherTypes...>> {
|
struct convert<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_map<K, V, OtherTypes...>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::unordered_map<K, V, OtherTypes...> tmp;
|
std::unordered_map<K, V, Hash, Compare, Alloc> tmp;
|
||||||
for(; p != pend; ++p) {
|
for(; p != pend; ++p) {
|
||||||
K key;
|
K key;
|
||||||
p->key.convert(key);
|
p->key.convert(key);
|
||||||
@ -65,13 +65,13 @@ struct convert<std::unordered_map<K, V, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<std::unordered_map<K, V, OtherTypes...>> {
|
struct pack<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_map<K, V, OtherTypes...>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for(typename std::unordered_map<K, V, OtherTypes...>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::unordered_map<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -80,9 +80,9 @@ struct pack<std::unordered_map<K, V, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::unordered_map<K, V, OtherTypes...>> {
|
struct object_with_zone<std::unordered_map<K, V, Hash, Compare, Alloc>> {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::unordered_map<K, V, OtherTypes...>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::unordered_map<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -93,7 +93,7 @@ struct object_with_zone<std::unordered_map<K, V, OtherTypes...>> {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename std::unordered_map<K, V, OtherTypes...>::const_iterator it(v.begin());
|
typename std::unordered_map<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
@ -105,15 +105,15 @@ struct object_with_zone<std::unordered_map<K, V, OtherTypes...>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct as<
|
struct as<
|
||||||
std::unordered_multimap<K, V, OtherTypes...>,
|
std::unordered_multimap<K, V, Hash, Compare, Alloc>,
|
||||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||||
std::unordered_multimap<K, V, OtherTypes...> operator()(msgpack::object const& o) const {
|
std::unordered_multimap<K, V, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::unordered_multimap<K, V, OtherTypes...> v;
|
std::unordered_multimap<K, V, Hash, Compare, Alloc> v;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||||
}
|
}
|
||||||
@ -121,13 +121,13 @@ struct as<
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<std::unordered_multimap<K, V, OtherTypes...>> {
|
struct convert<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap<K, V, OtherTypes...>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::unordered_multimap<K, V, OtherTypes...> tmp;
|
std::unordered_multimap<K, V, Hash, Compare, Alloc> tmp;
|
||||||
for(; p != pend; ++p) {
|
for(; p != pend; ++p) {
|
||||||
std::pair<K, V> value;
|
std::pair<K, V> value;
|
||||||
p->key.convert(value.first);
|
p->key.convert(value.first);
|
||||||
@ -139,13 +139,13 @@ struct convert<std::unordered_multimap<K, V, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<std::unordered_multimap<K, V, OtherTypes...>> {
|
struct pack<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multimap<K, V, OtherTypes...>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for(typename std::unordered_multimap<K, V, OtherTypes...>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -154,9 +154,9 @@ struct pack<std::unordered_multimap<K, V, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename... OtherTypes>
|
template <typename K, typename V, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::unordered_multimap<K, V, OtherTypes...>> {
|
struct object_with_zone<std::unordered_multimap<K, V, Hash, Compare, Alloc>> {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K, V, OtherTypes...>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K, V, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -167,7 +167,7 @@ struct object_with_zone<std::unordered_multimap<K, V, OtherTypes...>> {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename std::unordered_multimap<K, V, OtherTypes...>::const_iterator it(v.begin());
|
typename std::unordered_multimap<K, V, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
|
@ -32,13 +32,13 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct as<std::unordered_set<Key, OtherTypes...>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
struct as<std::unordered_set<Key, Hash, Compare, Alloc>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
||||||
std::unordered_set<Key, OtherTypes...> operator()(msgpack::object const& o) const {
|
std::unordered_set<Key, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::unordered_set<Key, OtherTypes...> v;
|
std::unordered_set<Key, Hash, Compare, Alloc> v;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
v.insert(p->as<Key>());
|
v.insert(p->as<Key>());
|
||||||
@ -47,13 +47,13 @@ struct as<std::unordered_set<Key, OtherTypes...>, typename std::enable_if<msgpac
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<std::unordered_set<Key, OtherTypes...>> {
|
struct convert<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_set<Key, OtherTypes...>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::unordered_set<Key, OtherTypes...> tmp;
|
std::unordered_set<Key, Hash, Compare, Alloc> tmp;
|
||||||
while(p > pbegin) {
|
while(p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<Key>());
|
tmp.insert(p->as<Key>());
|
||||||
@ -63,13 +63,13 @@ struct convert<std::unordered_set<Key, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<std::unordered_set<Key, OtherTypes...>> {
|
struct pack<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_set<Key, OtherTypes...>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(typename std::unordered_set<Key, OtherTypes...>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::unordered_set<Key, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -77,9 +77,9 @@ struct pack<std::unordered_set<Key, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::unordered_set<Key, OtherTypes...>> {
|
struct object_with_zone<std::unordered_set<Key, Hash, Compare, Alloc>> {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::unordered_set<Key, OtherTypes...>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::unordered_set<Key, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -90,7 +90,7 @@ struct object_with_zone<std::unordered_set<Key, OtherTypes...>> {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::unordered_set<Key, OtherTypes...>::const_iterator it(v.begin());
|
typename std::unordered_set<Key, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
@ -101,13 +101,13 @@ struct object_with_zone<std::unordered_set<Key, OtherTypes...>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct as<std::unordered_multiset<Key, OtherTypes...>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
struct as<std::unordered_multiset<Key, Hash, Compare, Alloc>, typename std::enable_if<msgpack::has_as<Key>::value>::type> {
|
||||||
std::unordered_multiset<Key, OtherTypes...> operator()(msgpack::object const& o) const {
|
std::unordered_multiset<Key, Hash, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::unordered_multiset<Key, OtherTypes...> v;
|
std::unordered_multiset<Key, Hash, Compare, Alloc> v;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
v.insert(p->as<Key>());
|
v.insert(p->as<Key>());
|
||||||
@ -116,13 +116,13 @@ struct as<std::unordered_multiset<Key, OtherTypes...>, typename std::enable_if<m
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<std::unordered_multiset<Key, OtherTypes...>> {
|
struct convert<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset<Key, OtherTypes...>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::unordered_multiset<Key, OtherTypes...> tmp;
|
std::unordered_multiset<Key, Hash, Compare, Alloc> tmp;
|
||||||
while(p > pbegin) {
|
while(p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<Key>());
|
tmp.insert(p->as<Key>());
|
||||||
@ -132,13 +132,13 @@ struct convert<std::unordered_multiset<Key, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<std::unordered_multiset<Key, OtherTypes...>> {
|
struct pack<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multiset<Key, OtherTypes...>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(typename std::unordered_multiset<Key, OtherTypes...>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::unordered_multiset<Key, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -146,9 +146,9 @@ struct pack<std::unordered_multiset<Key, OtherTypes...>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename... OtherTypes>
|
template <typename Key, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::unordered_multiset<Key, OtherTypes...>> {
|
struct object_with_zone<std::unordered_multiset<Key, Hash, Compare, Alloc>> {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multiset<Key, OtherTypes...>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::unordered_multiset<Key, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -159,7 +159,7 @@ struct object_with_zone<std::unordered_multiset<Key, OtherTypes...>> {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::unordered_multiset<Key, OtherTypes...>::const_iterator it(v.begin());
|
typename std::unordered_multiset<Key, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -32,14 +32,14 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct convert<std::deque<T> > {
|
struct convert<std::deque<T, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::deque<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::deque<T, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
v.resize(o.via.array.size);
|
v.resize(o.via.array.size);
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||||
typename std::deque<T>::iterator it = v.begin();
|
typename std::deque<T, Alloc>::iterator it = v.begin();
|
||||||
for(; p < pend; ++p, ++it) {
|
for(; p < pend; ++p, ++it) {
|
||||||
p->convert(*it);
|
p->convert(*it);
|
||||||
}
|
}
|
||||||
@ -47,13 +47,13 @@ struct convert<std::deque<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct pack<std::deque<T> > {
|
struct pack<std::deque<T, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::deque<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::deque<T, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::deque<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -61,9 +61,9 @@ struct pack<std::deque<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct object_with_zone<std::deque<T> > {
|
struct object_with_zone<std::deque<T, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::deque<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::deque<T, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -74,7 +74,7 @@ struct object_with_zone<std::deque<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::deque<T>::const_iterator it(v.begin());
|
typename std::deque<T, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -34,11 +34,11 @@ namespace adaptor {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct as<std::list<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
struct as<std::list<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||||
std::list<T> operator()(msgpack::object const& o) const {
|
std::list<T, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
std::list<T> v;
|
std::list<T, Alloc> v;
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||||
for (; p < pend; ++p) {
|
for (; p < pend; ++p) {
|
||||||
@ -50,14 +50,14 @@ struct as<std::list<T>, typename std::enable_if<msgpack::has_as<T>::value>::type
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct convert<std::list<T> > {
|
struct convert<std::list<T, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::list<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::list<T, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
v.resize(o.via.array.size);
|
v.resize(o.via.array.size);
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||||
typename std::list<T>::iterator it = v.begin();
|
typename std::list<T, Alloc>::iterator it = v.begin();
|
||||||
for (; p < pend; ++p, ++it) {
|
for (; p < pend; ++p, ++it) {
|
||||||
p->convert(*it);
|
p->convert(*it);
|
||||||
}
|
}
|
||||||
@ -65,13 +65,13 @@ struct convert<std::list<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct pack<std::list<T> > {
|
struct pack<std::list<T, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::list<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::list<T, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for (typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::list<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -79,9 +79,9 @@ struct pack<std::list<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct object_with_zone<std::list<T> > {
|
struct object_with_zone<std::list<T, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::list<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::list<T, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -93,7 +93,7 @@ struct object_with_zone<std::list<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::list<T>::const_iterator it(v.begin());
|
typename std::list<T, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -34,18 +34,18 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare = std::less<K>, typename Alloc = std::allocator<std::pair<K, V> > >
|
||||||
class assoc_vector : public std::vector< std::pair<K, V> > {
|
class assoc_vector : public std::vector< std::pair<K, V>, Alloc > {
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
using std::vector<std::pair<K, V>>::vector;
|
using std::vector<std::pair<K, V>, Alloc>::vector;
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct pair_first_less {
|
struct pair_first_less {
|
||||||
bool operator() (const std::pair<K, V>& x, const std::pair<K, V>& y) const
|
bool operator() (const std::pair<K, V>& x, const std::pair<K, V>& y) const
|
||||||
{ return x.first < y.first; }
|
{ return Compare()(x.first, y.first); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,29 +55,29 @@ namespace adaptor {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct as<
|
struct as<
|
||||||
type::assoc_vector<K, V>,
|
type::assoc_vector<K, V, Compare, Alloc>,
|
||||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||||
type::assoc_vector<K, V> operator()(msgpack::object const& o) const {
|
type::assoc_vector<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
type::assoc_vector<K, V> v;
|
type::assoc_vector<K, V, Compare, Alloc> v;
|
||||||
v.reserve(o.via.map.size);
|
v.reserve(o.via.map.size);
|
||||||
msgpack::object_kv* p = o.via.map.ptr;
|
msgpack::object_kv* p = o.via.map.ptr;
|
||||||
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||||
for (; p < pend; ++p) {
|
for (; p < pend; ++p) {
|
||||||
v.emplace_back(p->key.as<K>(), p->val.as<V>());
|
v.emplace_back(p->key.as<K>(), p->val.as<V>());
|
||||||
}
|
}
|
||||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K,V>());
|
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct convert<type::assoc_vector<K, V> > {
|
struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K,V>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
v.resize(o.via.map.size);
|
v.resize(o.via.map.size);
|
||||||
msgpack::object_kv* p = o.via.map.ptr;
|
msgpack::object_kv* p = o.via.map.ptr;
|
||||||
@ -87,18 +87,18 @@ struct convert<type::assoc_vector<K, V> > {
|
|||||||
p->key.convert(it->first);
|
p->key.convert(it->first);
|
||||||
p->val.convert(it->second);
|
p->val.convert(it->second);
|
||||||
}
|
}
|
||||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K,V>());
|
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct pack<type::assoc_vector<K, V> > {
|
struct pack<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::assoc_vector<K,V>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for (typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename type::assoc_vector<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -107,9 +107,9 @@ struct pack<type::assoc_vector<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<type::assoc_vector<K, V> > {
|
struct object_with_zone<type::assoc_vector<K, V, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const type::assoc_vector<K,V>& v) const {
|
void operator()(msgpack::object::with_zone& o, const type::assoc_vector<K, V, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -121,7 +121,7 @@ struct object_with_zone<type::assoc_vector<K, V> > {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename type::assoc_vector<K,V>::const_iterator it(v.begin());
|
typename type::assoc_vector<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
@ -134,15 +134,15 @@ struct object_with_zone<type::assoc_vector<K, V> > {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct as<
|
struct as<
|
||||||
std::map<K, V>,
|
std::map<K, V, Compare, Alloc>,
|
||||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||||
std::map<K, V> operator()(msgpack::object const& o) const {
|
std::map<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::map<K, V> v;
|
std::map<K, V, Compare, Alloc> v;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||||
}
|
}
|
||||||
@ -152,13 +152,13 @@ struct as<
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct convert<std::map<K, V> > {
|
struct convert<std::map<K, V, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::map<K, V>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::map<K, V, Compare, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::map<K, V> tmp;
|
std::map<K, V, Compare, Alloc> tmp;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
K key;
|
K key;
|
||||||
p->key.convert(key);
|
p->key.convert(key);
|
||||||
@ -177,13 +177,13 @@ struct convert<std::map<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct pack<std::map<K, V> > {
|
struct pack<std::map<K, V, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::map<K,V>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::map<K, V, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for (typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -192,9 +192,9 @@ struct pack<std::map<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::map<K, V> > {
|
struct object_with_zone<std::map<K, V, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::map<K,V>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::map<K, V, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -206,7 +206,7 @@ struct object_with_zone<std::map<K, V> > {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename std::map<K,V>::const_iterator it(v.begin());
|
typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
@ -219,15 +219,15 @@ struct object_with_zone<std::map<K, V> > {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct as<
|
struct as<
|
||||||
std::multimap<K, V>,
|
std::multimap<K, V, Compare, Alloc>,
|
||||||
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
typename std::enable_if<msgpack::has_as<K>::value && msgpack::has_as<V>::value>::type> {
|
||||||
std::multimap<K, V> operator()(msgpack::object const& o) const {
|
std::multimap<K, V, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::multimap<K, V> v;
|
std::multimap<K, V, Compare, Alloc> v;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
v.emplace(p->key.as<K>(), p->val.as<V>());
|
v.emplace(p->key.as<K>(), p->val.as<V>());
|
||||||
}
|
}
|
||||||
@ -237,13 +237,13 @@ struct as<
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct convert<std::multimap<K, V> > {
|
struct convert<std::multimap<K, V, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::multimap<K, V>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::multimap<K, V, Compare, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
std::multimap<K, V> tmp;
|
std::multimap<K, V, Compare, Alloc> tmp;
|
||||||
for (; p != pend; ++p) {
|
for (; p != pend; ++p) {
|
||||||
std::pair<K, V> value;
|
std::pair<K, V> value;
|
||||||
p->key.convert(value.first);
|
p->key.convert(value.first);
|
||||||
@ -263,13 +263,13 @@ struct convert<std::multimap<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct pack<std::multimap<K, V> > {
|
struct pack<std::multimap<K, V, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multimap<K,V>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multimap<K, V, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for (typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::multimap<K, V, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -278,9 +278,9 @@ struct pack<std::multimap<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::multimap<K, V> > {
|
struct object_with_zone<std::multimap<K, V, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::multimap<K,V>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::multimap<K, V, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -292,7 +292,7 @@ struct object_with_zone<std::multimap<K, V> > {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename std::multimap<K,V>::const_iterator it(v.begin());
|
typename std::multimap<K, V, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
|
@ -34,13 +34,13 @@ namespace adaptor {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct as<std::set<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
struct as<std::set<T, Compare, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||||
std::set<T> operator()(msgpack::object const& o) const {
|
std::set<T, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::set<T> v;
|
std::set<T, Compare, Alloc> v;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
v.insert(p->as<T>());
|
v.insert(p->as<T>());
|
||||||
@ -51,13 +51,13 @@ struct as<std::set<T>, typename std::enable_if<msgpack::has_as<T>::value>::type>
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct convert<std::set<T> > {
|
struct convert<std::set<T, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::set<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::set<T, Compare, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::set<T> tmp;
|
std::set<T, Compare, Alloc> tmp;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<T>());
|
tmp.insert(p->as<T>());
|
||||||
@ -71,13 +71,13 @@ struct convert<std::set<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct pack<std::set<T> > {
|
struct pack<std::set<T, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::set<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::set<T, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for (typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::set<T, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -85,9 +85,9 @@ struct pack<std::set<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::set<T> > {
|
struct object_with_zone<std::set<T, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::set<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::set<T, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -99,7 +99,7 @@ struct object_with_zone<std::set<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::set<T>::const_iterator it(v.begin());
|
typename std::set<T, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
@ -111,13 +111,13 @@ struct object_with_zone<std::set<T> > {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct as<std::multiset<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
struct as<std::multiset<T, Compare, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||||
std::multiset<T> operator()(msgpack::object const& o) const {
|
std::multiset<T, Compare, Alloc> operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::multiset<T> v;
|
std::multiset<T, Compare, Alloc> v;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
v.insert(p->as<T>());
|
v.insert(p->as<T>());
|
||||||
@ -128,13 +128,13 @@ struct as<std::multiset<T>, typename std::enable_if<msgpack::has_as<T>::value>::
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct convert<std::multiset<T> > {
|
struct convert<std::multiset<T, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::multiset<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::multiset<T, Compare, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
std::multiset<T> tmp;
|
std::multiset<T, Compare, Alloc> tmp;
|
||||||
while (p > pbegin) {
|
while (p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<T>());
|
tmp.insert(p->as<T>());
|
||||||
@ -148,13 +148,13 @@ struct convert<std::multiset<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct pack<std::multiset<T> > {
|
struct pack<std::multiset<T, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multiset<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multiset<T, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for (typename std::multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::multiset<T, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -162,9 +162,9 @@ struct pack<std::multiset<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<std::multiset<T> > {
|
struct object_with_zone<std::multiset<T, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::multiset<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::multiset<T, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -175,7 +175,7 @@ struct object_with_zone<std::multiset<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::multiset<T>::const_iterator it(v.begin());
|
typename std::multiset<T, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -51,13 +51,13 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct convert<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
struct convert<MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
MSGPACK_STD_TR1::unordered_map<K, V> tmp;
|
MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc> tmp;
|
||||||
for(; p != pend; ++p) {
|
for(; p != pend; ++p) {
|
||||||
K key;
|
K key;
|
||||||
p->key.convert(key);
|
p->key.convert(key);
|
||||||
@ -68,13 +68,13 @@ struct convert<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct pack<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
struct pack<MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for(typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -83,9 +83,9 @@ struct pack<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
struct object_with_zone<MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v) const {
|
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -96,7 +96,7 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin());
|
typename MSGPACK_STD_TR1::unordered_map<K, V, Hash, Pred, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
@ -107,13 +107,13 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct convert<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
struct convert<MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||||
msgpack::object_kv* p(o.via.map.ptr);
|
msgpack::object_kv* p(o.via.map.ptr);
|
||||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||||
MSGPACK_STD_TR1::unordered_multimap<K, V> tmp;
|
MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc> tmp;
|
||||||
for(; p != pend; ++p) {
|
for(; p != pend; ++p) {
|
||||||
std::pair<K, V> value;
|
std::pair<K, V> value;
|
||||||
p->key.convert(value.first);
|
p->key.convert(value.first);
|
||||||
@ -125,13 +125,13 @@ struct convert<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct pack<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
struct pack<MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_map(size);
|
o.pack_map(size);
|
||||||
for(typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(it->first);
|
o.pack(it->first);
|
||||||
o.pack(it->second);
|
o.pack(it->second);
|
||||||
@ -140,9 +140,9 @@ struct pack<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V, typename Hash, typename Pred, typename Alloc>
|
||||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
struct object_with_zone<MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v) const {
|
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc>& v) const {
|
||||||
o.type = msgpack::type::MAP;
|
o.type = msgpack::type::MAP;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.map.ptr = nullptr;
|
o.via.map.ptr = nullptr;
|
||||||
@ -153,7 +153,7 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
|||||||
msgpack::object_kv* const pend = p + size;
|
msgpack::object_kv* const pend = p + size;
|
||||||
o.via.map.ptr = p;
|
o.via.map.ptr = p;
|
||||||
o.via.map.size = size;
|
o.via.map.size = size;
|
||||||
typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin());
|
typename MSGPACK_STD_TR1::unordered_multimap<K, V, Hash, Pred, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
p->key = msgpack::object(it->first, o.zone);
|
p->key = msgpack::object(it->first, o.zone);
|
||||||
p->val = msgpack::object(it->second, o.zone);
|
p->val = msgpack::object(it->second, o.zone);
|
||||||
|
@ -51,13 +51,13 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<MSGPACK_STD_TR1::unordered_set<T> > {
|
struct convert<MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
MSGPACK_STD_TR1::unordered_set<T> tmp;
|
MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc> tmp;
|
||||||
while(p > pbegin) {
|
while(p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<T>());
|
tmp.insert(p->as<T>());
|
||||||
@ -67,13 +67,13 @@ struct convert<MSGPACK_STD_TR1::unordered_set<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<MSGPACK_STD_TR1::unordered_set<T> > {
|
struct pack<MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -81,9 +81,9 @@ struct pack<MSGPACK_STD_TR1::unordered_set<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_set<T> > {
|
struct object_with_zone<MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -94,7 +94,7 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_set<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin());
|
typename MSGPACK_STD_TR1::unordered_set<T, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
@ -105,13 +105,13 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_set<T> > {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct convert<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
struct convert<MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc>& v) const {
|
||||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||||
msgpack::object* const pbegin = o.via.array.ptr;
|
msgpack::object* const pbegin = o.via.array.ptr;
|
||||||
MSGPACK_STD_TR1::unordered_multiset<T> tmp;
|
MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc> tmp;
|
||||||
while(p > pbegin) {
|
while(p > pbegin) {
|
||||||
--p;
|
--p;
|
||||||
tmp.insert(p->as<T>());
|
tmp.insert(p->as<T>());
|
||||||
@ -121,13 +121,13 @@ struct convert<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct pack<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
struct pack<MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -135,9 +135,9 @@ struct pack<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Hash, typename Compare, typename Alloc>
|
||||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
struct object_with_zone<MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -148,7 +148,7 @@ struct object_with_zone<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin());
|
typename MSGPACK_STD_TR1::unordered_multiset<T, Hash, Compare, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(*it, o.zone);
|
*p = msgpack::object(*it, o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -34,11 +34,11 @@ namespace adaptor {
|
|||||||
|
|
||||||
#if !defined(MSGPACK_USE_CPP03)
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct as<std::vector<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
struct as<std::vector<T, Alloc>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||||
std::vector<T> operator()(const msgpack::object& o) const {
|
std::vector<T, Alloc> operator()(const msgpack::object& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
std::vector<T> v;
|
std::vector<T, Alloc> v;
|
||||||
v.reserve(o.via.array.size);
|
v.reserve(o.via.array.size);
|
||||||
if (o.via.array.size > 0) {
|
if (o.via.array.size > 0) {
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
@ -54,15 +54,15 @@ struct as<std::vector<T>, typename std::enable_if<msgpack::has_as<T>::value>::ty
|
|||||||
|
|
||||||
#endif // !defined(MSGPACK_USE_CPP03)
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct convert<std::vector<T> > {
|
struct convert<std::vector<T, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<T>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::vector<T, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
v.resize(o.via.array.size);
|
v.resize(o.via.array.size);
|
||||||
if (o.via.array.size > 0) {
|
if (o.via.array.size > 0) {
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||||
typename std::vector<T>::iterator it = v.begin();
|
typename std::vector<T, Alloc>::iterator it = v.begin();
|
||||||
do {
|
do {
|
||||||
p->convert(*it);
|
p->convert(*it);
|
||||||
++p;
|
++p;
|
||||||
@ -73,13 +73,13 @@ struct convert<std::vector<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct pack<std::vector<T> > {
|
struct pack<std::vector<T, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<T>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<T, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for (typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
for (typename std::vector<T, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(*it);
|
o.pack(*it);
|
||||||
}
|
}
|
||||||
@ -87,9 +87,9 @@ struct pack<std::vector<T> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T, typename Alloc>
|
||||||
struct object_with_zone<std::vector<T> > {
|
struct object_with_zone<std::vector<T, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::vector<T>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::vector<T, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if (v.empty()) {
|
if (v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -101,7 +101,7 @@ struct object_with_zone<std::vector<T> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
typename std::vector<T>::const_iterator it(v.begin());
|
typename std::vector<T, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
@ -30,14 +30,14 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct convert<std::vector<bool> > {
|
struct convert<std::vector<bool, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<bool>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::vector<bool, Alloc>& v) const {
|
||||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||||
if (o.via.array.size > 0) {
|
if (o.via.array.size > 0) {
|
||||||
v.resize(o.via.array.size);
|
v.resize(o.via.array.size);
|
||||||
msgpack::object* p = o.via.array.ptr;
|
msgpack::object* p = o.via.array.ptr;
|
||||||
for (std::vector<bool>::iterator it = v.begin(), end = v.end();
|
for (typename std::vector<bool, Alloc>::iterator it = v.begin(), end = v.end();
|
||||||
it != end;
|
it != end;
|
||||||
++it) {
|
++it) {
|
||||||
*it = p->as<bool>();
|
*it = p->as<bool>();
|
||||||
@ -48,13 +48,13 @@ struct convert<std::vector<bool> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct pack<std::vector<bool> > {
|
struct pack<std::vector<bool, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<bool>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<bool, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_array(size);
|
o.pack_array(size);
|
||||||
for(std::vector<bool>::const_iterator it(v.begin()), it_end(v.end());
|
for(typename std::vector<bool, Alloc>::const_iterator it(v.begin()), it_end(v.end());
|
||||||
it != it_end; ++it) {
|
it != it_end; ++it) {
|
||||||
o.pack(static_cast<bool>(*it));
|
o.pack(static_cast<bool>(*it));
|
||||||
}
|
}
|
||||||
@ -62,9 +62,9 @@ struct pack<std::vector<bool> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct object_with_zone<std::vector<bool> > {
|
struct object_with_zone<std::vector<bool, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::vector<bool>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::vector<bool, Alloc>& v) const {
|
||||||
o.type = msgpack::type::ARRAY;
|
o.type = msgpack::type::ARRAY;
|
||||||
if(v.empty()) {
|
if(v.empty()) {
|
||||||
o.via.array.ptr = nullptr;
|
o.via.array.ptr = nullptr;
|
||||||
@ -75,7 +75,7 @@ struct object_with_zone<std::vector<bool> > {
|
|||||||
msgpack::object* const pend = p + size;
|
msgpack::object* const pend = p + size;
|
||||||
o.via.array.ptr = p;
|
o.via.array.ptr = p;
|
||||||
o.via.array.size = size;
|
o.via.array.size = size;
|
||||||
std::vector<bool>::const_iterator it(v.begin());
|
typename std::vector<bool, Alloc>::const_iterator it(v.begin());
|
||||||
do {
|
do {
|
||||||
*p = msgpack::object(static_cast<bool>(*it), o.zone);
|
*p = msgpack::object(static_cast<bool>(*it), o.zone);
|
||||||
++p;
|
++p;
|
||||||
|
@ -32,9 +32,9 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
|
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct convert<std::vector<char> > {
|
struct convert<std::vector<char, Alloc> > {
|
||||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<char>& v) const {
|
msgpack::object const& operator()(msgpack::object const& o, std::vector<char, Alloc>& v) const {
|
||||||
switch (o.type) {
|
switch (o.type) {
|
||||||
case msgpack::type::BIN:
|
case msgpack::type::BIN:
|
||||||
v.resize(o.via.bin.size);
|
v.resize(o.via.bin.size);
|
||||||
@ -52,10 +52,10 @@ struct convert<std::vector<char> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct pack<std::vector<char> > {
|
struct pack<std::vector<char, Alloc> > {
|
||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char>& v) const {
|
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.pack_bin(size);
|
o.pack_bin(size);
|
||||||
o.pack_bin_body(&v.front(), size);
|
o.pack_bin_body(&v.front(), size);
|
||||||
@ -64,9 +64,9 @@ struct pack<std::vector<char> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct object<std::vector<char> > {
|
struct object<std::vector<char, Alloc> > {
|
||||||
void operator()(msgpack::object& o, const std::vector<char>& v) const {
|
void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.type = msgpack::type::BIN;
|
o.type = msgpack::type::BIN;
|
||||||
o.via.bin.ptr = &v.front();
|
o.via.bin.ptr = &v.front();
|
||||||
@ -74,9 +74,9 @@ struct object<std::vector<char> > {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <typename Alloc>
|
||||||
struct object_with_zone<std::vector<char> > {
|
struct object_with_zone<std::vector<char, Alloc> > {
|
||||||
void operator()(msgpack::object::with_zone& o, const std::vector<char>& v) const {
|
void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const {
|
||||||
uint32_t size = checked_get_container_size(v.size());
|
uint32_t size = checked_get_container_size(v.size());
|
||||||
o.type = msgpack::type::BIN;
|
o.type = msgpack::type::BIN;
|
||||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "test_allocator.hpp"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -21,187 +23,227 @@ using namespace std;
|
|||||||
const unsigned int kLoop = 1000;
|
const unsigned int kLoop = 1000;
|
||||||
const unsigned int kElements = 100;
|
const unsigned int kElements = 100;
|
||||||
|
|
||||||
|
// strong typedefs
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct equal_to : std::equal_to<Key> {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct less : std::less<Key> {
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_vector)
|
TEST(MSGPACK_STL, simple_buffer_vector)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef vector<int, test::allocator<int> > type;
|
||||||
vector<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
|
type val1;
|
||||||
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
|
val1.push_back(rand());
|
||||||
|
msgpack::sbuffer sbuf;
|
||||||
|
msgpack::pack(sbuf, val1);
|
||||||
|
msgpack::unpacked ret;
|
||||||
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
|
||||||
|
type const& val2 = ret.get().as<type>();
|
||||||
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK_STL, simple_buffer_vector_char)
|
||||||
|
{
|
||||||
|
typedef vector<char, test::allocator<char> > type;
|
||||||
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
|
type val1;
|
||||||
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
|
val1.push_back(rand());
|
||||||
|
msgpack::sbuffer sbuf;
|
||||||
|
msgpack::pack(sbuf, val1);
|
||||||
|
msgpack::unpacked ret;
|
||||||
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
|
||||||
|
type const& val2 = ret.get().as<type>();
|
||||||
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK_STL, simple_buffer_vector_bool)
|
||||||
|
{
|
||||||
|
typedef vector<bool, test::allocator<bool> > type;
|
||||||
|
type val1;
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
val1.push_back(rand());
|
val1.push_back(i % 2 ? false : true);
|
||||||
msgpack::sbuffer sbuf;
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpacked ret;
|
msgpack::unpacked ret;
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
|
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
|
||||||
vector<int> val2 = ret.get().as<vector<int> >();
|
type const& val2 = ret.get().as<type>();
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_vector_char)
|
|
||||||
|
TEST(MSGPACK_STL, simple_buffer_assoc_vector)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef msgpack::type::assoc_vector<int, int, test::less<int>, test::allocator<std::pair<int, int> > >type;
|
||||||
vector<char> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.push_back(rand());
|
val1.push_back(std::make_pair(1, 2));
|
||||||
msgpack::sbuffer sbuf;
|
val1.push_back(std::make_pair(3, 4));
|
||||||
msgpack::pack(sbuf, val1);
|
val1.push_back(std::make_pair(5, 6));
|
||||||
msgpack::unpacked ret;
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::pack(sbuf, val1);
|
||||||
EXPECT_EQ(ret.get().type, msgpack::type::BIN);
|
msgpack::unpacked ret;
|
||||||
vector<char> val2 = ret.get().as<vector<char> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type const& val2 = ret.get().as<type>();
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
}
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_vector_bool)
|
|
||||||
{
|
|
||||||
vector<bool> val1;
|
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
|
||||||
val1.push_back(i % 2 ? false : true);
|
|
||||||
msgpack::sbuffer sbuf;
|
|
||||||
msgpack::pack(sbuf, val1);
|
|
||||||
msgpack::unpacked ret;
|
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
|
||||||
EXPECT_EQ(ret.get().type, msgpack::type::ARRAY);
|
|
||||||
vector<bool> val2 = ret.get().as<vector<bool> >();
|
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_map)
|
TEST(MSGPACK_STL, simple_buffer_map)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef map<int, int, test::less<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
map<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1[rand()] = rand();
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1[rand()] = rand();
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
map<int, int> val2 = ret.get().as<map<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type const& val2 = ret.get().as<type>();
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
}
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_deque)
|
TEST(MSGPACK_STL, simple_buffer_deque)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef deque<int, test::allocator<int> > type;
|
||||||
deque<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.push_back(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.push_back(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
deque<int> val2 = ret.get().as<deque<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type const& val2 = ret.get().as<type>();
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
}
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_list)
|
TEST(MSGPACK_STL, simple_buffer_list)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef list<int, test::allocator<int> > type;
|
||||||
list<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.push_back(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.push_back(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
list<int> val2 = ret.get().as<list<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type const& val2 = ret.get().as<type>();
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
}
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_set)
|
TEST(MSGPACK_STL, simple_buffer_set)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef set<int, test::less<int>, test::allocator<int> > type;
|
||||||
set<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
set<int> val2 = ret.get().as<set<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type val2 = ret.get().as<type>();
|
||||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
}
|
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_pair)
|
TEST(MSGPACK_STL, simple_buffer_pair)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
pair<int, int> val1 = make_pair(rand(), rand());
|
pair<int, int> val1 = make_pair(rand(), rand());
|
||||||
msgpack::sbuffer sbuf;
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpacked ret;
|
msgpack::unpacked ret;
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
pair<int, int> val2 = ret.get().as<pair<int, int> >();
|
pair<int, int> val2 = ret.get().as<pair<int, int> >();
|
||||||
EXPECT_EQ(val1.first, val2.first);
|
EXPECT_EQ(val1.first, val2.first);
|
||||||
EXPECT_EQ(val1.second, val2.second);
|
EXPECT_EQ(val1.second, val2.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_multimap)
|
TEST(MSGPACK_STL, simple_buffer_multimap)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef multimap<int, int, test::less<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
multimap<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++) {
|
type val1;
|
||||||
int i1 = rand();
|
for (unsigned int i = 0; i < kElements; i++) {
|
||||||
val1.insert(make_pair(i1, rand()));
|
int i1 = rand();
|
||||||
val1.insert(make_pair(i1, rand()));
|
val1.insert(make_pair(i1, rand()));
|
||||||
}
|
val1.insert(make_pair(i1, rand()));
|
||||||
msgpack::sbuffer sbuf;
|
}
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
multimap<int, int> val2 = ret.get().as<multimap<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<pair<int, int> > v1, v2;
|
vector<pair<int, int> > v1, v2;
|
||||||
multimap<int, int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(make_pair(it->first, it->second));
|
v1.push_back(make_pair(it->first, it->second));
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(make_pair(it->first, it->second));
|
v2.push_back(make_pair(it->first, it->second));
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_multiset)
|
TEST(MSGPACK_STL, simple_buffer_multiset)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef multiset<int, test::less<int>, test::allocator<int> > type;
|
||||||
multiset<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
multiset<int> val2 = ret.get().as<multiset<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<int> v1, v2;
|
vector<int> v1, v2;
|
||||||
multiset<int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(*it);
|
v1.push_back(*it);
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(*it);
|
v2.push_back(*it);
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_TUPLE, simple_tuple)
|
TEST(MSGPACK_TUPLE, simple_tuple)
|
||||||
@ -233,56 +275,72 @@ TEST(MSGPACK_TUPLE, simple_tuple_empty)
|
|||||||
|
|
||||||
// TR1
|
// TR1
|
||||||
|
|
||||||
|
#if defined(MSGPACK_HAS_STD_TR1_UNORDERED_MAP) || defined(MSGPACK_HAS_STD_TR1_UNORDERED_SET)
|
||||||
|
|
||||||
|
#include <tr1/functional>
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct tr1_hash : std::tr1::hash<Key> {
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
#endif // defined(MSGPACK_HAS_STD_TR1_UNORDERED_MAP) || defined(MSGPACK_HAS_STD_TR1_UNORDERED_SET)
|
||||||
|
|
||||||
#ifdef MSGPACK_HAS_STD_TR1_UNORDERED_MAP
|
#ifdef MSGPACK_HAS_STD_TR1_UNORDERED_MAP
|
||||||
#include <tr1/unordered_map>
|
#include <tr1/unordered_map>
|
||||||
#include "msgpack/adaptor/tr1/unordered_map.hpp"
|
#include "msgpack/adaptor/tr1/unordered_map.hpp"
|
||||||
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map)
|
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef tr1::unordered_map<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
tr1::unordered_map<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1[rand()] = rand();
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1[rand()] = rand();
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
tr1::unordered_map<int, int> val2 = ret.get().as<tr1::unordered_map<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type val2 = ret.get().as<type>();
|
||||||
tr1::unordered_map<int, int>::const_iterator it;
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
for (it = val1.begin(); it != val1.end(); ++it) {
|
type::const_iterator it;
|
||||||
EXPECT_TRUE(val2.find(it->first) != val2.end());
|
for (it = val1.begin(); it != val1.end(); ++it) {
|
||||||
EXPECT_EQ(it->second, val2.find(it->first)->second);
|
EXPECT_TRUE(val2.find(it->first) != val2.end());
|
||||||
|
EXPECT_EQ(it->second, val2.find(it->first)->second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
|
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef tr1::unordered_multimap<int, int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
tr1::unordered_multimap<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++) {
|
type val1;
|
||||||
int i1 = rand();
|
for (unsigned int i = 0; i < kElements; i++) {
|
||||||
val1.insert(make_pair(i1, rand()));
|
int i1 = rand();
|
||||||
val1.insert(make_pair(i1, rand()));
|
val1.insert(make_pair(i1, rand()));
|
||||||
}
|
val1.insert(make_pair(i1, rand()));
|
||||||
msgpack::sbuffer sbuf;
|
}
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
tr1::unordered_multimap<int, int> val2 = ret.get().as<tr1::unordered_multimap<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<pair<int, int> > v1, v2;
|
vector<pair<int, int> > v1, v2;
|
||||||
tr1::unordered_multimap<int, int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(make_pair(it->first, it->second));
|
v1.push_back(make_pair(it->first, it->second));
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(make_pair(it->first, it->second));
|
v2.push_back(make_pair(it->first, it->second));
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -291,146 +349,167 @@ TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
|
|||||||
#include "msgpack/adaptor/tr1/unordered_set.hpp"
|
#include "msgpack/adaptor/tr1/unordered_set.hpp"
|
||||||
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set)
|
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef tr1::unordered_set<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type;
|
||||||
tr1::unordered_set<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
tr1::unordered_set<int> val2 = ret.get().as<tr1::unordered_set<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type val2 = ret.get().as<type>();
|
||||||
tr1::unordered_set<int>::const_iterator it;
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
type::const_iterator it;
|
||||||
EXPECT_TRUE(val2.find(*it) != val2.end());
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
}
|
EXPECT_TRUE(val2.find(*it) != val2.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset)
|
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef tr1::unordered_multiset<int, test::tr1_hash<int>, test::equal_to<int>, test::allocator<int> > type;
|
||||||
tr1::unordered_multiset<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
tr1::unordered_multiset<int> val2 = ret.get().as<tr1::unordered_multiset<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<int> v1, v2;
|
vector<int> v1, v2;
|
||||||
tr1::unordered_multiset<int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(*it);
|
v1.push_back(*it);
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(*it);
|
v2.push_back(*it);
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET)
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct hash : std::hash<Key> {
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
#endif // defined (MSGPACK_HAS_STD_UNORDERED_MAP) || defined (MSGPACK_HAS_STD_UNORDERED_SET)
|
||||||
|
|
||||||
#ifdef MSGPACK_HAS_STD_UNORDERED_MAP
|
#ifdef MSGPACK_HAS_STD_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "msgpack/adaptor/tr1/unordered_map.hpp"
|
#include "msgpack/adaptor/tr1/unordered_map.hpp"
|
||||||
TEST(MSGPACK_TR1, simple_buffer_unordered_map)
|
TEST(MSGPACK_TR1, simple_buffer_unordered_map)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
unordered_map<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1[rand()] = rand();
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1[rand()] = rand();
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_map<int, int> val2 = ret.get().as<unordered_map<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type val2 = ret.get().as<type>();
|
||||||
unordered_map<int, int>::const_iterator it;
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
for (it = val1.begin(); it != val1.end(); ++it) {
|
type::const_iterator it;
|
||||||
EXPECT_TRUE(val2.find(it->first) != val2.end());
|
for (it = val1.begin(); it != val1.end(); ++it) {
|
||||||
EXPECT_EQ(it->second, val2.find(it->first)->second);
|
EXPECT_TRUE(val2.find(it->first) != val2.end());
|
||||||
|
EXPECT_EQ(it->second, val2.find(it->first)->second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
|
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::allocator<std::pair<int, int> > > type;
|
||||||
unordered_multimap<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++) {
|
type val1;
|
||||||
int i1 = rand();
|
for (unsigned int i = 0; i < kElements; i++) {
|
||||||
val1.insert(make_pair(i1, rand()));
|
int i1 = rand();
|
||||||
val1.insert(make_pair(i1, rand()));
|
val1.insert(make_pair(i1, rand()));
|
||||||
}
|
val1.insert(make_pair(i1, rand()));
|
||||||
msgpack::sbuffer sbuf;
|
}
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_multimap<int, int> val2 = ret.get().as<unordered_multimap<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<pair<int, int> > v1, v2;
|
vector<pair<int, int> > v1, v2;
|
||||||
unordered_multimap<int, int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(make_pair(it->first, it->second));
|
v1.push_back(make_pair(it->first, it->second));
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(make_pair(it->first, it->second));
|
v2.push_back(make_pair(it->first, it->second));
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MSGPACK_HAS_STD_UNORDERED_SET
|
#ifdef MSGPACK_HAS_STD_UNORDERED_SET
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "msgpack/adaptor/tr1/unordered_set.hpp"
|
#include "msgpack/adaptor/tr1/unordered_set.hpp"
|
||||||
TEST(MSGPACK_TR1, simple_buffer_unordered_set)
|
TEST(MSGPACK_TR1, simple_buffer_unordered_set)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef unordered_set<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type;
|
||||||
unordered_set<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_set<int> val2 = ret.get().as<unordered_set<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
type val2 = ret.get().as<type>();
|
||||||
unordered_set<int>::const_iterator it;
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
type::const_iterator it;
|
||||||
EXPECT_TRUE(val2.find(*it) != val2.end());
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
}
|
EXPECT_TRUE(val2.find(*it) != val2.end());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
|
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
typedef unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::allocator<int> > type;
|
||||||
unordered_multiset<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_multiset<int> val2 = ret.get().as<unordered_multiset<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type>();
|
||||||
|
|
||||||
vector<int> v1, v2;
|
vector<int> v1, v2;
|
||||||
unordered_multiset<int>::const_iterator it;
|
type::const_iterator it;
|
||||||
for (it = val1.begin(); it != val1.end(); ++it)
|
for (it = val1.begin(); it != val1.end(); ++it)
|
||||||
v1.push_back(*it);
|
v1.push_back(*it);
|
||||||
for (it = val2.begin(); it != val2.end(); ++it)
|
for (it = val2.begin(); it != val2.end(); ++it)
|
||||||
v2.push_back(*it);
|
v2.push_back(*it);
|
||||||
EXPECT_EQ(val1.size(), val2.size());
|
EXPECT_EQ(val1.size(), val2.size());
|
||||||
EXPECT_EQ(v1.size(), v2.size());
|
EXPECT_EQ(v1.size(), v2.size());
|
||||||
sort(v1.begin(), v1.end());
|
sort(v1.begin(), v1.end());
|
||||||
sort(v2.begin(), v2.end());
|
sort(v2.begin(), v2.end());
|
||||||
EXPECT_TRUE(v1 == v2);
|
EXPECT_TRUE(v1 == v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -93,83 +93,119 @@ TEST(MSGPACK_CPP11, simple_buffer_array_char)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// strong typedefs
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct hash : std::hash<Key> {
|
||||||
|
using std::hash<Key>::hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct equal_to : std::equal_to<Key> {
|
||||||
|
using std::equal_to<Key>::equal_to;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Key>
|
||||||
|
struct set_allocator : std::allocator<Key> {
|
||||||
|
using std::allocator<Key>::allocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Key, class T>
|
||||||
|
struct map_allocator : std::allocator<std::pair<const Key, T>> {
|
||||||
|
using std::allocator<std::pair<const Key, T>>::allocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
struct allocator : std::allocator<T> {
|
||||||
|
using std::allocator<T>::allocator;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_forward_list)
|
TEST(MSGPACK_STL, simple_buffer_forward_list)
|
||||||
{
|
{
|
||||||
|
using type = forward_list<int, test::allocator<int>>;
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
forward_list<int> val1;
|
type val1;
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
val1.push_front(rand());
|
val1.push_front(rand());
|
||||||
msgpack::sbuffer sbuf;
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpacked ret;
|
msgpack::unpacked ret;
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
forward_list<int> val2 = ret.get().as<forward_list<int> >();
|
type val2 = ret.get().as<type >();
|
||||||
EXPECT_EQ(val1, val2);
|
EXPECT_EQ(val1, val2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_unordered_map)
|
TEST(MSGPACK_STL, simple_buffer_unordered_map)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
using type = unordered_map<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
|
||||||
unordered_map<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1[rand()] = rand();
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1[rand()] = rand();
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_map<int, int> val2 = ret.get().as<unordered_map<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1, val2);
|
type val2 = ret.get().as<type >();
|
||||||
}
|
EXPECT_EQ(val1, val2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_unordered_multimap)
|
TEST(MSGPACK_STL, simple_buffer_unordered_multimap)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
using type = unordered_multimap<int, int, test::hash<int>, test::equal_to<int>, test::map_allocator<int, int>>;
|
||||||
unordered_multimap<int, int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++) {
|
type val1;
|
||||||
int i1 = rand();
|
for (unsigned int i = 0; i < kElements; i++) {
|
||||||
val1.insert(make_pair(i1, rand()));
|
int i1 = rand();
|
||||||
val1.insert(make_pair(i1, rand()));
|
val1.insert(make_pair(i1, rand()));
|
||||||
}
|
val1.insert(make_pair(i1, rand()));
|
||||||
msgpack::sbuffer sbuf;
|
}
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_multimap<int, int> val2 = ret.get().as<unordered_multimap<int, int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
|
type val2 = ret.get().as<type >();
|
||||||
|
|
||||||
EXPECT_EQ(val1, val2);
|
EXPECT_EQ(val1, val2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_unordered_set)
|
TEST(MSGPACK_STL, simple_buffer_unordered_set)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
using type = unordered_set<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
|
||||||
unordered_set<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_set<int> val2 = ret.get().as<unordered_set<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1, val2);
|
type val2 = ret.get().as<type>();
|
||||||
}
|
EXPECT_EQ(val1, val2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_STL, simple_buffer_unordered_multiset)
|
TEST(MSGPACK_STL, simple_buffer_unordered_multiset)
|
||||||
{
|
{
|
||||||
for (unsigned int k = 0; k < kLoop; k++) {
|
using type = unordered_multiset<int, test::hash<int>, test::equal_to<int>, test::set_allocator<int>>;
|
||||||
unordered_multiset<int> val1;
|
for (unsigned int k = 0; k < kLoop; k++) {
|
||||||
for (unsigned int i = 0; i < kElements; i++)
|
type val1;
|
||||||
val1.insert(rand());
|
for (unsigned int i = 0; i < kElements; i++)
|
||||||
msgpack::sbuffer sbuf;
|
val1.insert(rand());
|
||||||
msgpack::pack(sbuf, val1);
|
msgpack::sbuffer sbuf;
|
||||||
msgpack::unpacked ret;
|
msgpack::pack(sbuf, val1);
|
||||||
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
msgpack::unpacked ret;
|
||||||
unordered_multiset<int> val2 = ret.get().as<unordered_multiset<int> >();
|
msgpack::unpack(ret, sbuf.data(), sbuf.size());
|
||||||
EXPECT_EQ(val1, val2);
|
type val2 = ret.get().as<type >();
|
||||||
}
|
EXPECT_EQ(val1, val2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_class_member)
|
TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_class_member)
|
||||||
@ -206,16 +242,16 @@ inline bool operator<(no_def_con const& lhs, no_def_con const& rhs) {
|
|||||||
|
|
||||||
namespace msgpack {
|
namespace msgpack {
|
||||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
template <>
|
template <>
|
||||||
struct as<no_def_con> {
|
struct as<no_def_con> {
|
||||||
no_def_con operator()(msgpack::object const& o) const {
|
no_def_con operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
||||||
if (o.via.array.size != 1) throw msgpack::type_error();
|
if (o.via.array.size != 1) throw msgpack::type_error();
|
||||||
return no_def_con(o.via.array.ptr[0].as<int>());
|
return no_def_con(o.via.array.ptr[0].as<int>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // adaptor
|
} // adaptor
|
||||||
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||||
} // msgpack
|
} // msgpack
|
||||||
|
|
||||||
@ -261,16 +297,16 @@ inline bool operator<(no_def_con_composite const& lhs, no_def_con_composite cons
|
|||||||
|
|
||||||
namespace msgpack {
|
namespace msgpack {
|
||||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
template <>
|
template <>
|
||||||
struct as<no_def_con_composite> {
|
struct as<no_def_con_composite> {
|
||||||
no_def_con_composite operator()(msgpack::object const& o) const {
|
no_def_con_composite operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
||||||
if (o.via.array.size != 1) throw msgpack::type_error();
|
if (o.via.array.size != 1) throw msgpack::type_error();
|
||||||
return no_def_con_composite(o.via.array.ptr[0].as<no_def_con>());
|
return no_def_con_composite(o.via.array.ptr[0].as<no_def_con>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // adaptor
|
} // adaptor
|
||||||
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||||
} // msgpack
|
} // msgpack
|
||||||
|
|
||||||
@ -293,16 +329,16 @@ struct no_def_con_inherit : no_def_con {
|
|||||||
|
|
||||||
namespace msgpack {
|
namespace msgpack {
|
||||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||||
namespace adaptor {
|
namespace adaptor {
|
||||||
template <>
|
template <>
|
||||||
struct as<no_def_con_inherit> {
|
struct as<no_def_con_inherit> {
|
||||||
no_def_con_inherit operator()(msgpack::object const& o) const {
|
no_def_con_inherit operator()(msgpack::object const& o) const {
|
||||||
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
||||||
if (o.via.array.size != 1) throw msgpack::type_error();
|
if (o.via.array.size != 1) throw msgpack::type_error();
|
||||||
return no_def_con_inherit(o.via.array.ptr[0].as<no_def_con>());
|
return no_def_con_inherit(o.via.array.ptr[0].as<no_def_con>());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // adaptor
|
} // adaptor
|
||||||
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||||
} // msgpack
|
} // msgpack
|
||||||
|
|
||||||
|
87
test/test_allocator.hpp
Normal file
87
test/test_allocator.hpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for C++ static resolution routine
|
||||||
|
//
|
||||||
|
// Copyright (C) 2015 KONDO Takatoshi
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TEST_ALLOCATOR_HPP
|
||||||
|
#define TEST_ALLOCATOR_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct allocator {
|
||||||
|
typedef typename std::allocator<T>::value_type value_type;
|
||||||
|
typedef typename std::allocator<T>::pointer pointer;
|
||||||
|
typedef typename std::allocator<T>::reference reference;
|
||||||
|
typedef typename std::allocator<T>::const_pointer const_pointer;
|
||||||
|
typedef typename std::allocator<T>::const_reference const_reference;
|
||||||
|
typedef typename std::allocator<T>::size_type size_type;
|
||||||
|
typedef typename std::allocator<T>::difference_type difference_type;
|
||||||
|
template <class U> struct rebind { typedef allocator<U> other; };
|
||||||
|
#if defined(MSGPACK_USE_CPP03)
|
||||||
|
allocator() throw() {}
|
||||||
|
allocator (const allocator& alloc) throw()
|
||||||
|
:alloc_(alloc.alloc_) {}
|
||||||
|
template <class U>
|
||||||
|
allocator (const allocator<U>& alloc) throw()
|
||||||
|
:alloc_(alloc.alloc_) {}
|
||||||
|
|
||||||
|
|
||||||
|
void construct ( pointer p, const_reference val ) {
|
||||||
|
return alloc_.construct(p, val);
|
||||||
|
}
|
||||||
|
size_type max_size() const throw() { return alloc_.max_size(); }
|
||||||
|
#else // defined(MSGPACK_USE_CPP03)
|
||||||
|
allocator() noexcept {}
|
||||||
|
allocator (const allocator& alloc) noexcept
|
||||||
|
:alloc_(alloc.alloc_) {}
|
||||||
|
template <class U>
|
||||||
|
allocator (const allocator<U>& alloc) noexcept
|
||||||
|
:alloc_(alloc.alloc_) {}
|
||||||
|
template <class U, class... Args>
|
||||||
|
void construct (U* p, Args&&... args) {
|
||||||
|
return alloc_.construct(p, std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
size_type max_size() const noexcept { return alloc_.max_size(); }
|
||||||
|
#endif // defined(MSGPACK_USE_CPP03)
|
||||||
|
pointer allocate (size_type n) {
|
||||||
|
return alloc_.allocate(n);
|
||||||
|
}
|
||||||
|
void deallocate (pointer p, size_type n) {
|
||||||
|
return alloc_.deallocate(p, n);
|
||||||
|
}
|
||||||
|
void destroy (pointer p) {
|
||||||
|
alloc_.destroy(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::allocator<T> alloc_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool operator==(allocator<T> const& lhs, allocator<T> const& rhs) {
|
||||||
|
return lhs.alloc_ == rhs.alloc_;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline bool operator!=(allocator<T> const& lhs, allocator<T> const& rhs) {
|
||||||
|
return lhs.alloc_ != rhs.alloc_;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
#endif // TEST_ALLOCATOR_HPP
|
Loading…
x
Reference in New Issue
Block a user