46 using std::make_tuple;
60 virtual string woof (
bool huge, uint cnt) =0;
61 virtual string honk (
string) =0;
62 virtual string moo (
size_t num) =0;
63 virtual string meh () =0;
68 using TokenSeq = vector<Token>;
79 woof (
bool huge, uint cnt)
override 83 woof += isnil(woof)?
string {huge?
"Woof..":
"haw-haw"}
88 honk (
string theHonk)
override 90 return theHonk+
"-"+theHonk+
"!";
93 moo (
size_t num)
override 95 return join (vector<string>{num,
"Moo"},
"__");
110 string woof (
bool huge, uint cnt)
override {
return report(
"woof", huge, cnt); }
111 string honk (
string theHonk)
override {
return report(
"honk", theHonk); }
112 string moo (
size_t num)
override {
return report(
"moo", num); }
113 string meh()
override {
return report(
"meh"); }
115 template<
typename...ARGS>
117 report (
Literal func, ARGS&&...args)
120 + meta::dump (make_tuple (forward<ARGS>(args)...));
144 TokenSeq tokens = build_and_copy_tokens();
145 apply_VerboseRenderer (tokens);
146 apply_different_receivers (tokens);
147 verify_copy_and_equality (tokens);
157 Token littleWoof(&Receiver::woof,
"woof", 0, 3);
158 Token bigWoof(&Receiver::woof,
"woof",
true, 2);
159 Token quack(&Receiver::honk,
"honk",
"quaack");
160 Token honk(&Receiver::honk,
"honk",
"Hoonk");
161 Token moo(&Receiver::moo,
"moo", 3);
162 Token meh(&Receiver::meh,
"meh");
164 CHECK (
sizeof(Token) ==
sizeof(
string)
166 +
sizeof(
void(Receiver::*)())
171 return TokenSeq{{littleWoof, quack, honk, bigWoof, moo, meh}};
182 VerboseRenderer receiver;
183 for (Token& tok : tokens)
184 cout <<
"dispatching " << tok
186 << tok.applyTo(receiver)
199 VerboseRenderer verbose;
200 DiagnosticRenderer diagnostic;
201 auto render = [&](Receiver& renderer)
204 .transform ([&](Token tok)
206 return tok.applyTo (renderer);
211 CHECK (
render(diagnostic) ==
"woof(false,3)-honk(quaack)-honk(Hoonk)-woof(true,2)-moo(3)-meh()");
212 CHECK (
render(verbose) ==
"haw-hawhaw-hawhaw-hawhaw-haw-quaack-quaack!-Hoonk-Hoonk!-Woof..Woof..-Moo__Moo__Moo-Meh?");
217 verify_copy_and_equality (TokenSeq& tokens)
219 Token bigWoof = tokens[3];
220 Token oldWoof{&Receiver::woof,
"woof",
true, 1};
221 Token oldWolf{&Receiver::woof,
"wolf",
true, 0};
223 CHECK (bigWoof == oldWoof);
224 CHECK (bigWoof != oldWolf);
226 CHECK (not util::isSameObject (bigWoof, oldWoof));
227 CHECK (
string(bigWoof) ==
"VerbPack(woof)");
228 CHECK (
string(oldWoof) ==
"VerbPack(woof)");
229 CHECK (
string(oldWolf) ==
"VerbPack(wolf)");
231 VerboseRenderer bark;
232 CHECK (bigWoof.applyTo(bark) ==
"Woof..Woof..");
233 CHECK (oldWoof.applyTo(bark) ==
"Woof..");
234 CHECK (oldWolf.applyTo(bark) ==
"");
string render(DataCap const &)
void apply_different_receivers(TokenSeq &tokens)
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
a concrete receiver of verb-tokens, which renders them verbosely
A self-contained token to embody a specific yet abstracted operation, together with a concrete set of...
inline string literal This is a marker type to indicate that
A front-end for using printf-style formatting.
Implementation namespace for support and library code.
Metaprogramming with tuples-of-types and the std::tuple record.
void apply_VerboseRenderer(TokenSeq &tokens)
Simple test class runner.
A specific double dispatch variation for function invocation.
another concrete receiver to report any invocation with arguments
Building tree expanding and backtracking evaluations within hierarchical scopes.
virtual ~Receiver()
this is an interface
TokenSeq build_and_copy_tokens()
the "visitor" interface used by all VerbPacks in this test