31 #ifndef LUMIERA_VISITOR_DISPATCHER_H 32 #define LUMIERA_VISITOR_DISPATCHER_H 50 template<
class TOOL>
class Tag;
53 template<
class TOOL,
class TOOLImpl>
68 static size_t lastRegisteredID;
71 generateID (
size_t&
id)
75 id = ++lastRegisteredID;
80 operator size_t()
const {
return tagID; }
83 template<
class TOOLImpl>
85 get (TOOLImpl*
const =0)
88 if (!t) generateID (t.
tagID);
97 template<
class TOOL,
class TOOLImpl>
117 template<
class TAR,
class TOOL>
120 typedef typename TOOL::ReturnType ReturnType;
127 template<
class TOOLImpl>
133 TOOLImpl& toolObj =
static_cast<TOOLImpl&
> (tool);
138 return toolObj.treat (obj);
141 typedef ReturnType (*Trampoline) (TAR&, TOOL& );
149 accomodate (
size_t index)
152 if (index > table_.size())
153 table_.resize (index);
159 return id<=table_.size() && table_[
id-1];
163 storePtr (
size_t id, Trampoline func)
167 if (
id>table_.size())
173 storedTrampoline (
size_t id)
175 if (
id<=table_.size() && table_[
id-1])
178 return &errorHandler;
182 errorHandler (TAR& target, TOOL& tool)
184 return tool.onUnknown (target);
192 forwardCall (TAR& target, TOOL& tool)
196 return (*storedTrampoline(index)) (target, tool);
199 template<
class TOOLImpl>
201 enrol(TOOLImpl* typeref)
204 if (is_known (index))
208 Trampoline func = &callTrampoline<TOOLImpl>;
209 storePtr (index, func);
216 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.