pair.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_TYPE_PAIR_HPP
#define MSGPACK_V1_TYPE_PAIR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/meta.hpp"
#include <utility>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace adaptor {
#if !defined(MSGPACK_USE_CPP03)
template <typename T1, typename T2>
struct as<std::pair<T1, T2>,
typename std::enable_if<msgpack::any_of<msgpack::has_as, T1, T2>::value>::type> {
std::pair<T1, T2> operator()(msgpack::object const& o) const {
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
if (o.via.array.size != 2) { throw msgpack::type_error(); }
return std::make_pair(o.via.array.ptr[0].as<T1>(), o.via.array.ptr[1].as<T2>());
}
};
#endif // !defined(MSGPACK_USE_CPP03)
template <typename T1, typename T2>
struct convert<std::pair<T1, T2> > {
msgpack::object const& operator()(msgpack::object const& o, std::pair<T1, T2>& v) const {
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
if(o.via.array.size != 2) { throw msgpack::type_error(); }
o.via.array.ptr[0].convert(v.first);
o.via.array.ptr[1].convert(v.second);
return o;
}
};
template <typename T1, typename T2>
struct pack<std::pair<T1, T2> > {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::pair<T1, T2>& v) const {
o.pack_array(2);
o.pack(v.first);
o.pack(v.second);
return o;
}
};
template <typename T1, typename T2>
struct object_with_zone<std::pair<T1, T2> > {
void operator()(msgpack::object::with_zone& o, const std::pair<T1, T2>& v) const {
o.type = msgpack::type::ARRAY;
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*2, MSGPACK_ZONE_ALIGNOF(msgpack::object)));
o.via.array.ptr = p;
o.via.array.size = 2;
p[0] = msgpack::object(v.first, o.zone);
p[1] = msgpack::object(v.second, o.zone);
}
};
} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_PAIR_HPP
msgpack::object_array::size
uint32_t size
Definition: object_fwd.hpp:23
msgpack::zone::allocate_align
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition: cpp03_zone.hpp:246
msgpack::adaptor::pack< std::pair< T1, T2 > >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const std::pair< T1, T2 > &v) const
Definition: pair.hpp:55
meta.hpp
msgpack::adaptor::convert< std::pair< T1, T2 > >::operator()
msgpack::object const & operator()(msgpack::object const &o, std::pair< T1, T2 > &v) const
Definition: pair.hpp:43
msgpack::adaptor::as
Definition: object_fwd_decl.hpp:62
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::object::as
std::enable_if< msgpack::has_as< T >::value, T >::type as() const
Get value as T.
Definition: object.hpp:593
adaptor_base.hpp
msgpack::object::with_zone::zone
msgpack::zone & zone
Definition: object.hpp:36
msgpack::object_array::ptr
msgpack::object * ptr
Definition: object_fwd.hpp:24
msgpack::packer::pack_array
packer< Stream > & pack_array(uint32_t n)
Packing array header and size.
Definition: pack.hpp:1160
msgpack
Definition: adaptor_base.hpp:15
versioning.hpp
msgpack::object::with_zone
Definition: object.hpp:34
msgpack::packer::pack
packer< Stream > & pack(const T &v)
Packing function template.
msgpack::adaptor::object_with_zone
Definition: adaptor_base.hpp:43
msgpack::type_error
Definition: object_fwd.hpp:236
msgpack::adaptor::pack
Definition: adaptor_base.hpp:32
msgpack::object::union_type::array
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::type::ARRAY
Definition: object_fwd_decl.hpp:41
MSGPACK_ZONE_ALIGNOF
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
msgpack::object::convert
msgpack::enable_if< !msgpack::is_array< T >::value &&!msgpack::is_pointer< T >::value, T &>::type convert(T &v) const
Convert the object.
Definition: object.hpp:543
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
msgpack::adaptor::convert
Definition: adaptor_base.hpp:27
msgpack::adaptor::as< std::pair< T1, T2 >, typename std::enable_if< msgpack::any_of< msgpack::has_as, T1, T2 >::value >::type >::operator()
std::pair< T1, T2 > operator()(msgpack::object const &o) const
Definition: pair.hpp:32
msgpack::adaptor::object_with_zone< std::pair< T1, T2 > >::operator()
void operator()(msgpack::object::with_zone &o, const std::pair< T1, T2 > &v) const
Definition: pair.hpp:65