37 using std::make_tuple;
51 virtual string woof (
bool huge, uint cnt) =0;
52 virtual string honk (
string) =0;
53 virtual string moo (
size_t num) =0;
54 virtual string meh () =0;
59 using TokenSeq = vector<Token>;
70 woof (
bool huge, uint cnt)
override 74 woof += isnil(woof)?
string {huge?
"Woof..":
"haw-haw"}
79 honk (
string theHonk)
override 81 return theHonk+
"-"+theHonk+
"!";
84 moo (
size_t num)
override 86 return join (vector<string>{num,
"Moo"},
"__");
101 string woof (
bool huge, uint cnt)
override {
return report(
"woof", huge, cnt); }
102 string honk (
string theHonk)
override {
return report(
"honk", theHonk); }
103 string moo (
size_t num)
override {
return report(
"moo", num); }
104 string meh()
override {
return report(
"meh"); }
106 template<
typename...ARGS>
108 report (
Literal func, ARGS&&...args)
111 + meta::dump (make_tuple (forward<ARGS>(args)...));
135 TokenSeq tokens = build_and_copy_tokens();
136 apply_VerboseRenderer (tokens);
137 apply_different_receivers (tokens);
138 verify_copy_and_equality (tokens);
148 Token littleWoof(&Receiver::woof,
"woof", 0, 3);
149 Token bigWoof(&Receiver::woof,
"woof",
true, 2);
150 Token quack(&Receiver::honk,
"honk",
"quaack");
151 Token honk(&Receiver::honk,
"honk",
"Hoonk");
152 Token moo(&Receiver::moo,
"moo", 3);
153 Token meh(&Receiver::meh,
"meh");
155 CHECK (
sizeof(Token) ==
sizeof(
string)
157 +
sizeof(
void(Receiver::*)())
162 return TokenSeq{{littleWoof, quack, honk, bigWoof, moo, meh}};
173 VerboseRenderer receiver;
174 for (Token& tok : tokens)
175 cout <<
"dispatching " << tok
177 << tok.applyTo(receiver)
190 VerboseRenderer verbose;
191 DiagnosticRenderer diagnostic;
192 auto render = [&](Receiver& renderer)
195 .transform ([&](Token tok)
197 return tok.applyTo (renderer);
202 CHECK (
render(diagnostic) ==
"woof(false,3)-honk(quaack)-honk(Hoonk)-woof(true,2)-moo(3)-meh()");
203 CHECK (
render(verbose) ==
"haw-hawhaw-hawhaw-hawhaw-haw-quaack-quaack!-Hoonk-Hoonk!-Woof..Woof..-Moo__Moo__Moo-Meh?");
208 verify_copy_and_equality (TokenSeq& tokens)
210 Token bigWoof = tokens[3];
211 Token oldWoof{&Receiver::woof,
"woof",
true, 1};
212 Token oldWolf{&Receiver::woof,
"wolf",
true, 0};
214 CHECK (bigWoof == oldWoof);
215 CHECK (bigWoof != oldWolf);
217 CHECK (not util::isSameObject (bigWoof, oldWoof));
218 CHECK (
string(bigWoof) ==
"VerbPack(woof)");
219 CHECK (
string(oldWoof) ==
"VerbPack(woof)");
220 CHECK (
string(oldWolf) ==
"VerbPack(wolf)");
222 VerboseRenderer bark;
223 CHECK (bigWoof.applyTo(bark) ==
"Woof..Woof..");
224 CHECK (oldWoof.applyTo(bark) ==
"Woof..");
225 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)
Simplistic 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