diff --git a/src/lib/verb-visitor.hpp b/src/lib/verb-visitor.hpp index ed04d1d58..3efb9512c 100644 --- a/src/lib/verb-visitor.hpp +++ b/src/lib/verb-visitor.hpp @@ -48,12 +48,15 @@ #define LIB_VERB_VISITOR_H +#include "lib/meta/variadic-helper.hpp" +#include "lib/polymorphic-value.hpp" #include "lib/symbol.hpp" #include "lib/util.hpp" #include #include #include +#include namespace lib { @@ -128,6 +131,79 @@ namespace lib { #define VERB(RECEIVER, FUN) VERB_##FUN (&RECEIVER::FUN, STRINGIFY(FUN)) + using JustSomeIrrelvantType = struct{}; + const size_t VERB_TOKEN_SIZE = sizeof(VerbToken); + + template + struct Hook + { + virtual ~Hook() { } + + virtual RET applyTo (REC&) =0; + }; + + template + struct Holder; + + template + struct Holder + : polyvalue::CopySupport< // mix-in virtual copy/move support + Hook> // ...the common interface to use + { + using Verb = VerbToken; + using Args = std::tuple; + + /** meta-sequence to pick argument values from the storage tuple */ + using SequenceIterator = typename meta::BuildIdxIter::Ascending; + + Verb verb_; + Args args_; + + Holder (typename Verb::Handler handlerRef, Literal verbID, ARGS... args) + : verb_{handlerRef, verbID} + , args_{std::forward (args)...} + { } + + RET + applyTo (REC& receiver) override + { + return invokeVerb (receiver, SequenceIterator()); + } + + template + RET + invokeVerb (REC& receiver, meta::IndexSeq) + { + return verb_.applyTo (receiver, std::get (args_)...); + } + }; + + static constexpr size_t + storageOverhead(size_t argStorage) + { + return argStorage + VERB_TOKEN_SIZE; + } + + + template + class VerbPack + : public PolymorphicValue, storageOverhead(arg_storage)> + { + using PolyHolder = PolymorphicValue, storageOverhead(arg_storage)>; + + template + using PayloadType = Holder*; + + template + using Handler = typename VerbToken::Handler; + + public: + template + VerbPack (Handler handler, Literal verbID, ARGS&&... args) + : PolyHolder(PayloadType(), handler, verbID, std::forward(args)...) + { } + }; + diff --git a/tests/library/verb-visitor-dispatch-test.cpp b/tests/library/verb-visitor-dispatch-test.cpp index 1fa5cb603..38426d729 100644 --- a/tests/library/verb-visitor-dispatch-test.cpp +++ b/tests/library/verb-visitor-dispatch-test.cpp @@ -27,6 +27,7 @@ #include "lib/test/run.hpp" +//#include "lib/verb-token.hpp" #include "lib/verb-visitor.hpp" #include "lib/format-string.hpp" #include "lib/format-cout.hpp" @@ -136,6 +137,10 @@ namespace test{ VerbSeq tokens = build_test_feed(); render_verbose (tokens); verify_dispatch (tokens); + + VerbPack woof(&Receiver::woof, "woof"); + +// profile.append_woof(1, 2); }