Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
34
35#include <iostream>
36#include <string>
37
38using util::_Fmt;
39using std::string;
40using std::cout;
41
42// GCC > 13 warns at class definition when a new overload shadows an inherited virtual function.
43// While theoretically correct, this warning is besides the point when an interface is assembled
44// by metaprogramming from a chain of template instantiations, driven by a type list
45// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740
46_Pragma("GCC diagnostic push") \
47_Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"")
48
49
50namespace lib {
51namespace meta {
52namespace test {
53
55 template<int I>
56 struct Block
57 {
58 static string name;
59 string talk() { return "__"+name+"__"; }
60 };
61
62
63
64 template<int I>
65 string Block<I>::name = _Fmt("Block<%2i>") % I;
66
67
68
70 template<class X>
71 class TakeIt
72 {
73 public:
74 virtual void eat (X& x) = 0;
75 virtual ~TakeIt() { }
76 };
77
79 template<class X, class BASE>
80 class DoIt
81 : public BASE
82 {
83 protected:
84 DoIt () { cout << "ctor DoIt<"<< X::name << " >\n";}
85 virtual ~DoIt() { cout << "dtor DoIt<"<< X::name << " >\n";}
86 public:
87 void eat (X& x) { cout << "devouring" << x.talk() << "\n";}
88 using BASE::eat; // prevent shadowing
89 };
90
91 using TheTypes = Types< Block<1>
92 , Block<2>
93 , Block<3>
94 , Block<5>
95 , Block<8>
96 , Block<13>
97 >::List;
98
99 typedef InstantiateForEach<TheTypes,TakeIt> TheInterface;
100
101
102 struct BaseImpl : public TheInterface
103 {
104 void eat() { cout << "gulp!\n"; }
105 };
106
107 typedef InstantiateChained<TheTypes,DoIt, BaseImpl> NumberBabbler;
108
109
110 /*********************************************************************/
116 class TypeListGenerator_test : public Test
117 {
118 virtual void
119 run (Arg)
120 {
121 NumberBabbler me_can_has_more_numberz;
122
123 CHECK (INSTANCEOF (TheInterface, &me_can_has_more_numberz));
124
125 TheTypes::Tail::Head b2; // Block<2>
126 TheTypes::Tail::Tail::Tail::Head b5; // Block<5>
127 TheTypes::Tail::Tail::Tail::Tail::Tail::Head b13; // Block<13>
128
129 me_can_has_more_numberz.eat (b2);
130 me_can_has_more_numberz.eat (b5);
131
132 TakeIt<Block<13>>& subInterface = me_can_has_more_numberz;
133
134 subInterface.eat (b13);
135 me_can_has_more_numberz.eat();
136
137 INFO (test, "SizeOf = %zu", sizeof(me_can_has_more_numberz));
138 }
139 };
140
141
143 LAUNCHER (TypeListGenerator_test, "unit common");
144
145
146
147}}} // namespace lib::meta::test
A front-end for using printf-style formatting.
Front-end for printf-style string template interpolation.
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Woverloaded-virtual\"") namespace lib
Helpers for working with lib::meta::Types (i.e.
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition util.hpp:514