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)
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 
14 
61 #ifndef MOBJECT_PLACEMENT_H
62 #define MOBJECT_PLACEMENT_H
63 
64 #include "lib/error.hpp"
65 #include "lib/hash-indexed.hpp"
66 #include "lib/time/timevalue.hpp"
68 
69 #include "steam/asset/pipe.hpp"
70 
71 #include <memory>
72 
73 
74 namespace steam {
75 namespace mobject {
76 
77  namespace session{ class MObjectFactory; }
78 
79  class MObject;
80  class ExplicitPlacement;
81 
82  using std::shared_ptr;
83  using std::static_pointer_cast;
84  using lib::HashIndexed;
85 
86 
87 
105  template<class MO, class B =MObject>
106  class Placement ;
107 
108 
113  template<>
115  : protected shared_ptr<MObject>
116  , public HashIndexed<Placement<MObject>, lib::hash::LuidH >
117  {
118  protected:
121  typedef void (*Deleter)(MObject*);
122  typedef lib::time::Time Time;
124 
125 
126 
127  public:
132  MObject *
133  operator->() const
134  {
135  ENSURE (*this);
136  return _SmartPtr::operator->();
137  }
138 
142  template<class Y>
143  bool
144  isCompatible () const
145  {
146  return 0 != dynamic_cast<Y*> (get());
147  }
148 
152  template<class Y>
153  void
155  {
156  REQUIRE (isCompatible<Y>());
157  target = static_pointer_cast<Y>(*this);
158  }
159 
161  friend bool
162  isSharedPointee (Placement const& p1, Placement const& p2)
163  {
164  return static_cast<const void*> (p1.get())
165  == static_cast<const void*> (p2.get());
166  }
167 
168 
169  operator string() const ;
170  size_t use_count() const { return _SmartPtr::use_count(); }
171  bool isValid() const { return _SmartPtr::use_count(); }
172 
173 
174  virtual ~Placement() {};
175 
176 
177 
183 
188  virtual ExplicitPlacement resolve () const;
192 
193 
194  Placement (Placement const& ref)
195  : _SmartPtr (ref)
196  , HashInd() // creating a new ID!
197  , chain(ref.chain)
198  { }
199 
200  protected:
201  Placement (MObject & subject, Deleter killer)
202  : _SmartPtr (&subject, killer) { };
203 
204  friend class session::MObjectFactory;
205 
206 
208 // private:
209 // /** copy assignment prohibited */
210 // Placement& operator= (Placement const&);
212  };
213 
214 
225  template<class MO, class B>
226  class Placement
227  : public Placement<B>
228  {
229  protected:
230  typedef Placement<B> _Parent;
231  typedef typename _Parent::template Id<MO> const& _Id;
232  typedef typename _Parent::Deleter Deleter;
233  typedef typename _Parent::_SmartPtr _SmartPtr;
234 
235 
236  Placement (MO & mo, Deleter killer)
237  : _Parent (mo, killer)
238  { };
239  friend class session::MObjectFactory;
240 
241  public:
242  MO*
243  operator-> () const
244  {
245  ENSURE (INSTANCEOF (MO, this->get()));
246  return static_cast<MO*>
247  (_SmartPtr::operator-> ());
248  }
249 
250  _Id
251  getID () const
252  {
253  return _Parent::template recastID<MO>();
254  }
255 
256  };
257 
258 
261  typedef Placement<MObject> PMO;
262 
263 
264 
265  /* == free functions == */
266 
267  string
268  format_PlacementID (PlacementMO const&) ;
269 
270 
275  bool
276  isSameDef (PlacementMO const&, PlacementMO const&);
277 
278 
279 
280 }} // namespace steam::mobject
281 #endif
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:82
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:514
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:88
Steam-Layer implementation namespace root.
Implementing the Placement mechanics.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:70
MObject * operator->() const
smart pointer: accessing the MObject, which is subject to placement.
Definition: placement.hpp:133
bool isCompatible() const
run time diagnostics: is the pointee of this placement compatible to the given type?
Definition: placement.hpp:144
Placement< MObject > PlacementMO
Definition: placement.hpp:260
bool isSameDef(PlacementMO const &pl1, PlacementMO const &pl2)
compare the properties of placement
Definition: placement.cpp:68
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:174
void extendOwnershipTo(shared_ptr< Y > &target) const
extend shared ownership to the given smart-ptr
Definition: placement.hpp:154
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:56
friend bool isSharedPointee(Placement const &p1, Placement const &p2)
free function to detect two placements sharing a pointee
Definition: placement.hpp:162