Lumiera  0.pre.03
»edityourfreedom«
buildertool.hpp
Go to the documentation of this file.
1 /*
2  BUILDERTOOL.hpp - Interface, (visiting) tool for processing MObjects
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
52 #ifndef MOBJECT_BUILDER_TOOL_H
53 #define MOBJECT_BUILDER_TOOL_H
54 
55 #include "lib/visitor.hpp"
56 #include "lib/wrapperptr.hpp"
57 
58 #include "lib/p.hpp"
61 
62 
63 namespace proc {
64 namespace mobject {
65 
66  class Buildable;
67 
68  namespace builder {
69 
70 
76  template<class RET>
78  {
79  protected:
81  public:
82  virtual RET onUnknown (Buildable& target) = 0;
83  };
84 
85 
86 
107  : public lib::visitor::Tool<void, InvokeCatchAllFunction>
109 
110  public:
111 
112  template<template<class> class WRA, class TAR>
113  void rememberWrapper (WRA<TAR>* ptr_toWrappedTarget)
114  {
115  currentWrapper_ = ptr_toWrappedTarget;
116  }
117  template<template<class,class> class Placement, class TAR, class B>
118  void rememberWrapper (Placement<TAR,B>* ptr_toWrappedTarget)
119  {
120  currentWrapper_ = ptr_toWrappedTarget;
121  }
122 
124  {
125  currentWrapper_.reset();
126  }
127 
128 
129  protected: /* == interface for accessing the wrapper from within tool application == */
130 
131  template<class TAR>
134  {
135  Placement<TAR>* pPlacement = currentWrapper_.get<Placement<TAR>*>();
136  ENSURE (pPlacement, "wrong target type when invoking %s", __PRETTY_FUNCTION__);
137  return *pPlacement;
138  }
139 
142  {
143  return getPlacement<MObject>().resolve();
144  }
145 
146  template<class TAR>
149  {
150  lib::P<TAR>* pP = currentWrapper_.get<lib::P<TAR>*>();
151  ENSURE (pP, "wrong target type when invoking %s", __PRETTY_FUNCTION__);
152  return *pP;
153  }
154  };
155 
156 
157 
162  template
163  < class TOOLImpl, // concrete BuilderTool implementation
164  class TYPELIST // list of all concrete Buildables to be treated
165  >
167  : public lib::visitor::Applicable<TOOLImpl, TYPELIST, BuilderTool>
168  { }
169  ;
170 
171  using lib::meta::Types; // convenience for the users of "Applicable"
172 
173  }// namespace mobject::builder
174 
175 
176 
177 
178 
182  class Buildable : public lib::visitor::Visitable<builder::BuilderTool>
183  { };
184 
185 
186 
187 
188  namespace builder {
189 
197  template<typename WRA>
198  inline Buildable::ReturnType
199  apply (BuilderTool& tool, WRA& wrappedTargetObj)
200  {
201  tool.rememberWrapper(&wrappedTargetObj);
202  wrappedTargetObj->apply (tool); // dispatch to suitable treat() function
203  tool.forgetWrapper();
204  }
205 
206 
207 }}} // namespace proc::mobject::builder
208 #endif
Wrapper to treat several flavours of smart-pointers uniformly.
declare the concrete types a BuilderTool may receive and treat.
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:87
virtual RET onUnknown(Buildable &target)=0
Marker template to declare that some "visiting tool" wants to treat a set of concrete Visitable class...
Definition: visitor.hpp:144
Marker interface or base class for all "Visitables".
Definition: visitor.hpp:197
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.
void rememberWrapper(Placement< TAR, B > *ptr_toWrappedTarget)
ExplicitPlacement getExplicitPlacement()
Customised refcounting smart pointer.
Base class of all BuilderTools, used according to the visitor pattern: each Tool contains the concret...
void rememberWrapper(WRA< TAR > *ptr_toWrappedTarget)
Marker Interface for classes visitable by Builder tools.
Marker interface / base class for all "visiting tools".
Definition: visitor.hpp:107
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
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:77
TAR get()
retrieve current content of the variant, trying to cast or convert it to the given type...
Definition: variant-o.hpp:293
builder::BuilderTool ::ReturnType ReturnType
Definition: visitor.hpp:200
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
ENSURE(r==&pq)
A library implementation of the Visitor Pattern tailored specifically to Lumiera&#39;s needs within the P...
Buildable::ReturnType apply(BuilderTool &tool, WRA &wrappedTargetObj)
to be picked up by ADL: redirect tool invocation for double dispatch.