59 namespace visitor_concept_draft {
65 template<
class TOOL>
class Tag;
68 template<
class TOOL,
class TOOLImpl>
79 static size_t lastRegisteredID;
83 operator size_t()
const {
return tagID; }
86 template<
class TOOLImpl>
88 get (TOOLImpl*
const =0)
93 t.tagID = ++lastRegisteredID;
102 template<
class TOOL,
class TOOLImpl>
114 template<
typename RET>
118 typedef RET ReturnType;
130 template<
class TOOLImpl,
class BASE =Tool<
void>>
134 typedef typename BASE::ToolBase ToolBase;
140 TOOLImpl* typeKey = 0;
153 template<
class TAR,
class TOOL>
156 typedef typename TOOL::ReturnType ReturnType;
163 template<
class TOOLImpl>
169 TOOLImpl& toolObj =
static_cast<TOOLImpl&
> (tool);
174 return toolObj.treat (obj);
177 typedef ReturnType (*Trampoline) (TAR&, TOOL& );
187 return id<=table_.size() && table_[
id-1];
191 storePtr (
size_t id, Trampoline func)
194 if (
id>table_.size())
200 storedTrampoline (
size_t id)
202 if (
id<=table_.size() && table_[
id-1])
205 return &errorHandler;
209 errorHandler (TAR&, TOOL&)
211 cout <<
"Error Handler: unregistered combination of (Tool, TargetObject) invoked!\n";
219 forwardCall (TAR& target, TOOL& tool)
223 return (*storedTrampoline(index)) (target, tool);
226 template<
class TOOLImpl>
228 enrol (TOOLImpl* typeKey)
231 if (is_known (index))
235 Trampoline func = &callTrampoline<TOOLImpl>;
236 storePtr (index, func);
243 template<
class TAR,
class TOOL>
255 template<
class TAR,
class TOOLImpl,
class BASE=Tool<
void> >
258 typedef typename BASE::ReturnType Ret;
259 typedef typename BASE::ToolBase ToolBase;
264 TOOLImpl* typeKey = 0;
292 typedef typename TOOL::ToolBase
ToolBase;
293 typedef typename TOOL::ReturnType ReturnType;
301 static inline ReturnType
310 virtual ReturnType apply (TOOL&) = 0;
318 #define DEFINE_PROCESSABLE_BY(TOOL) \ 319 virtual ReturnType apply (TOOL& tool) \ 320 { return dispatchOp (*this, tool); } 331 typedef Tool<void> VisitingTool;
361 :
public VisitingTool
364 void talk_to (
string guy)
366 cout <<
_Fmt{
"Hello %s, nice to meet you...\n"} % guy;
375 public ToolType<Babbler, VerboseVisitor>
378 void treat (
Boss&) { talk_to(
"Boss"); }
379 void treat (
BigBoss&) { talk_to(
"Big Boss"); }
402 virtual void run(Arg)
404 known_visitor_known_class();
405 visitor_not_visiting_some_class();
408 void known_visitor_known_class()
417 cout <<
"=== Babbler meets Boss and BigBoss ===\n";
419 VisitingTool& vista (bab);
424 void visitor_not_visiting_some_class()
432 cout <<
"=== Babbler meets HomoSapiens and Visionary ===\n";
434 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)
Simplistic 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)