size_equal_only.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2016 KONDO Takatoshi
//
// 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_SIZE_EQUAL_ONLY_HPP
#define MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
#include "msgpack/v1/adaptor/size_equal_only_decl.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename T>
inline std::size_t size(T const& t) {
return t.size();
}
template <typename T, std::size_t N>
inline std::size_t size(const T(&)[N]) {
return N;
}
#if !defined(MSGPACK_USE_CPP03)
template <typename... T>
inline std::size_t size(std::tuple<T...> const&) {
return sizeof...(T);
}
#endif // !defined(MSGPACK_USE_CPP03)
template <typename T>
struct size_equal_only {
size_equal_only(T& t):m_t(t) {}
T& m_t;
};
template <typename T>
inline size_equal_only<T> make_size_equal_only(T& t) {
return size_equal_only<T>(t);
}
template <typename T>
inline bool operator<(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
return lhs.m_t < rhs.m_t;
}
template <typename T>
inline bool operator==(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
return lhs.m_t == &rhs.m_t;
}
} // namespace type
namespace adaptor {
template <typename T>
struct convert<type::size_equal_only<T> > {
msgpack::object const& operator()(msgpack::object const& o, type::size_equal_only<T>& v) const {
switch(o.type) {
case msgpack::type::ARRAY:
if (o.via.array.size != msgpack::type::size(v.m_t)) throw msgpack::type_error();
break;
case msgpack::type::MAP:
if (o.via.map.size != msgpack::type::size(v.m_t)) throw msgpack::type_error();
break;
default:
throw msgpack::type_error();
}
o >> v.m_t;
return o;
}
};
template <typename T>
struct pack<type::size_equal_only<T> > {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::size_equal_only<T>& v) const {
o << v.m_t;
return o;
}
};
template <typename T>
struct object<type::size_equal_only<T> > {
void operator()(msgpack::object& o, type::size_equal_only<T> const& v) const {
o << v.m_t;
}
};
template <typename T>
struct object_with_zone<type::size_equal_only<T> > {
void operator()(msgpack::object::with_zone& o, type::size_equal_only<T> v) const {
o << v.m_t;
}
};
} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
msgpack::object_array::size
uint32_t size
Definition: object_fwd.hpp:23
msgpack::type::size_equal_only::size_equal_only
size_equal_only(T &t)
Definition: size_equal_only.hpp:46
msgpack::adaptor::object_with_zone< type::size_equal_only< T > >::operator()
void operator()(msgpack::object::with_zone &o, type::size_equal_only< T > v) const
Definition: size_equal_only.hpp:105
size_equal_only_decl.hpp
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::type::make_size_equal_only
size_equal_only< T > make_size_equal_only(T &t)
Definition: size_equal_only.hpp:51
msgpack
Definition: adaptor_base.hpp:15
msgpack::object::with_zone
Definition: object.hpp:34
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::type::size
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
msgpack::adaptor::convert< type::size_equal_only< T > >::operator()
msgpack::object const & operator()(msgpack::object const &o, type::size_equal_only< T > &v) const
Definition: size_equal_only.hpp:71
msgpack::object::union_type::array
msgpack::object_array array
Definition: object_fwd.hpp:85
msgpack::object::union_type::map
msgpack::object_map map
Definition: object_fwd.hpp:86
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::object_map::size
uint32_t size
Definition: object_fwd.hpp:28
msgpack::type::MAP
Definition: object_fwd_decl.hpp:42
msgpack::type::operator==
bool operator==(nil_t const &lhs, nil_t const &rhs)
Definition: nil.hpp:29
msgpack::adaptor::object< type::size_equal_only< T > >::operator()
void operator()(msgpack::object &o, type::size_equal_only< T > const &v) const
Definition: size_equal_only.hpp:98
msgpack::adaptor::object
Definition: adaptor_base.hpp:38
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
msgpack::type::size_equal_only
Definition: size_equal_only.hpp:45
msgpack::type::size_equal_only::m_t
T & m_t
Definition: size_equal_only.hpp:47
msgpack::adaptor::convert
Definition: adaptor_base.hpp:27
msgpack::adaptor::pack< type::size_equal_only< T > >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::size_equal_only< T > &v) const
Definition: size_equal_only.hpp:90