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)
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 
14 
31 #include "lib/test/run.hpp"
32 #include "lib/format-string.hpp"
33 #include "lib/meta/generator.hpp"
34 
35 #include <iostream>
36 #include <string>
37 
38 using util::_Fmt;
39 using std::string;
40 using std::cout;
41 
42 
43 namespace lib {
44 namespace meta {
45 namespace test {
46 
48  template<int I>
49  struct Block
50  {
51  static string name;
52  string talk() { return "__"+name+"__"; }
53  };
54 
55 
56 
57  template<int I>
58  string Block<I>::name = _Fmt("Block<%2i>") % I;
59 
60 
61 
63  template<class X>
64  class TakeIt
65  {
66  public:
67  virtual void eat (X& x) = 0;
68  virtual ~TakeIt() { }
69  };
70 
72  template<class X, class BASE>
73  class DoIt
74  : public BASE
75  {
76  protected:
77  DoIt () { cout << "ctor DoIt<"<< X::name << " >\n";}
78  virtual ~DoIt() { cout << "dtor DoIt<"<< X::name << " >\n";}
79  public:
80  void eat (X& x) { cout << "devouring" << x.talk() << "\n";}
81  using BASE::eat; // prevent shadowing
82  };
83 
84  typedef Types< Block<1>
85  , Block<2>
86  , Block<3>
87  , Block<5>
88  , Block<8>
89  , Block<13>
90  >::List TheTypes;
91 
93 
94 
95  struct BaseImpl : public TheInterface
96  {
97  void eat() { cout << "gulp!\n"; }
98  };
99 
101 
102 
103  /*********************************************************************/
109  class TypeListGenerator_test : public Test
110  {
111  virtual void
112  run (Arg)
113  {
114  NumberBabbler me_can_has_more_numberz;
115 
116  CHECK (INSTANCEOF (TheInterface, &me_can_has_more_numberz));
117 
118  TheTypes::Tail::Head b2; // Block<2>
119  TheTypes::Tail::Tail::Tail::Head b5; // Block<5>
120  TheTypes::Tail::Tail::Tail::Tail::Tail::Head b13; // Block<13>
121 
122  me_can_has_more_numberz.eat (b2);
123  me_can_has_more_numberz.eat (b5);
124 
125  TakeIt<Block<13>>& subInterface = me_can_has_more_numberz;
126 
127  subInterface.eat (b13);
128  me_can_has_more_numberz.eat();
129 
130  INFO (test, "SizeOf = %zu", sizeof(me_can_has_more_numberz));
131  }
132  };
133 
134 
136  LAUNCHER (TypeListGenerator_test, "unit common");
137 
138 
139 
140 }}} // namespace lib::meta::test
Definition: run.hpp:40
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition: util.hpp:514
Front-end for printf-style string template interpolation.
Apply a template to a collection of types.
Definition: generator.hpp:71
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.
Simplistic test class runner.
Build a single inheritance chain of template instantiations.
Definition: generator.hpp:120
Use this building block for chaining corresponding implementation classes.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption