68 namespace visitor_concept_draft {
74 template<
class TOOL>
class Tag;
77 template<
class TOOL,
class TOOLImpl>
88 static size_t lastRegisteredID;
92 operator size_t()
const {
return tagID; }
95 template<
class TOOLImpl>
97 get (TOOLImpl*
const =0)
102 t.tagID = ++lastRegisteredID;
111 template<
class TOOL,
class TOOLImpl>
123 template<
typename RET>
127 typedef RET ReturnType;
139 template<
class TOOLImpl,
class BASE =Tool<
void>>
143 typedef typename BASE::ToolBase ToolBase;
149 TOOLImpl* typeKey = 0;
162 template<
class TAR,
class TOOL>
165 typedef typename TOOL::ReturnType ReturnType;
172 template<
class TOOLImpl>
178 TOOLImpl& toolObj =
static_cast<TOOLImpl&
> (tool);
183 return toolObj.treat (obj);
186 typedef ReturnType (*Trampoline) (TAR&, TOOL& );
196 return id<=table_.size() && table_[
id-1];
200 storePtr (
size_t id, Trampoline func)
203 if (
id>table_.size())
209 storedTrampoline (
size_t id)
211 if (
id<=table_.size() && table_[
id-1])
214 return &errorHandler;
218 errorHandler (TAR&, TOOL&)
220 cout <<
"Error Handler: unregistered combination of (Tool, TargetObject) invoked!\n";
228 forwardCall (TAR& target, TOOL& tool)
232 return (*storedTrampoline(index)) (target, tool);
235 template<
class TOOLImpl>
237 enrol (TOOLImpl* typeKey)
240 if (is_known (index))
244 Trampoline func = &callTrampoline<TOOLImpl>;
245 storePtr (index, func);
252 template<
class TAR,
class TOOL>
264 template<
class TAR,
class TOOLImpl,
class BASE=Tool<
void> >
267 typedef typename BASE::ReturnType Ret;
268 typedef typename BASE::ToolBase ToolBase;
273 TOOLImpl* typeKey = 0;
301 typedef typename TOOL::ToolBase
ToolBase;
302 typedef typename TOOL::ReturnType ReturnType;
310 static inline ReturnType
319 virtual ReturnType apply (TOOL&) = 0;
327 #define DEFINE_PROCESSABLE_BY(TOOL) \ 328 virtual ReturnType apply (TOOL& tool) \ 329 { return dispatchOp (*this, tool); } 340 typedef Tool<void> VisitingTool;
370 :
public VisitingTool
373 void talk_to (
string guy)
375 cout <<
_Fmt{
"Hello %s, nice to meet you...\n"} % guy;
384 public ToolType<Babbler, VerboseVisitor>
387 void treat (
Boss&) { talk_to(
"Boss"); }
388 void treat (
BigBoss&) { talk_to(
"Big Boss"); }
411 virtual void run(Arg)
413 known_visitor_known_class();
414 visitor_not_visiting_some_class();
417 void known_visitor_known_class()
426 cout <<
"=== Babbler meets Boss and BigBoss ===\n";
428 VisitingTool& vista (bab);
433 void visitor_not_visiting_some_class()
441 cout <<
"=== Babbler meets HomoSapiens and Visionary ===\n";
443 VisitingTool& vista (bab);
any concrete visiting tool implementation has to inherit from this class for each kind of calls it wa...
virtual ReturnType apply(TOOL &)=0
to be defined by the DEFINE_PROCESSABLE_BY macro in all classes wanting to be treated by some tool ...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
static Tag< TOOL > tag
storage for the Tag registry for each concrete tool
A front-end for using printf-style formatting.
Access point to singletons and other kinds of dependencies designated by type.
static ReturnType callTrampoline(TAR &obj, TOOL &tool)
generator for Trampoline functions, used to dispatch calls down to the right "treat"-Function on the ...
std::vector< Trampoline > table_
custom VTable for storing the Trampoline pointers
static lib::Depend< Dispatcher< TAR, TOOL > > instance
storage for the dispatcher table(s)
Simple test class runner.
For each possible call entry point via some subclass of the visitable hierarchy, we maintain a dispat...
Singleton services and Dependency Injection.
Lumiera public interface.
Marker interface "visitable object".
static ReturnType dispatchOp(TAR &target, TOOL &tool)