Lumiera  0.pre.03
»edit your freedom«
generator.hpp
Go to the documentation of this file.
1 /*
2  GENERATOR.hpp - metaprogramming utilities for generating classes and interfaces
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 This code is heavily inspired by
23  The Loki Library (loki-lib/trunk/include/loki/Sequence.h)
24  Copyright (c) 2001 by Andrei Alexandrescu
25  Copyright (c) 2005 by Peter Kümmel
26  This Loki code accompanies the book:
27  Alexandrescu, Andrei. "Modern C++ Design: Generic Programming
28  and Design Patterns Applied".
29  Copyright (c) 2001. Addison-Wesley. ISBN 0201704315
30 
31  Loki Copyright Notice:
32  Permission to use, copy, modify, distribute and sell this software for any
33  purpose is hereby granted without fee, provided that the above copyright
34  notice appear in all copies and that both that copyright notice and this
35  permission notice appear in supporting documentation.
36  The author makes no representations about the suitability of this software
37  for any purpose. It is provided "as is" without express or implied warranty.
38 */
39 
40 
59 #ifndef LIB_META_GENERATOR_H
60 #define LIB_META_GENERATOR_H
61 
62 #include "lib/meta/typelist.hpp"
63 
64 
65 
66 namespace lib {
67 namespace meta{
68 
75  template
76  < class TYPES // List of Types
77  , template<class> class _X_ // your-template-goes-here
78  , class BASE = NullType // Base class at end of chain
79  >
81 
82 
83  template<template<class> class _X_, class BASE>
84  class InstantiateForEach<NullType, _X_, BASE>
85  : public BASE
86  {
87  public:
88  typedef BASE Unit;
89  typedef NullType Next;
90  };
91 
92 
93  template
94  < class TY, typename TYPES
95  , template<class> class _X_
96  , class BASE
97  >
98  class InstantiateForEach<Node<TY, TYPES>, _X_, BASE>
99  : public _X_<TY>,
100  public InstantiateForEach<TYPES, _X_, BASE>
101  {
102  public:
103  typedef _X_<TY> Unit;
105  };
106 
107 
109  template<typename T>
110  struct InheritFrom : T
111  { };
112 
113 
114 
115 
124  template
125  < class TYPES // List of Types
126  , template<class,class> class _X_ // your-template-goes-here
127  , class BASE = NullType // Base class at end of chain
128  >
130 
131 
132  template<template<class,class> class _X_, class BASE>
133  class InstantiateChained<NullType, _X_, BASE>
134  : public BASE
135  {
136  public:
137  typedef BASE Unit;
138  typedef NullType Next;
139  };
140 
141 
142  template
143  < class TY, typename TYPES
144  , template<class,class> class _X_
145  , class BASE
146  >
147  class InstantiateChained<Node<TY, TYPES>, _X_, BASE>
148  : public _X_< TY
149  , InstantiateChained<TYPES, _X_, BASE>
150  >
151  {
152  public:
154  typedef _X_<TY,Next> Unit;
155  };
156 
157 
158 
168  template
169  < class TYPES // List of Types
170  , template<class,class,uint> class _X_ // your-template-goes-here
171  , class BASE = NullType // Base class at end of chain
172  , uint i = 0 // incremented on each instantiation
173  >
175 
176 
177  template< template<class,class,uint> class _X_
178  , class BASE
179  , uint i
180  >
181  class InstantiateWithIndex<NullType, _X_, BASE, i>
182  : public BASE
183  {
184  public:
185  typedef BASE Unit;
186  typedef NullType Next;
187  enum{ COUNT = i };
188  };
189 
190 
191  template
192  < class TY, typename TYPES
193  , template<class,class,uint> class _X_
194  , class BASE
195  , uint i
196  >
197  class InstantiateWithIndex<Node<TY, TYPES>, _X_, BASE, i>
198  : public _X_< TY
199  , InstantiateWithIndex<TYPES, _X_, BASE, i+1 >
200  , i
201  >
202  {
203  public:
205  typedef _X_<TY,Next,i> Unit;
206  enum{ COUNT = Next::COUNT };
207  };
208 
209 
210 }} // namespace lib::meta
211 #endif
A template metaprogramming technique for manipulating collections of types.
Apply a template to a collection of types.
Definition: generator.hpp:80
Implementation namespace for support and library code.
A Variation of InstantiateChained providing an incremented Index value template parameter.
Definition: generator.hpp:174
Helper to just inherit from the given type(s)
Definition: generator.hpp:110
Build a single inheritance chain of template instantiations.
Definition: generator.hpp:129