Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | // 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 6 | #ifndef NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED |
| 7 | #define NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 8 | |
| 9 | #include <ndnboost/preprocessor/logical/or.hpp> |
| 10 | #include <ndnboost/preprocessor/seq/fold_left.hpp> |
| 11 | #include <ndnboost/preprocessor/seq/enum.hpp> |
| 12 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 13 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 16 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 17 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM(Params)\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 18 | (TEMPLATE_PARAM)\ |
| 19 | (Params) |
| 20 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 21 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(This)\ |
| 22 | NDNBOOST_TYPEOF_TOSEQ(NDNBOOST_PP_SEQ_ELEM(1, This)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 23 | |
| 24 | //Encode / decode this |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 25 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 29 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 30 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 34 | |
| 35 | // template<class, unsigned int, ...> class |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 36 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM_EXPANDTYPE(This) \ |
| 37 | template <NDNBOOST_PP_SEQ_ENUM(NDNBOOST_TYPEOF_TEMPLATE_PARAM_GETPARAMS(This)) > class |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 38 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 39 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM_PLACEHOLDER(Param)\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 40 | Nested_Template_Template_Arguments_Not_Supported |
| 41 | |
| 42 | //'template<class,int> class' is reduced to 'class' |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 43 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM_DECLARATION_TYPE(Param) class |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 44 | |
| 45 | // T3<int, (unsigned int)0, ...> |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 46 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 49 | #define NDNBOOST_TYPEOF_TEMPLATE_PARAM_ISTEMPLATE 1 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 50 | |
| 51 | //////////////////////////// |
| 52 | // move to encode_decode? |
| 53 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 54 | NDNBOOST_TYPEOF_BEGIN_ENCODE_NS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 55 | |
| 56 | template<class V, class Type_Not_Registered_With_Typeof_System> struct encode_template_impl; |
| 57 | template<class T, class Iter> struct decode_template_impl; |
| 58 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 59 | NDNBOOST_TYPEOF_END_ENCODE_NS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 60 | |
| 61 | namespace ndnboost { namespace type_of { |
| 62 | |
| 63 | template<class V, class T> struct encode_template |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 64 | : NDNBOOST_TYPEOF_ENCODE_NS_QUALIFIER::encode_template_impl<V, T> |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 65 | {}; |
| 66 | |
| 67 | template<class Iter> struct decode_template |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 68 | : NDNBOOST_TYPEOF_ENCODE_NS_QUALIFIER::decode_template_impl<typename Iter::type, typename Iter::next> |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 69 | {}; |
| 70 | }} |
| 71 | |
| 72 | //////////////////////////// |
| 73 | // move to template_encoding.hpp? |
| 74 | |
| 75 | //Template template registration |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 76 | #define NDNBOOST_TYPEOF_REGISTER_TYPE_FOR_TEMPLATE_TEMPLATE(Name,Params,ID)\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 77 | template<class V\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 78 | NDNBOOST_TYPEOF_SEQ_ENUM_TRAILING(Params,NDNBOOST_TYPEOF_REGISTER_TEMPLATE_PARAM_PAIR)\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 79 | >\ |
| 80 | struct encode_template_impl<V,Name<\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 81 | NDNBOOST_PP_ENUM_PARAMS(\ |
| 82 | NDNBOOST_PP_SEQ_SIZE(Params),\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 83 | 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 89 | 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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 91 | typedef Iter iter;\ |
| 92 | }; |
| 93 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 94 | #define NDNBOOST_TYPEOF_TYPEDEF_INT_PN(z,n,Params) typedef int NDNBOOST_PP_CAT(P,n); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 95 | |
| 96 | #ifdef __BORLANDC__ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 97 | #define NDNBOOST_TYPEOF_DECODE_NESTED_TEMPLATE_HELPER_NAME NDNBOOST_PP_CAT(\ |
| 98 | NDNBOOST_PP_CAT(\ |
| 99 | NDNBOOST_PP_CAT(\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 100 | decode_nested_template_helper,\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 101 | NDNBOOST_TYPEOF_REGISTRATION_GROUP\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 102 | ),0x10000\ |
| 103 | ),__LINE__\ |
| 104 | ) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 105 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 108 | struct decode_params;\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 109 | 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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 111 | {\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 112 | typedef Name<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),T)> type;\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 113 | };\ |
| 114 | }; |
| 115 | //Template template param decoding |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 116 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 118 | |
| 119 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 120 | #define NDNBOOST_TYPEOF_REGISTER_DECODE_NESTED_TEMPLATE_HELPER_IMPL(Name,Params,ID) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 121 | |
| 122 | //Template template param decoding |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 123 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 125 | struct decode_params;\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 126 | 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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 128 | {\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 129 | typedef Name<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),T)> type;\ |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 130 | };\ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 131 | typedef typename decode_params<NDNBOOST_PP_ENUM_PARAMS(NDNBOOST_PP_SEQ_SIZE(Params),P)>::type type; |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 132 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 133 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 135 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 136 | // 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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 139 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 140 | #define NDNBOOST_TYPEOF_HAS_TEMPLATES_OP(s, state, elem)\ |
| 141 | NDNBOOST_PP_OR(state, NDNBOOST_TYPEOF_VIRTUAL(ISTEMPLATE, elem)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 142 | |
| 143 | //Define template template arguments |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 144 | #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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 148 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 149 | #endif //NDNBOOST_TYPEOF_TEMPLATE_TEMPLATE_PARAM_HPP_INCLUDED |