85 #ifndef LIB_VERB_VISITOR_H 86 #define LIB_VERB_VISITOR_H 103 using JustSomeIrrelvantType =
struct{};
107 storageOverhead(
size_t argStorage)
109 return argStorage + VERB_TOKEN_SIZE;
115 template<
class REC,
class RET>
121 virtual RET applyTo (REC&) =0;
122 virtual Literal getID()
const =0;
124 bool operator== (
VerbInvoker const& o)
const {
return getID() == o.getID(); }
125 bool operator!= (
VerbInvoker const& o)
const {
return getID() != o.getID(); }
129 template<
class REC,
class SIG>
136 template<
class REC,
class RET,
typename... ARGS>
142 using Args = std::tuple<ARGS...>;
150 template<
typename...PARS>
152 : Verb{handlerRef, verbID}
153 , args_{std::forward<PARS> (args)...}
157 getID()
const override 159 return Verb::getID();
163 applyTo (REC& receiver)
override 170 template<
size_t...idx>
174 return (receiver.*Verb::handler_) (std::get<idx> (args_)...);
195 template<
class REC,
class RET,
size_t arg_storage>
197 :
public PolymorphicValue<VerbInvoker<REC,RET>, storageOverhead(arg_storage)>
202 template<
typename FUN>
205 static_assert (!
sizeof(FUN),
"handler must be a function member pointer for the given receiver");
207 template<
typename...ARGS>
214 template<
typename FUN>
226 template<
typename FUN,
typename...ARGS>
228 :
PolyHolder(PayloadType<FUN>(), handler, verbID,
std::forward<ARGS>(args)...)
239 return PolyHolder::getPayload().applyTo (receiver);
242 operator string()
const 245 +
string{util::unConst(
this)->getPayload().getID()}
250 template<
typename ARG>
255 REQUIRE (
INSTANCEOF (EmbeddedPayload, &this->getPayload()));
256 EmbeddedPayload& embedded =
static_cast<EmbeddedPayload&
>(this->getPayload());
257 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.