2020
2121#include "msgpack/versioning.hpp"
2222#include "msgpack/object.hpp"
23+ #include "msgpack/adaptor/adaptor_base.hpp"
2324
2425namespace msgpack {
2526
@@ -31,7 +32,7 @@ namespace type {
3132// FIXME operator!=
3233<% GENERATION_LIMIT = 31 %>
3334
34- template <typename A0<% 1 . upto ( GENERATION_LIMIT +1 ) { |i |%> , typename A <%= i %> <% } %> >
35+ template <typename A0 = void <% 1 . upto ( GENERATION_LIMIT +1 ) { |i |%> , typename A <%= i %> = void <% } %> >
3536struct tuple;
3637
3738template < typename Tuple, int N >
@@ -136,81 +137,90 @@ inline tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<
136137
137138} // namespace type
138139
139- inline msgpack::object const& operator> > (
140+ namespace adaptor {
141+
142+ template < >
143+ struct convert< type::tuple < > > {
144+ msgpack::object const& operator()(
140145 msgpack::object const& o,
141- type::tuple< > &) {
142- if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
143- return o;
144- }
146+ type::tuple< > &) const {
147+ if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
148+ return o;
149+ }
150+ };
151+
145152<% 0 . upto ( GENERATION_LIMIT ) { |i |%>
146153template < typename A0<% 1 . upto ( i ) { |j |%> , typename A <%= j %> <% } %> >
147- inline msgpack::object const& operator> > (
154+ struct convert< type::tuple < A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > > {
155+ msgpack::object const& operator()(
148156 msgpack::object const& o,
149- type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) {
150- if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
151- if(o.via.array.size < <%= i +1%> ) { throw msgpack::type_error(); }
152- <% 0 . upto ( i ) { |j |%>
153- o.via.array.ptr[<%= j%> ].convert< typename type::tuple_type < A <%= j%> > ::type> (v.template get< <%= j %> > ());<% } %>
154- return o;
155- }
157+ type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) const {
158+ if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
159+ if(o.via.array.size < <%= i +1%> ) { throw msgpack::type_error(); }
160+ <% 0 . upto ( i ) { |j |%>
161+ // In order to avoid clang++'s invalid warning, msgpack::object:: has been added.
162+ o.via.array.ptr[<%= j%> ].msgpack::object::convert< typename type::tuple_type < A <%= j%> > ::type> (v.template get< <%= j %> > ());<% } %>
163+ return o;
164+ }
165+ };
156166<% } %>
157167
158- template < typename Stream >
159- inline const msgpack::packer< Stream > & operator< < (
168+ template < >
169+ struct pack< type::tuple < > > {
170+ template < typename Stream >
171+ msgpack::packer< Stream > & operator()(
160172 msgpack::packer< Stream > & o,
161- const type::tuple< > &) {
162- o.pack_array(0);
163- return o;
164- }
173+ const type::tuple< > &) const {
174+ o.pack_array(0);
175+ return o;
176+ }
177+ };
178+
165179<% 0 . upto ( GENERATION_LIMIT ) { |i |%>
166- template < typename Stream, typename A0<% 1 . upto ( i ) { |j |%> , typename A <%= j %> <% } %> >
167- inline const msgpack::packer< Stream > & operator< < (
180+ template < typename A0<% 1 . upto ( i ) { |j |%> , typename A <%= j %> <% } %> >
181+ struct pack< type::tuple < A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > > {
182+ template < typename Stream >
183+ msgpack::packer< Stream > & operator()(
168184 msgpack::packer< Stream > & o,
169- const type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) {
170- o.pack_array(<%= i +1%> );
171- <% 0 . upto ( i ) { |j |%>
172- o.pack(v.template get< <%= j %> > ());<% } %>
173- return o;
174- }
185+ const type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) const {
186+ o.pack_array(<%= i +1%> );
187+ <% 0 . upto ( i ) { |j |%>
188+ o.pack(v.template get< <%= j %> > ());<% } %>
189+ return o;
190+ }
191+ };
175192<% } %>
176193
177- inline void operator< < (
194+ template < >
195+ struct object_with_zone< type::tuple < > > {
196+ void operator()(
178197 msgpack::object::with_zone& o,
179- const type::tuple< > &) {
180- o.type = msgpack::type::ARRAY;
181- o.via.array.ptr = nullptr;
182- o.via.array.size = 0;
183- }
198+ const type::tuple< > &) const {
199+ o.type = msgpack::type::ARRAY;
200+ o.via.array.ptr = nullptr;
201+ o.via.array.size = 0;
202+ }
203+ };
204+
184205<% 0 . upto ( GENERATION_LIMIT ) { |i |%>
185206template < typename A0<% 1 . upto ( i ) { |j |%> , typename A <%= j %> <% } %> >
186- inline void operator< < (
207+ struct object_with_zone< type::tuple < A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > > {
208+ void operator()(
187209 msgpack::object::with_zone& o,
188- const type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) {
189- o.type = msgpack::type::ARRAY;
190- o.via.array.ptr = static_cast< msgpack::object * > (o.zone.allocate_align(sizeof(msgpack::object)*<%= i +1 %> ));
191- o.via.array.size = <%= i +1%> ;
192- <% 0 . upto ( i ) { |j |%>
193- o.via.array.ptr[<%= j%> ] = msgpack::object(v.template get< <%= j %> > (), o.zone);<% } %>
194- }
210+ const type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) const {
211+ o.type = msgpack::type::ARRAY;
212+ o.via.array.ptr = static_cast< msgpack::object * > (o.zone.allocate_align(sizeof(msgpack::object)*<%= i +1 %> ));
213+ o.via.array.size = <%= i +1%> ;
214+ <% 0 . upto ( i ) { |j |%>
215+ o.via.array.ptr[<%= j%> ] = msgpack::object(v.template get< <%= j %> > (), o.zone);<% } %>
216+ }
217+ };
195218<% } %>
196219
220+ } // namespace adaptor
221+
197222} // MSGPACK_API_VERSION_NAMESPACE(v1)
198223
199224} // namespace msgpack
200225
201-
202- //inline std::ostream& operator< < (std::ostream& o, const msgpack::type::tuple< > & v) {
203- // return o < < "[]";
204- //}
205- //<% 0 . upto ( GENERATION_LIMIT ) { |i |%>
206- //template < typename A0<% 1 . upto ( i ) { |j |%> , typename A <%= j %> <% } %> >
207- //inline std::ostream& operator< < (std::ostream& o,
208- // const msgpack::type::tuple< A0 <% 1 . upto ( i ) { |j |%> , A <%= j %> <% } %> > & v) {
209- // return o < < "["
210- // <% 0 . upto ( i ) { |j |%>
211- // < < <% if j != 0 then%> ", " < < <% end%> v.template get< <%= j %> > ()<% } %>
212- // < < "]";
213- //}
214- //<% } %>
215-
216226#endif // MSGPACK_CPP03_MSGPACK_TUPLE_HPP
0 commit comments