blob: dfb1dfd83ce72c709089a3e1e468d9c8da9a8dff [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001// Copyright (C) 2005 Arkadiy Vertleyb
2// Copyright (C) 2005 Peder Holt
3//
4// Copyright (C) 2006 Tobias Schwinger
5//
6// Use, modification and distribution is subject to the Boost Software
7// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
8
Jeff Thompson3d613fd2013-10-15 15:39:04 -07009#ifndef NDNBOOST_TYPEOF_VECTOR_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -070010
11#include <ndnboost/mpl/int.hpp>
12#include <ndnboost/preprocessor/iteration/self.hpp>
13
Jeff Thompson3d613fd2013-10-15 15:39:04 -070014#ifndef NDNBOOST_TYPEOF_LIMIT_SIZE
15# define NDNBOOST_TYPEOF_LIMIT_SIZE 50
Jeff Thompsona28eed82013-08-22 16:21:10 -070016#endif
17
18//
19// To recreate the preprocessed versions of this file preprocess and run
20//
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021// $(NDNBOOST_ROOT)/libs/typeof/tools/preprocess.pl
Jeff Thompsona28eed82013-08-22 16:21:10 -070022//
23
Jeff Thompson3d613fd2013-10-15 15:39:04 -070024#if defined(NDNBOOST_TYPEOF_PP_INCLUDE_EXTERNAL)
Jeff Thompsona28eed82013-08-22 16:21:10 -070025
Jeff Thompson3d613fd2013-10-15 15:39:04 -070026# undef NDNBOOST_TYPEOF_PP_INCLUDE_EXTERNAL
Jeff Thompsona28eed82013-08-22 16:21:10 -070027
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028#elif !defined(NDNBOOST_TYPEOF_PREPROCESSING_MODE) && !NDNBOOST_PP_IS_SELFISH
Jeff Thompsona28eed82013-08-22 16:21:10 -070029
Jeff Thompson3d613fd2013-10-15 15:39:04 -070030# define NDNBOOST_PP_INDIRECT_SELF <ndnboost/typeof/vector.hpp>
31# if NDNBOOST_TYPEOF_LIMIT_SIZE < 50
32# include NDNBOOST_PP_INCLUDE_SELF()
33# elif NDNBOOST_TYPEOF_LIMIT_SIZE < 100
Jeff Thompsona28eed82013-08-22 16:21:10 -070034# include <ndnboost/typeof/vector50.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070035# define NDNBOOST_TYPEOF_PP_START_SIZE 51
36# include NDNBOOST_PP_INCLUDE_SELF()
37# elif NDNBOOST_TYPEOF_LIMIT_SIZE < 150
Jeff Thompsona28eed82013-08-22 16:21:10 -070038# include <ndnboost/typeof/vector100.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070039# define NDNBOOST_TYPEOF_PP_START_SIZE 101
40# include NDNBOOST_PP_INCLUDE_SELF()
41# elif NDNBOOST_TYPEOF_LIMIT_SIZE < 200
Jeff Thompsona28eed82013-08-22 16:21:10 -070042# include <ndnboost/typeof/vector150.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070043# define NDNBOOST_TYPEOF_PP_START_SIZE 151
44# include NDNBOOST_PP_INCLUDE_SELF()
45# elif NDNBOOST_TYPEOF_LIMIT_SIZE <= 250
Jeff Thompsona28eed82013-08-22 16:21:10 -070046# include <ndnboost/typeof/vector200.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047# define NDNBOOST_TYPEOF_PP_START_SIZE 201
48# include NDNBOOST_PP_INCLUDE_SELF()
Jeff Thompsona28eed82013-08-22 16:21:10 -070049# else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070050# error "NDNBOOST_TYPEOF_LIMIT_SIZE too high"
Jeff Thompsona28eed82013-08-22 16:21:10 -070051# endif
52
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053#else// defined(NDNBOOST_TYPEOF_PREPROCESSING_MODE) || NDNBOOST_PP_IS_SELFISH
Jeff Thompsona28eed82013-08-22 16:21:10 -070054
Jeff Thompson3d613fd2013-10-15 15:39:04 -070055# ifndef NDNBOOST_TYPEOF_PP_NEXT_SIZE
56# define NDNBOOST_TYPEOF_PP_NEXT_SIZE NDNBOOST_TYPEOF_LIMIT_SIZE
Jeff Thompsona28eed82013-08-22 16:21:10 -070057# endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070058# ifndef NDNBOOST_TYPEOF_PP_START_SIZE
59# define NDNBOOST_TYPEOF_PP_START_SIZE 0
Jeff Thompsona28eed82013-08-22 16:21:10 -070060# endif
61
Jeff Thompson3d613fd2013-10-15 15:39:04 -070062# if NDNBOOST_TYPEOF_PP_START_SIZE <= NDNBOOST_TYPEOF_LIMIT_SIZE
Jeff Thompsona28eed82013-08-22 16:21:10 -070063
64# include <ndnboost/preprocessor/enum_params.hpp>
65# include <ndnboost/preprocessor/repeat.hpp>
66# include <ndnboost/preprocessor/repeat_from_to.hpp>
67# include <ndnboost/preprocessor/cat.hpp>
68# include <ndnboost/preprocessor/inc.hpp>
69# include <ndnboost/preprocessor/dec.hpp>
70# include <ndnboost/preprocessor/comma_if.hpp>
71# include <ndnboost/preprocessor/iteration/local.hpp>
72# include <ndnboost/preprocessor/control/expr_iif.hpp>
73# include <ndnboost/preprocessor/logical/not.hpp>
74
75// iterator
76
Jeff Thompson3d613fd2013-10-15 15:39:04 -070077# define NDNBOOST_TYPEOF_spec_iter(n)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070078 template<class V>\
79 struct v_iter<V, mpl::int_<n> >\
80 {\
81 typedef typename V::item ## n type;\
82 typedef v_iter<V, mpl::int_<n + 1> > next;\
83 };
84
85namespace ndnboost { namespace type_of {
86
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087 template<class V, class Increase_NDNBOOST_TYPEOF_LIMIT_SIZE> struct v_iter; // not defined
88# define NDNBOOST_PP_LOCAL_MACRO NDNBOOST_TYPEOF_spec_iter
89# define NDNBOOST_PP_LOCAL_LIMITS \
90 (NDNBOOST_PP_DEC(NDNBOOST_TYPEOF_PP_START_SIZE), \
91 NDNBOOST_PP_DEC(NDNBOOST_TYPEOF_LIMIT_SIZE))
92# include NDNBOOST_PP_LOCAL_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -070093
94}}
95
Jeff Thompson3d613fd2013-10-15 15:39:04 -070096# undef NDNBOOST_TYPEOF_spec_iter
Jeff Thompsona28eed82013-08-22 16:21:10 -070097
98// vector
99
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700100# define NDNBOOST_TYPEOF_typedef_item(z, n, _)\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700101 typedef P ## n item ## n;
102
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700103# define NDNBOOST_TYPEOF_typedef_fake_item(z, n, _)\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700104 typedef mpl::int_<1> item ## n;
105
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700106# define NDNBOOST_TYPEOF_define_vector(n)\
107 template<NDNBOOST_PP_ENUM_PARAMS(n, class P) NDNBOOST_PP_EXPR_IIF(NDNBOOST_PP_NOT(n), class T = void)>\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700108 struct vector ## n\
109 {\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700110 typedef v_iter<vector ## n<NDNBOOST_PP_ENUM_PARAMS(n,P)>, ndnboost::mpl::int_<0> > begin;\
111 NDNBOOST_PP_REPEAT(n, NDNBOOST_TYPEOF_typedef_item, ~)\
112 NDNBOOST_PP_REPEAT_FROM_TO(n, NDNBOOST_TYPEOF_PP_NEXT_SIZE, NDNBOOST_TYPEOF_typedef_fake_item, ~)\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700113 };
114
115namespace ndnboost { namespace type_of {
116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117# define NDNBOOST_PP_LOCAL_MACRO NDNBOOST_TYPEOF_define_vector
118# define NDNBOOST_PP_LOCAL_LIMITS \
119 (NDNBOOST_TYPEOF_PP_START_SIZE,NDNBOOST_TYPEOF_LIMIT_SIZE)
120# include NDNBOOST_PP_LOCAL_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700121
122}}
123
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700124# undef NDNBOOST_TYPEOF_typedef_item
125# undef NDNBOOST_TYPEOF_typedef_fake_item
126# undef NDNBOOST_TYPEOF_define_vector
Jeff Thompsona28eed82013-08-22 16:21:10 -0700127
128// push_back
129
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700130# define NDNBOOST_TYPEOF_spec_push_back(n)\
131 template<NDNBOOST_PP_ENUM_PARAMS(n, class P) NDNBOOST_PP_COMMA_IF(n) class T>\
132 struct push_back<NDNBOOST_PP_CAT(ndnboost::type_of::vector, n)<NDNBOOST_PP_ENUM_PARAMS(n, P)>, T>\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700133 {\
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700134 typedef NDNBOOST_PP_CAT(ndnboost::type_of::vector, NDNBOOST_PP_INC(n))<\
135 NDNBOOST_PP_ENUM_PARAMS(n, P) NDNBOOST_PP_COMMA_IF(n) T\
Jeff Thompsona28eed82013-08-22 16:21:10 -0700136 > type;\
137 };
138
139namespace ndnboost { namespace type_of {
140
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700141# if NDNBOOST_TYPEOF_LIMIT_SIZE < 50
Jeff Thompsona28eed82013-08-22 16:21:10 -0700142 template<class V, class T> struct push_back {
143 typedef V type;
144 };
145# endif
146 //default behaviour is to let push_back ignore T, and return the input vector.
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700147 //This is to let NDNBOOST_TYPEOF_NESTED_TYPEDEF work properly with the default vector.
148# define NDNBOOST_PP_LOCAL_MACRO NDNBOOST_TYPEOF_spec_push_back
149# define NDNBOOST_PP_LOCAL_LIMITS \
150 (NDNBOOST_PP_DEC(NDNBOOST_TYPEOF_PP_START_SIZE), \
151 NDNBOOST_PP_DEC(NDNBOOST_TYPEOF_LIMIT_SIZE))
152# include NDNBOOST_PP_LOCAL_ITERATE()
Jeff Thompsona28eed82013-08-22 16:21:10 -0700153
154}}
155
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700156# undef NDNBOOST_TYPEOF_spec_push_back
Jeff Thompsona28eed82013-08-22 16:21:10 -0700157
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700158# endif//NDNBOOST_TYPEOF_PP_START_SIZE<=NDNBOOST_TYPEOF_LIMIT_SIZE
159# undef NDNBOOST_TYPEOF_PP_START_SIZE
160# undef NDNBOOST_TYPEOF_PP_NEXT_SIZE
Jeff Thompsona28eed82013-08-22 16:21:10 -0700161
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700162#endif//NDNBOOST_TYPEOF_PREPROCESSING_MODE || NDNBOOST_PP_IS_SELFISH
Jeff Thompsona28eed82013-08-22 16:21:10 -0700163
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700164#define NDNBOOST_TYPEOF_VECTOR_HPP_INCLUDED
165#endif//NDNBOOST_TYPEOF_VECTOR_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -0700166