Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
configflags.hpp
Go to the documentation of this file.
1 /*
2  CONFIGFLAGS.hpp - Building classes based on configuration cases
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
48 #ifndef LIB_META_CONFIGFLAGS_H
49 #define LIB_META_CONFIGFLAGS_H
50 
51 
52 #include "lib/meta/typelist.hpp"
53 
54 
55 namespace lib {
56 namespace meta{
57 
58  const size_t CONFIG_FLAGS_MAX = 5;
59 
60 
61  template<uint bit> struct Flag { typedef Flag ID; };
62  template<> struct Flag<0> { typedef NullType ID; };
63 
64 
65  template< uint f1=0
66  , uint f2=0
67  , uint f3=0
68  , uint f4=0
69  , uint f5=0
70  >
71  struct Flags
72  {
73  typedef typename Types< typename Flag<f1>::ID
74  , typename Flag<f2>::ID
75  , typename Flag<f3>::ID
76  , typename Flag<f4>::ID
77  , typename Flag<f5>::ID
78  >::List
80  typedef Tuple List;
81  };
82 
83 
84  template< uint f1=0
85  , uint f2=0
86  , uint f3=0
87  , uint f4=0
88  , uint f5=0
89  >
90  struct Config
91  {
93  typedef Flags List;
94  };
95 
96 
97 
98  template<uint Fl, class CONF>
99  struct ConfigSetFlag;
100 
101  template< uint Fl
102  , uint f1
103  , uint f2
104  , uint f3
105  , uint f4
106  , uint IGN
107  >
108  struct ConfigSetFlag<Fl, Config<f1,f2,f3,f4,IGN>>
109  {
111  };
112 
113 
114 
116  template<class FLAGS, class CONF=Config<> >
118  {
119  typedef CONF Config;
120  typedef Config Type;
121  };
122  template<uint Fl, class FLAGS, class CONF>
123  struct BuildConfigFromFlags< Node<Flag<Fl>,FLAGS>, CONF>
124  {
125  typedef typename ConfigSetFlag< Fl
128  typedef Config Type;
129  };
130 
132  template<class FLAGS>
134 
135 
136  namespace {
138  template<uint ii, uint jj>
139  struct maxC
140  {
141  enum{ VAL = ii < jj? jj : ii };
142  };
143  }
144 
145 
157  template<class FLAGS>
158  struct FlagInfo;
159 
160  template<uint ff, class FLAGS>
161  struct FlagInfo<Node<Flag<ff>, FLAGS>>
162  {
163  enum{ BITS = maxC< ff, FlagInfo<FLAGS>::BITS> ::VAL
164  , CODE = (1<<ff) | FlagInfo<FLAGS>::CODE
165  };
166  };
167 
168  template<>
170  {
171  enum{ BITS = 0
172  , CODE = 0
173  };
174 
175  template<class FUNC>
176  static typename FUNC::Ret
177  accept (FUNC& functor)
178  {
179  return functor.done();
180  }
181  };
182 
183  template<class CONF, class TAIL>
184  struct FlagInfo<Node<CONF, TAIL>>
185  {
186  typedef typename CONF::Flags ThisFlags;
187  enum{
188  BITS = maxC< FlagInfo<ThisFlags>::BITS, FlagInfo<TAIL>::BITS > ::VAL
189  };
190 
191  template<class FUNC>
192  static typename FUNC::Ret
193  accept (FUNC& functor)
194  {
195  functor.template visit<CONF>(FlagInfo<ThisFlags>::CODE);
196  return FlagInfo<TAIL>::accept (functor);
197  }
198  };
199 
200 
201 
202 }} // namespace lib::meta
203 #endif
A template metaprogramming technique for manipulating collections of types.
const size_t CONFIG_FLAGS_MAX
Definition: configflags.hpp:58
static FUNC::Ret accept(FUNC &functor)
Implementation namespace for support and library code.
Types< typename Flag< f1 >::ID, typename Flag< f2 >::ID, typename Flag< f3 >::ID, typename Flag< f4 >::ID, typename Flag< f5 >::ID >::List Tuple
Definition: configflags.hpp:79
Flags< f1, f2, f3, f4, f5 >::Tuple Flags
Definition: configflags.hpp:92
< distinct type representing a configuration
Definition: configflags.hpp:90
static FUNC::Ret accept(FUNC &functor)
build a configuration type from a list-of-flags
ConfigSetFlag< Fl, typename BuildConfigFromFlags< FLAGS, CONF >::Config >::Config Config
create a configuration type for the given list-of-flags
Helper for calculating values and for invoking runtime code based on a given FlagTuple.