Lumiera  0.pre.03
»edit your freedom«
generator-test.cpp
Go to the documentation of this file.
1 /*
2  Generator(Test) - build an interface + implementation directed by a typelis
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 
40 #include "lib/test/run.hpp"
41 #include "lib/format-string.hpp"
42 #include "lib/meta/generator.hpp"
43 
44 #include <iostream>
45 #include <string>
46 
47 using util::_Fmt;
48 using std::string;
49 using std::cout;
50 
51 
52 namespace lib {
53 namespace meta {
54 namespace test {
55 
57  template<int I>
58  struct Block
59  {
60  static string name;
61  string talk() { return "__"+name+"__"; }
62  };
63 
64 
65 
66  template<int I>
67  string Block<I>::name = _Fmt("Block<%2i>") % I;
68 
69 
70 
72  template<class X>
73  class TakeIt
74  {
75  public:
76  virtual void eat (X& x) = 0;
77  virtual ~TakeIt() { }
78  };
79 
81  template<class X, class BASE>
82  class DoIt
83  : public BASE
84  {
85  protected:
86  DoIt () { cout << "ctor DoIt<"<< X::name << " >\n";}
87  virtual ~DoIt() { cout << "dtor DoIt<"<< X::name << " >\n";}
88  public:
89  void eat (X& x) { cout << "devouring" << x.talk() << "\n";}
90  using BASE::eat; // prevent shadowing
91  };
92 
93  typedef Types< Block<1>
94  , Block<2>
95  , Block<3>
96  , Block<5>
97  , Block<8>
98  , Block<13>
99  >::List TheTypes;
100 
102 
103 
104  struct BaseImpl : public TheInterface
105  {
106  void eat() { cout << "gulp!\n"; }
107  };
108 
110 
111 
112  /*********************************************************************/
118  class TypeListGenerator_test : public Test
119  {
120  virtual void
121  run (Arg)
122  {
123  NumberBabbler me_can_has_more_numberz;
124 
125  CHECK (INSTANCEOF (TheInterface, &me_can_has_more_numberz));
126 
127  TheTypes::Tail::Head b2; // Block<2>
128  TheTypes::Tail::Tail::Tail::Head b5; // Block<5>
129  TheTypes::Tail::Tail::Tail::Tail::Tail::Head b13; // Block<13>
130 
131  me_can_has_more_numberz.eat (b2);
132  me_can_has_more_numberz.eat (b5);
133 
134  TakeIt<Block<13>>& subInterface = me_can_has_more_numberz;
135 
136  subInterface.eat (b13);
137  me_can_has_more_numberz.eat();
138 
139  INFO (test, "SizeOf = %zu", sizeof(me_can_has_more_numberz));
140  }
141  };
142 
143 
145  LAUNCHER (TypeListGenerator_test, "unit common");
146 
147 
148 
149 }}} // namespace lib::meta::test
Definition: run.hpp:49
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition: util.hpp:492
Front-end for printf-style string template interpolation.
Apply a template to a collection of types.
Definition: generator.hpp:80
Helpers for working with lib::meta::Types (i.e.
template for generating lots of different test types
A front-end for using printf-style formatting.
Use this building block for assembling an abstract interface.
Implementation namespace for support and library code.
Simple test class runner.
Build a single inheritance chain of template instantiations.
Definition: generator.hpp:129
Use this building block for chaining corresponding implementation classes.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption