Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
typelist-diagnostics.hpp
Go to the documentation of this file.
1/*
2 TYPELIST-DIAGNOSTICS - helper for testing the typelist based utilities
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
29#ifndef META_TYPELIST_DIAGNOSTICS_H
30#define META_TYPELIST_DIAGNOSTICS_H
31
32
34#include "lib/meta/typelist.hpp"
36#include "lib/format-string.hpp"
37#include "lib/format-cout.hpp"
38#include "lib/meta/util.hpp"
39
40
41
42namespace lib {
43namespace meta {
44
45 using std::string;
46
47
49 struct Numz
50 {
52 Numz (uint x =0) : o_(x) { }
53 operator uint () const { return o_; }
54 };
55
56
60 template<int I>
61 struct Num : Numz
62 {
63 enum{ VAL=I };
64
65 Num (uint x = uint(I)) : Numz(x) { }
66 };
67
68
69
70 /* some forwards used by config-flags-test.cpp */
71 template<uint bit> struct Flag;
72 template< uint f1
73 , uint f2
74 , uint f3
75 , uint f4
76 , uint f5
77 >
78 struct Config;
79
80
81
83 template<class X> struct CountDown { using List = Nil; };
84 template<> struct CountDown<Num<0>> { using List = Node<Num<0>, Nil>; };
85 template<int I> struct CountDown<Num<I>> { using List = Node<Num<I>, typename CountDown<Num<I-1>>::List>; };
86
87
88
89
90 namespace test{ // unit tests covering typelist manipulating templates
91 namespace { // internals to support diagnostics in unit tests....
92
93
94 using util::_Fmt;
95
96 struct NullP
97 {
98 static string show() { return "-"; }
99 };
100
104 template<class T=Nil, class BASE=NullP>
105 struct Printer
106 : BASE
107 {
108 static string show() { return _Fmt("-<%s>%s") % typeStr<T>() % BASE::show(); }
109 };
110
111 template<class BASE>
112 struct Printer<Nil, BASE>
113 : BASE
114 {
115 static string show() { return _Fmt("-<%s>%s") % "·" % BASE::show(); }
116 };
117
118 template<class BASE, int I>
119 struct Printer<Num<I>, BASE>
120 : BASE
121 {
122 static string show() { return _Fmt("-<%u>%s") % uint(Num<I>::VAL) % BASE::show(); }
123 };
124
125 template<class BASE, uint Fl>
126 struct Printer<Flag<Fl>, BASE>
127 : BASE
128 {
129 static string show() { return _Fmt("-<%u>%s") % uint(Fl) % BASE::show(); }
130 };
131
132 template<class BASE>
133 struct Printer<int, BASE>
134 : BASE
135 {
136 static string show() { return _Fmt("-<%s>%s") % 'i' % BASE::show(); }
137 };
138
139
140
143 template<class LIST>
144 string
146 {
148 return PrinterChain::show();
149 }
150
152 template<class TY, class TYPES, class BASE>
153 struct Printer<Node<TY,TYPES>, BASE>
154 : BASE
155 {
156 static string show()
157 {
158 typedef Node<TY,TYPES> List;
159 return string("\n\t+--") + printSublist<List>()+"+"
160 + BASE::show();
161 }
162 };
163
164 template<uint f1, uint f2, uint f3, uint f4, uint f5, class BASE>
165 struct Printer<Config<f1,f2,f3,f4,f5>, BASE>
166 : BASE
167 {
168 static string show()
169 {
171 return string("\n\t+-Conf-[") + printSublist<FlagList>()+"]"
172 + BASE::show();
173 }
174 };
175
176 } // (End) internal defs
177
178
179
180 /* ===== printing types and contents ===== */
181
182 template<typename TYPES>
184 string >
185 showType ()
186 {
187 using TypeList = TYPES::List;
188 return printSublist<TypeList>();
189 }
190
191 // Note: we define further overloads of this function for other types, especially Tuples
192
193
194
195
196
197 /* ================= convenience macro notation ================= */
198
199#define DISPLAY(_IT_) \
200 cout << STRINGIFY(_IT_) << "\t:" << showType<_IT_>() << endl;
201
202#define DUMPVAL(_IT_) \
203 cout << STRINGIFY(_IT_) << "\t:" << util::toString(_IT_) << endl;
204
205#define EXPECT(_TY_, RENDERED_STRUCTURE ) \
206 CHECK (showType<_TY_>() == RENDERED_STRUCTURE ## _expect)
207
208
209}}} // namespace lib::meta::test
210#endif
A front-end for using printf-style formatting.
Automatically use custom string conversion in C++ stream output.
Front-end for printf-style string template interpolation.
Helpers for working with lib::meta::Types (i.e.
unsigned int uint
Definition integral.hpp:29
Simple and lightweight helpers for metaprogramming and type detection.
string printSublist()
call the debug-print for a typelist utilising the Printer template
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Node< Num< I >, typename CountDown< Num< I-1 > >::List > List
helper for generating test lists
»Empty« mark
Definition typelist.hpp:82
Type list with head and tail; T ≡ Nil marks list end.
Definition typelist.hpp:90
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
constant-wrapper type for debugging purposes, usable for generating lists of distinguishable types
dummy interface / baseclass for diagnostics
debugging template, printing the "number" used for instantiation on ctor call
A collection of frequently used helper functions to support unit testing.
A template metaprogramming technique for manipulating collections of types.