blob: d0802b773c989db655bd47f355e240e91224b531 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001// Copyright (C) 2005 Peder Holt
2// Copyright (C) 2005 Arkadiy Vertleyb
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
Jeff Thompson3d613fd2013-10-15 15:39:04 -07006#ifndef NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED
7#define NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07008
9#include <ndnboost/preprocessor/logical/or.hpp>
10#include <ndnboost/preprocessor/seq/fold_left.hpp>
11#include <ndnboost/preprocessor/seq/enum.hpp>
12
Jeff Thompson3d613fd2013-10-15 15:39:04 -070013#define NDNBOOST_TYPEOF_MAKE_OBJ_template(x) NDNBOOST_TYPEOF_TEMPLATE_PARAM(x)
14#define NDNBOOST_TYPEOF_TEMPLATE(X) template(X) NDNBOOST_TYPEOF_EAT
15#define NDNBOOST_TYPEOF_template(X) (template(X))
Jeff Thompsona28eed82013-08-22 16:21:10 -070016
Jeff Thompson3d613fd2013-10-15 15:39:04 -070017#define NDNBOOST_TYPEOF_TEMPLATE_PARAM(Params)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070018 (TEMPLATE_PARAM)\
19 (Params)
20
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(This)\
22 NDNBOOST_TYPEOF_TOSEQ(NDNBOOST_PP_SEQ_ELEM(1, This))
Jeff Thompsona28eed82013-08-22 16:21:10 -070023
24//Encode / decode this
Jeff Thompson3d613fd2013-10-15 15:39:04 -070025#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_ENCODE(This, n)\
26 typedef typename ndnboost::type_of::encode_template<NDNBOOST_PP_CAT(V, n),\
27 NDNBOOST_PP_CAT(P, n)<NDNBOOST_TYPEOF_SEQ_ENUM(NDNBOOST_TYPEOF_MAKE_OBJS(NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(This)),NDNBOOST_TYPEOF_PLACEHOLDER) >\
28 >::type NDNBOOST_PP_CAT(V, NDNBOOST_PP_INC(n));
Jeff Thompsona28eed82013-08-22 16:21:10 -070029
Jeff Thompson3d613fd2013-10-15 15:39:04 -070030#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_DECODE(This, n)\
31 typedef ndnboost::type_of::decode_template< NDNBOOST_PP_CAT(iter, n) > NDNBOOST_PP_CAT(d, n);\
32 typedef typename NDNBOOST_PP_CAT(d, n)::type NDNBOOST_PP_CAT(P, n);\
33 typedef typename NDNBOOST_PP_CAT(d, n)::iter NDNBOOST_PP_CAT(iter,NDNBOOST_PP_INC(n));
Jeff Thompsona28eed82013-08-22 16:21:10 -070034
35// template<class, unsigned int, ...> class
Jeff Thompson3d613fd2013-10-15 15:39:04 -070036#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_EXPANDTYPE(This) \
37 template <NDNBOOST_PP_SEQ_ENUM(NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(This)) > class
Jeff Thompsona28eed82013-08-22 16:21:10 -070038
Jeff Thompson3d613fd2013-10-15 15:39:04 -070039#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_PLACEHOLDER(Param)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070040 Nested_Template_Template_Arguments_Not_Supported
41
42//'template<class,int> class' is reduced to 'class'
Jeff Thompson3d613fd2013-10-15 15:39:04 -070043#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_DECLARATION_TYPE(Param) class
Jeff Thompsona28eed82013-08-22 16:21:10 -070044
45// T3<int, (unsigned int)0, ...>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_PLACEHOLDER_TYPES(Param, n)\
47 NDNBOOST_PP_CAT(T,n)<NDNBOOST_TYPEOF_SEQ_ENUM_1(NDNBOOST_TYPEOF_MAKE_OBJS(NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(Param)),NDNBOOST_TYPEOF_PLACEHOLDER) >
Jeff Thompsona28eed82013-08-22 16:21:10 -070048
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049#define NDNBOOST_TYPEOF_TEMPLATE_PARAM_ISTEMPLATE 1
Jeff Thompsona28eed82013-08-22 16:21:10 -070050
51////////////////////////////
52// move to encode_decode?
53
Jeff Thompson3d613fd2013-10-15 15:39:04 -070054NDNBOOST_TYPEOF_BEGIN_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -070055
56template<class V, class Type_Not_Registered_With_Typeof_System> struct encode_template_impl;
57template<class T, class Iter> struct decode_template_impl;
58
Jeff Thompson3d613fd2013-10-15 15:39:04 -070059NDNBOOST_TYPEOF_END_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -070060
61namespace ndnboost { namespace type_of {
62
63 template<class V, class T> struct encode_template
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064 : NDNBOOST_TYPEOF_ENCODE_NS_QUALIFIER::encode_template_impl<V, T>
Jeff Thompsona28eed82013-08-22 16:21:10 -070065 {};
66
67 template<class Iter> struct decode_template
Jeff Thompson3d613fd2013-10-15 15:39:04 -070068 : NDNBOOST_TYPEOF_ENCODE_NS_QUALIFIER::decode_template_impl<typename Iter::type, typename Iter::next>
Jeff Thompsona28eed82013-08-22 16:21:10 -070069 {};
70}}
71
72////////////////////////////
73// move to template_encoding.hpp?
74
75//Template template registration
Jeff Thompson3d613fd2013-10-15 15:39:04 -070076#define NDNBOOST_TYPEOF_REGISTER_TYPE_FOR_TEMPLATE_TEMPLATE(Name,Params,ID)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070077 template<class V\
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078 NDNBOOST_TYPEOF_SEQ_ENUM_TRAILING(Params,NDNBOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_PAIR)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070079 >\
80 struct encode_template_impl<V,Name<\
Jeff Thompson3d613fd2013-10-15 15:39:04 -070081 NDNBOOST_PP_ENUM_PARAMS(\
82 NDNBOOST_PP_SEQ_SIZE(Params),\
Jeff Thompsona28eed82013-08-22 16:21:10 -070083 P)> >\
84 : ndnboost::type_of::push_back<V, ndnboost::mpl::size_t<ID> >\
85 {\
86 };\
87 template<class Iter> struct decode_template_impl<ndnboost::mpl::size_t<ID>, Iter>\
88 {\
Jeff Thompson3d613fd2013-10-15 15:39:04 -070089 NDNBOOST_PP_REPEAT(NDNBOOST_PP_SEQ_SIZE(Params),NDNBOOST_TYPEOF_TYPEDEF_INT_PN,_)\
90 typedef Name<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_PLACEHOLDER) > type;\
Jeff Thompsona28eed82013-08-22 16:21:10 -070091 typedef Iter iter;\
92 };
93
Jeff Thompson3d613fd2013-10-15 15:39:04 -070094#define NDNBOOST_TYPEOF_TYPEDEF_INT_PN(z,n,Params) typedef int NDNBOOST_PP_CAT(P,n);
Jeff Thompsona28eed82013-08-22 16:21:10 -070095
96#ifdef __BORLANDC__
Jeff Thompson3d613fd2013-10-15 15:39:04 -070097#define NDNBOOST_TYPEOF_DECODE_NESTED_TEMPLATE_HELPER_NAME NDNBOOST_PP_CAT(\
98 NDNBOOST_PP_CAT(\
99 NDNBOOST_PP_CAT(\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700100 decode_nested_template_helper,\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700101 NDNBOOST_TYPEOF_REGISTRATION_GROUP\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700102 ),0x10000\
103 ),__LINE__\
104 )
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105#define NDNBOOST_TYPEOF_REGISTER_DECODE_NESTED_TEMPLATE_HELPER_IMPL(Name,Params,ID)\
106 struct NDNBOOST_TYPEOF_DECODE_NESTED_TEMPLATE_HELPER_NAME {\
107 template<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_REGISTER_DECLARE_DECODER_TYPE_PARAM_PAIR) >\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700108 struct decode_params;\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700109 template<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_REGISTER_DECODER_TYPE_PARAM_PAIR) >\
110 struct decode_params<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_PLACEHOLDER_TYPES) >\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700111 {\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112 typedef Name<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),T)> type;\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700113 };\
114 };
115//Template template param decoding
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700116#define NDNBOOST_TYPEOF_TYPEDEF_DECODED_TEMPLATE_TEMPLATE_TYPE(Name,Params)\
117 typedef typename NDNBOOST_TYPEOF_DECODE_NESTED_TEMPLATE_HELPER_NAME::decode_params<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),P)>::type type;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700118
119#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700120#define NDNBOOST_TYPEOF_REGISTER_DECODE_NESTED_TEMPLATE_HELPER_IMPL(Name,Params,ID)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700121
122//Template template param decoding
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700123#define NDNBOOST_TYPEOF_TYPEDEF_DECODED_TEMPLATE_TEMPLATE_TYPE(Name,Params)\
124 template<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_REGISTER_DECLARE_DECODER_TYPE_PARAM_PAIR) >\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700125 struct decode_params;\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700126 template<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_REGISTER_DECODER_TYPE_PARAM_PAIR) >\
127 struct decode_params<NDNBOOST_TYPEOF_SEQ_ENUM(Params,NDNBOOST_TYPEOF_PLACEHOLDER_TYPES) >\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700128 {\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700129 typedef Name<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),T)> type;\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700130 };\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700131 typedef typename decode_params<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),P)>::type type;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700132#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700133#define NDNBOOST_TYPEOF_REGISTER_DECLARE_DECODER_TYPE_PARAM_PAIR(z,n,elem) \
134 NDNBOOST_TYPEOF_VIRTUAL(DECLARATION_TYPE, elem)(elem) NDNBOOST_PP_CAT(T, n)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700135
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700136// NDNBOOST_TYPEOF_HAS_TEMPLATES
137#define NDNBOOST_TYPEOF_HAS_TEMPLATES(Params)\
138 NDNBOOST_PP_SEQ_FOLD_LEFT(NDNBOOST_TYPEOF_HAS_TEMPLATES_OP, 0, Params)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700139
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700140#define NDNBOOST_TYPEOF_HAS_TEMPLATES_OP(s, state, elem)\
141 NDNBOOST_PP_OR(state, NDNBOOST_TYPEOF_VIRTUAL(ISTEMPLATE, elem))
Jeff Thompsona28eed82013-08-22 16:21:10 -0700142
143//Define template template arguments
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700144#define NDNBOOST_TYPEOF_REGISTER_TEMPLATE_TEMPLATE_IMPL(Name,Params,ID)\
145 NDNBOOST_PP_IF(NDNBOOST_TYPEOF_HAS_TEMPLATES(Params),\
146 NDNBOOST_TYPEOF_REGISTER_DECODE_NESTED_TEMPLATE_HELPER_IMPL,\
147 NDNBOOST_TYPEOF_REGISTER_TYPE_FOR_TEMPLATE_TEMPLATE)(Name,Params,ID)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700148
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700149#endif //NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED