76 #ifndef LIB_VERB_VISITOR_H 77 #define LIB_VERB_VISITOR_H 94 using JustSomeIrrelvantType =
struct{};
98 storageOverhead(
size_t argStorage)
100 return argStorage + VERB_TOKEN_SIZE;
106 template<
class REC,
class RET>
112 virtual RET applyTo (REC&) =0;
113 virtual Literal getID()
const =0;
115 bool operator== (
VerbInvoker const& o)
const {
return getID() == o.getID(); }
116 bool operator!= (
VerbInvoker const& o)
const {
return getID() != o.getID(); }
120 template<
class REC,
class SIG>
127 template<
class REC,
class RET,
typename... ARGS>
133 using Args = std::tuple<ARGS...>;
141 template<
typename...PARS>
143 : Verb{handlerRef, verbID}
144 , args_{std::forward<PARS> (args)...}
148 getID()
const override 150 return Verb::getID();
154 applyTo (REC& receiver)
override 161 template<
size_t...idx>
165 return (receiver.*Verb::handler_) (std::get<idx> (args_)...);
186 template<
class REC,
class RET,
size_t arg_storage>
188 :
public PolymorphicValue<VerbInvoker<REC,RET>, storageOverhead(arg_storage)>
193 template<
typename FUN>
196 static_assert (!
sizeof(FUN),
"handler must be a function member pointer for the given receiver");
198 template<
typename...ARGS>
205 template<
typename FUN>
217 template<
typename FUN,
typename...ARGS>
219 :
PolyHolder(PayloadType<FUN>(), handler, verbID,
std::forward<ARGS>(args)...)
230 return PolyHolder::getPayload().applyTo (receiver);
233 operator string()
const 236 +
string{util::unConst(
this)->getPayload().getID()}
241 template<
typename ARG>
246 REQUIRE (
INSTANCEOF (EmbeddedPayload, &this->getPayload()));
247 EmbeddedPayload& embedded =
static_cast<EmbeddedPayload&
>(this->getPayload());
248 return std::get<0> (embedded.args_);
Action token implemented by double dispatch to a handler function, as defined in the "receiver" inter...
Building block: actual storage for a "verb" (function pointer), together with the pre-bound invocatio...
ARG & accessArg()
unsafe downcast and access to an embedded payload argument value
Building block: the Interface to cause the invocation.
Building blocks for a simple DSL using double dispatch to a handler function.
A self-contained token to embody a specific yet abstracted operation, together with a concrete set of...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
inline string literal This is a marker type to indicate that
A variation for limited copy support.
A mechanism to allow for opaque polymorphic value objects.
Implementation namespace for support and library code.
Marker types to indicate a literal string and a Symbol.
Template to build polymorphic value objects.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
RET invokeVerb(REC &receiver, meta::IndexSeq< idx... >)
RET applyTo(REC &receiver)
Core operation: invoke the operation for this "verb" with the pre-bound parameters.
typename meta::BuildIdxIter< ARGS... >::Ascending SequenceIterator
meta-sequence to pick argument values from the storage tuple
VerbPack(FUN handler, Literal verbID, ARGS &&... args)
setup a VerbPack for a given operation on the interface REC
Args args_
Storage for the argument tuple.
Metaprogramming with type sequences based on variadic template parameters.