Lumiera  0.pre.03
»edit your freedom«
placement.hpp
Go to the documentation of this file.
1 /*
2  PLACEMENT.hpp - Key Abstraction: a way to place and locate a Media Object
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 
23 
70 #ifndef MOBJECT_PLACEMENT_H
71 #define MOBJECT_PLACEMENT_H
72 
73 #include "lib/error.hpp"
74 #include "lib/hash-indexed.hpp"
75 #include "lib/time/timevalue.hpp"
77 
78 #include "steam/asset/pipe.hpp"
79 
80 #include <memory>
81 
82 
83 namespace steam {
84 namespace mobject {
85 
86  namespace session{ class MObjectFactory; }
87 
88  class MObject;
89  class ExplicitPlacement;
90 
91  using std::shared_ptr;
92  using std::static_pointer_cast;
93  using lib::HashIndexed;
94 
95 
96 
114  template<class MO, class B =MObject>
115  class Placement ;
116 
117 
122  template<>
124  : protected shared_ptr<MObject>
125  , public HashIndexed<Placement<MObject>, lib::hash::LuidH >
126  {
127  protected:
130  typedef void (*Deleter)(MObject*);
131  typedef lib::time::Time Time;
133 
134 
135 
136  public:
141  MObject *
142  operator->() const
143  {
144  ENSURE (*this);
145  return _SmartPtr::operator->();
146  }
147 
151  template<class Y>
152  bool
153  isCompatible () const
154  {
155  return 0 != dynamic_cast<Y*> (get());
156  }
157 
161  template<class Y>
162  void
164  {
165  REQUIRE (isCompatible<Y>());
166  target = static_pointer_cast<Y>(*this);
167  }
168 
170  friend bool
171  isSharedPointee (Placement const& p1, Placement const& p2)
172  {
173  return static_cast<const void*> (p1.get())
174  == static_cast<const void*> (p2.get());
175  }
176 
177 
178  operator string() const ;
179  size_t use_count() const { return _SmartPtr::use_count(); }
180  bool isValid() const { return _SmartPtr::use_count(); }
181 
182 
183  virtual ~Placement() {};
184 
185 
186 
192 
197  virtual ExplicitPlacement resolve () const;
201 
202 
203  Placement (Placement const& ref)
204  : _SmartPtr (ref)
205  , HashInd() // creating a new ID!
206  , chain(ref.chain)
207  { }
208 
209  protected:
210  Placement (MObject & subject, Deleter killer)
211  : _SmartPtr (&subject, killer) { };
212 
213  friend class session::MObjectFactory;
214 
215 
217 // private:
218 // /** copy assignment prohibited */
219 // Placement& operator= (Placement const&);
221  };
222 
223 
234  template<class MO, class B>
235  class Placement
236  : public Placement<B>
237  {
238  protected:
239  typedef Placement<B> _Parent;
240  typedef typename _Parent::template Id<MO> const& _Id;
241  typedef typename _Parent::Deleter Deleter;
242  typedef typename _Parent::_SmartPtr _SmartPtr;
243 
244 
245  Placement (MO & mo, Deleter killer)
246  : _Parent (mo, killer)
247  { };
248  friend class session::MObjectFactory;
249 
250  public:
251  MO*
252  operator-> () const
253  {
254  ENSURE (INSTANCEOF (MO, this->get()));
255  return static_cast<MO*>
256  (_SmartPtr::operator-> ());
257  }
258 
259  _Id
260  getID () const
261  {
262  return _Parent::template recastID<MO>();
263  }
264 
265  };
266 
267 
270  typedef Placement<MObject> PMO;
271 
272 
273 
274  /* == free functions == */
275 
276  string
277  format_PlacementID (PlacementMO const&) ;
278 
279 
284  bool
285  isSameDef (PlacementMO const&, PlacementMO const&);
286 
287 
288 
289 }} // namespace steam::mobject
290 #endif
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:91
Hash based ID, typed to a specific subclass of BA.
A "processing pipe" represented as Asset.
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition: util.hpp:492
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
A Mixin to add a private ID type to the target class, together with storage to hold an instance of th...
Positioning specification, possibly chained to further specifications.
Definition: locatingpin.hpp:97
Steam-Layer implementation namespace root.
Implementing the Placement mechanics.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:79
MObject * operator->() const
smart pointer: accessing the MObject, which is subject to placement.
Definition: placement.hpp:142
bool isCompatible() const
run time diagnostics: is the pointee of this placement compatible to the given type?
Definition: placement.hpp:153
Placement< MObject > PlacementMO
Definition: placement.hpp:269
bool isSameDef(PlacementMO const &pl1, PlacementMO const &pl2)
compare the properties of placement
Definition: placement.cpp:77
A template for generating hash based ID tags carrying compile-time type info.
Lumiera error handling (C++ interface).
Hash implementation based on a lumiera unique object id (LUID) When invoking the default ctor...
session::LocatingPin chain
interface for defining the kind of placement to employ, and for controlling any additional constraint...
Definition: placement.hpp:183
void extendOwnershipTo(shared_ptr< Y > &target) const
extend shared ownership to the given smart-ptr
Definition: placement.hpp:163
a family of time value like entities and their relationships.
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:65
friend bool isSharedPointee(Placement const &p1, Placement const &p2)
free function to detect two placements sharing a pointee
Definition: placement.hpp:171