// // MessagePack for C++ static resolution routine // // Copyright (C) 2008-2009 FURUHASHI Sadayuki // // 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 MSGPACK_TYPE_DEFINE_HPP__ #define MSGPACK_TYPE_DEFINE_HPP__ #define MSGPACK_DEFINE(...) \ template \ void msgpack_pack(Packer& pk) const \ { \ msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \ } \ void msgpack_unpack(msgpack::object o) \ { \ msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \ } namespace msgpack { namespace type { <% GENERATION_LIMIT = 15 %> template , typename A<%=i%> = void<%}%>> struct define; template <> struct define<> { typedef define<> value_type; typedef tuple<> tuple_type; template void msgpack_pack(Packer& pk) const { pk.pack_array(1); } void msgpack_unpack(msgpack::object o) { if(o.type != type::ARRAY) { throw type_error(); } } }; <%0.upto(GENERATION_LIMIT) {|i|%> template , typename A<%=j%><%}%>> struct define, A<%=j%><%}%>> { typedef define, A<%=j%><%}%>> value_type; typedef tuple, A<%=j%><%}%>> tuple_type; define(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) : a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {} template void msgpack_pack(Packer& pk) const { pk.pack_array(<%=i+1%>); <%0.upto(i) {|j|%> pk.pack(a<%=j%>);<%}%> } void msgpack_unpack(msgpack::object o) { if(o.type != type::ARRAY) { throw type_error(); } const size_t size = o.via.array.size; <%0.upto(i) {|j|%> if(size <= <%=j%>) { return; } o.via.array.ptr[<%=j%>].convert(&a<%=j%>);<%}%> } <%0.upto(i) {|j|%> A<%=j%>& a<%=j%>;<%}%> }; <%}%> inline define<> make_define() { return define<>(); } <%0.upto(GENERATION_LIMIT) {|i|%> template , typename A<%=j%><%}%>> define, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>) { return define, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>); } <%}%> } // namespace type } // namespace msgpack #endif /* msgpack/type/define.hpp */