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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 ====================================================================
13 This code is heavily inspired by
14  The Loki Library (loki-lib/trunk/include/loki/Sequence.h)
15  Copyright (c) 2001 by Andrei Alexandrescu
16  Copyright (c) 2005 by Peter Kümmel
17  This Loki code accompanies the book:
18  Alexandrescu, Andrei. "Modern C++ Design: Generic Programming
19  and Design Patterns Applied".
20  Copyright (c) 2001. Addison-Wesley. ISBN 0201704315
21 
22  Loki Copyright Notice:
23  Permission to use, copy, modify, distribute and sell this software for any
24  purpose is hereby granted without fee, provided that the above copyright
25  notice appear in all copies and that both that copyright notice and this
26  permission notice appear in supporting documentation.
27  The author makes no representations about the suitability of this software
28  for any purpose. It is provided "as is" without express or implied warranty.
29 */
30 
31 
50 #ifndef LIB_META_GENERATOR_H
51 #define LIB_META_GENERATOR_H
52 
53 #include "lib/meta/typelist.hpp"
54 
55 
56 
57 namespace lib {
58 namespace meta{
59 
66  template
67  < class TYPES // List of Types
68  , template<class> class _X_ // your-template-goes-here
69  , class BASE = NullType // Base class at end of chain
70  >
72 
73 
74  template<template<class> class _X_, class BASE>
75  class InstantiateForEach<NullType, _X_, BASE>
76  : public BASE
77  {
78  public:
79  typedef BASE Unit;
80  typedef NullType Next;
81  };
82 
83 
84  template
85  < class TY, typename TYPES
86  , template<class> class _X_
87  , class BASE
88  >
89  class InstantiateForEach<Node<TY, TYPES>, _X_, BASE>
90  : public _X_<TY>,
91  public InstantiateForEach<TYPES, _X_, BASE>
92  {
93  public:
94  typedef _X_<TY> Unit;
96  };
97 
98 
100  template<typename T>
101  struct InheritFrom : T
102  { };
103 
104 
105 
106 
115  template
116  < class TYPES // List of Types
117  , template<class,class> class _X_ // your-template-goes-here
118  , class BASE = NullType // Base class at end of chain
119  >
121 
122 
123  template<template<class,class> class _X_, class BASE>
124  class InstantiateChained<NullType, _X_, BASE>
125  : public BASE
126  {
127  public:
128  typedef BASE Unit;
129  typedef NullType Next;
130  };
131 
132 
133  template
134  < class TY, typename TYPES
135  , template<class,class> class _X_
136  , class BASE
137  >
138  class InstantiateChained<Node<TY, TYPES>, _X_, BASE>
139  : public _X_< TY
140  , InstantiateChained<TYPES, _X_, BASE>
141  >
142  {
143  public:
145  typedef _X_<TY,Next> Unit;
146  };
147 
148 
149 
159  template
160  < class TYPES // List of Types
161  , template<class,class,uint> class _X_ // your-template-goes-here
162  , class BASE = NullType // Base class at end of chain
163  , uint i = 0 // incremented on each instantiation
164  >
166 
167 
168  template< template<class,class,uint> class _X_
169  , class BASE
170  , uint i
171  >
172  class InstantiateWithIndex<NullType, _X_, BASE, i>
173  : public BASE
174  {
175  public:
176  typedef BASE Unit;
177  typedef NullType Next;
178  enum{ COUNT = i };
179  };
180 
181 
182  template
183  < class TY, typename TYPES
184  , template<class,class,uint> class _X_
185  , class BASE
186  , uint i
187  >
188  class InstantiateWithIndex<Node<TY, TYPES>, _X_, BASE, i>
189  : public _X_< TY
190  , InstantiateWithIndex<TYPES, _X_, BASE, i+1 >
191  , i
192  >
193  {
194  public:
196  typedef _X_<TY,Next,i> Unit;
197  enum{ COUNT = Next::COUNT };
198  };
199 
200 
201 }} // namespace lib::meta
202 #endif
A template metaprogramming technique for manipulating collections of types.
Apply a template to a collection of types.
Definition: generator.hpp:71
Implementation namespace for support and library code.
A Variation of InstantiateChained providing an incremented Index value template parameter.
Definition: generator.hpp:165
Helper to just inherit from the given type(s)
Definition: generator.hpp:101
Build a single inheritance chain of template instantiations.
Definition: generator.hpp:120