/* VerbVisitorDispatch(Test) - Setup to dispatch to arbitrary functions on a receiver interface Copyright (C) Lumiera.org 2019, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ /** @file verb-visitor-dispatch-test.cpp ** Demonstrate the extended concept of a _verb language_ based on double dispatch. ** @see body-canvas-widget.hpp */ #include "lib/test/run.hpp" #include "lib/verb-visitor.hpp" #include "lib/format-string.hpp" #include "lib/format-cout.hpp" #include "lib/format-util.hpp" #include #include using std::string; using util::_Fmt; using util::join; using std::vector; namespace lib { namespace test{ ///////////////////////////TODO : Debugging struct Trackr { size_t num; Trackr (size_t val) : num(val) { cout <<"Trackr("<; using TokenSeq = vector; } /** * a receiver of verb-tokens, * which renders them verbosely */ class VerboseRenderer : public Receiver { string woof (bool huge, uint cnt) override { string woof{huge? "Woof..":"haw-haw"}; while (0 < cnt--) woof += woof; return woof; } string honk (string theHonk) override { return theHonk+"-"+theHonk+"!"; } string moo (Trackr num) override { return join (vector{num.num, "Moo"}, "__"); } string meh() override { return "Meh!"; } }; #define SHOW_TYPE(_TY_) \ cout << "typeof( " << STRINGIFY(_TY_) << " )= " << lib::meta::typeStr<_TY_>() < '" << tok.applyTo(receiver) << "'\n"; } }; /** Register this test class... */ LAUNCHER (VerbVisitorDispatch_test, "unit common"); }} // namespace lib::test