22 #ifndef LUMIERA_VISITOR_DISPATCHER_H 23 #define LUMIERA_VISITOR_DISPATCHER_H 41 template<
class TOOL>
class Tag;
44 template<
class TOOL,
class TOOLImpl>
59 static size_t lastRegisteredID;
62 generateID (
size_t&
id)
66 id = ++lastRegisteredID;
71 operator size_t()
const {
return tagID; }
74 template<
class TOOLImpl>
76 get (TOOLImpl*
const =0)
79 if (!t) generateID (t.
tagID);
88 template<
class TOOL,
class TOOLImpl>
108 template<
class TAR,
class TOOL>
111 typedef typename TOOL::ReturnType ReturnType;
118 template<
class TOOLImpl>
124 TOOLImpl& toolObj =
static_cast<TOOLImpl&
> (tool);
129 return toolObj.treat (obj);
132 typedef ReturnType (*Trampoline) (TAR&, TOOL& );
140 accomodate (
size_t index)
143 if (index > table_.size())
144 table_.resize (index);
150 return id<=table_.size() && table_[
id-1];
154 storePtr (
size_t id, Trampoline func)
158 if (
id>table_.size())
164 storedTrampoline (
size_t id)
166 if (
id<=table_.size() && table_[
id-1])
169 return &errorHandler;
173 errorHandler (TAR& target, TOOL& tool)
175 return tool.onUnknown (target);
183 forwardCall (TAR& target, TOOL& tool)
187 return (*storedTrampoline(index)) (target, tool);
190 template<
class TOOLImpl>
192 enrol(TOOLImpl* typeref)
195 if (is_known (index))
199 Trampoline func = &callTrampoline<TOOLImpl>;
200 storePtr (index, func);
207 template<
class TAR,
class TOOL>
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Access point to singletons and other kinds of dependencies designated by type.
Implementation namespace for support and library code.
static Tag< TOOL > tag
storage for the Tag registry for each concrete tool
static ReturnType callTrampoline(TAR &obj, TOOL &tool)
generator for Trampoline functions, used to dispatch calls down to the right "treat"-Function on the ...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A special implementation of lib::Sync, where the storage of the object monitor is associated directly...
Singleton services and Dependency Injection.
Lumiera error handling (C++ interface).
Type tag for concrete visiting tool classes.
A synchronisation protection guard employing a lock scoped to the parameter type as a whole...
For each possible call entry point via some subclass of the visitable hierarchy, we maintain a dispat...
static Depend< Dispatcher< TAR, TOOL > > instance
storage for the dispatcher table(s)
std::vector< Trampoline > table_
VTable for storing the Trampoline pointers.