Lumiera  0.pre.03
»edit your freedom«
buildertool.hpp
Go to the documentation of this file.
1 /*
2  BUILDERTOOL.hpp - Interface, (visiting) tool for processing MObjects
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
43 #ifndef MOBJECT_BUILDER_TOOL_H
44 #define MOBJECT_BUILDER_TOOL_H
45 
46 #include "lib/visitor.hpp"
47 #include "lib/wrapperptr.hpp"
48 
49 #include "lib/p.hpp"
52 
53 
54 namespace steam {
55 namespace mobject {
56 
57  class Buildable;
58 
59  namespace builder {
60 
61 
67  template<class RET>
69  {
70  protected:
71  virtual ~InvokeCatchAllFunction() {}
72  public:
73  virtual RET onUnknown (Buildable& target) = 0;
74  };
75 
76 
77 
98  : public lib::visitor::Tool<void, InvokeCatchAllFunction>
99  { lumiera::WrapperPtr currentWrapper_;
100 
101  public:
102 
103  template<template<class> class WRA, class TAR>
104  void rememberWrapper (WRA<TAR>* ptr_toWrappedTarget)
105  {
106  currentWrapper_ = ptr_toWrappedTarget;
107  }
108  template<template<class,class> class Placement, class TAR, class B>
109  void rememberWrapper (Placement<TAR,B>* ptr_toWrappedTarget)
110  {
111  currentWrapper_ = ptr_toWrappedTarget;
112  }
113 
114  void forgetWrapper ()
115  {
116  currentWrapper_.reset();
117  }
118 
119 
120  protected: /* == interface for accessing the wrapper from within tool application == */
121 
122  template<class TAR>
124  getPlacement ()
125  {
126  Placement<TAR>* pPlacement = currentWrapper_.get<Placement<TAR>*>();
127  ENSURE (pPlacement, "wrong target type when invoking %s", __PRETTY_FUNCTION__);
128  return *pPlacement;
129  }
130 
132  getExplicitPlacement ()
133  {
134  return getPlacement<MObject>().resolve();
135  }
136 
137  template<class TAR>
139  getPtr ()
140  {
141  lib::P<TAR>* pP = currentWrapper_.get<lib::P<TAR>*>();
142  ENSURE (pP, "wrong target type when invoking %s", __PRETTY_FUNCTION__);
143  return *pP;
144  }
145  };
146 
147 
148 
153  template
154  < class TOOLImpl, // concrete BuilderTool implementation
155  class TYPELIST // list of all concrete Buildables to be treated
156  >
158  : public lib::visitor::Applicable<TOOLImpl, TYPELIST, BuilderTool>
159  { }
160  ;
161 
162  using lib::meta::Types; // convenience for the users of "Applicable"
163 
164  }// namespace mobject::builder
165 
166 
167 
168 
169 
173  class Buildable : public lib::visitor::Visitable<builder::BuilderTool>
174  { };
175 
176 
177 
178 
179  namespace builder {
180 
188  template<typename WRA>
189  inline Buildable::ReturnType
190  apply (BuilderTool& tool, WRA& wrappedTargetObj)
191  {
192  tool.rememberWrapper(&wrappedTargetObj);
193  wrappedTargetObj->apply (tool); // dispatch to suitable treat() function
194  tool.forgetWrapper();
195  }
196 
197 
198 }}} // namespace steam::mobject::builder
199 #endif
Wrapper to treat several flavours of smart-pointers uniformly.
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:82
Marker Interface for classes visitable by Builder tools.
Marker template to declare that some "visiting tool" wants to treat a set of concrete Visitable class...
Definition: visitor.hpp:135
Marker interface or base class for all "Visitables".
Definition: visitor.hpp:188
Core abstraction: completely resolved placement of an MObject Within the session model, all media objects are attached with the help of mobject::Placement elements.
Core abstraction: placement of a media object into session context.
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
declare the concrete types a BuilderTool may receive and treat.
Customised refcounting smart pointer.
Base class of all BuilderTools, used according to the visitor pattern: each Tool contains the concret...
Definition: buildertool.hpp:97
Steam-Layer implementation namespace root.
Marker interface / base class for all "visiting tools".
Definition: visitor.hpp:98
TAR get()
retrieve current content of the variant, trying to cast or convert it to the given type...
Definition: variant-o.hpp:284
Policy invoking an catch-all function for processing an unknown tool / target pair, effectively enforcing the implementation of a catch-all function onUnknown(BASE&)
Definition: buildertool.hpp:68
A library implementation of the Visitor Pattern tailored specifically to Lumiera&#39;s needs within the S...
Buildable::ReturnType apply(BuilderTool &tool, WRA &wrappedTargetObj)
to be picked up by ADL: redirect tool invocation for double dispatch.
string resolve(fsys::path iniSpec)
use the general mechanism for resolving a search path to get the absolute path of the setup...
Definition: basic-setup.cpp:56