Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
placement-ref.hpp
Go to the documentation of this file.
1/*
2 PLACEMENT-REF.hpp - generic reference to an individual placement added to the session
3
4 Copyright (C)
5 2009, 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
56#ifndef MOBJECT_PLACEMENT_REF_H
57#define MOBJECT_PLACEMENT_REF_H
58
59#include "lib/error.hpp"
63
64
65namespace lumiera {
66namespace error {
67 LUMIERA_ERROR_DECLARE (INVALID_PLACEMENTREF);
68 LUMIERA_ERROR_DECLARE (BOTTOM_PLACEMENTREF);
69}}
70
71
72namespace steam {
73 namespace error = lumiera::error;
74
75 namespace mobject {
76
77 class MObject;
78
79
80
89 template<class MX =MObject>
91 {
95
97
98 public:
114 template<class Y>
115 explicit
116 PlacementRef (Y const& refID)
117 : id_(recast (refID))
118 {
119 validate(id_);
120 }
121
124 : id_( bottomID() )
125 {
126 REQUIRE (!isValid(), "hash-ID clash with existing ID");
127 }
128
130 : id_(r.id_)
131 {
132 validate(id_);
133 }
134
135 template<class X>
137 : id_(recast(r))
138 {
139 validate(id_);
140 }
141
142
145 {
146 validate(r.id_);
147 id_ = r.id_;
148 return *this;
149 }
150
151 template<class X>
154 {
155 validate(recast (r));
156 id_ = recast(r);
157 return *this;
158 }
159
160 template<class Y>
162 operator= (Y const& refID)
163 {
164 validate (recast (refID));
165 id_ = recast (refID);
166 return *this;
167 }
168
169 void clear () { id_ = bottomID(); }
170
171
172
173 /* == forwarding smart-ptr operations == */
174
175 PlacementMX& operator*() const { return access(id_); }
176
177 PlacementMX& operator->() const { return access(id_); }
178
179 operator string() const { return access(id_).operator string(); }
180 size_t use_count() const { return access(id_).use_count(); }
181
182
183 /* == accessing the embedded ID == */
184 operator _Id const&() const { return id_; }
185 LumieraUid getLUID() const { return id_.get(); }
186
187 template<class O>
188 bool operator== (PlacementRef<O> const& o) const { return id_ == o; }
189 template<class O>
190 bool operator!= (PlacementRef<O> const& o) const { return id_ != o; }
191
192
193
194
195
196 /* == forwarding part of the Placement-API == */
197
198 explicit
199 operator bool() const
200 {
201 return isValid();
202 }
203
204 bool isValid() const
205 {
206 if (checkValidity())
207 try
208 {
209 return access(id_).isValid();
210 }
211 catch (error::Invalid&) {}
212
213 return false;
214 }
215
217 resolve() const
218 {
219 return access(id_).resolve();
220 }
221
222
224
225 private:
226 bool
228 {
229 return session::SessionServiceFetch::isAccessible() // session interface opened?
231 }
232
233 static void
234 validate (_Id const& rId)
235 {
236 access (rId); // may throw
238 }
239
240 static _Id const&
241 recast (_ID const& someID)
242 {
243 return static_cast<_Id const&> (someID);
244 }
245
246 static _Id const&
247 recast (const LumieraUid luid)
248 {
249 REQUIRE (luid);
250 return reinterpret_cast<_Id const&> (*luid);
251 }
252
253 static _Id const&
255 {
256 static lumiera_uid invalidLUID;
257 return recast (&invalidLUID);
258 }
259
260 static PlacementMX&
261 access (_Id const& placementID)
262 {
263 if (not placementID)
264 throw error::Logic{"Attempt to access a NIL PlacementRef"
265 , LERR_(BOTTOM_PLACEMENTREF)};
266
267 Placement<MObject> & genericPlacement (session::SessionServiceFetch::resolveID (placementID)); // may throw
268 REQUIRE (genericPlacement.isValid());
269
270 if (!(genericPlacement.template isCompatible<MX>()))
271 throw error::Invalid{"actual type of the resolved placement is incompatible"
272 , LERR_(INVALID_PLACEMENTREF)};
275
276 return static_cast<PlacementMX&> (genericPlacement);
277 }
278 };
279
280
282 typedef PlacementRef<MObject> RefPlacement;
283
284
285
286}} // namespace steam::mobject
287#endif
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
virtual ExplicitPlacement resolve() const
no need to resolve any further, as this ExplicitPlacement already is the result of a resolve()-call.
Reference tag denoting a placement attached to the session.
static _Id const & bottomID()
Placement< MObject >::Id< MX > _Id
PlacementRef()
Default is an NIL Placement ref.
static void validate(_Id const &rId)
PlacementMX & operator->() const
provide access to pointee API by smart-ptr chaining
ExplicitPlacement resolve() const
static _Id const & recast(const LumieraUid luid)
PlacementRef(Y const &refID)
Creating a PlacementRef from a compatible reference source.
bool operator==(PlacementRef< O > const &o) const
PlacementRef & operator=(PlacementRef const &r)
bool operator!=(PlacementRef< O > const &o) const
PlacementRef(PlacementRef const &r)
PlacementMX & operator*() const
dereferencing fetches referred Placement from Index
Placement< MObject >::ID _ID
PlacementRef(PlacementRef< X > const &r)
static PlacementMX & access(_Id const &placementID)
static _Id const & recast(_ID const &someID)
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
static bool isRegisteredID(PlacementMO::ID const &)
verify the given placement-ID (hash) is valid, by checking if it refers to a Placement instance curre...
static PlacementMO & resolveID(PlacementMO::ID const &)
actually retrieve a Placement tracked by the index.
static bool isAccessible()
is the element-fetch service usable? Effectively this means: is the session up?
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Lumiera error handling (C++ interface).
#define LERR_(_NAME_)
Definition error.hpp:45
Core abstraction: completely resolved placement of an MObject Within the session model,...
lumiera_uid * LumieraUid
Definition hash-value.h:41
unsigned char lumiera_uid[16]
storage for a Lumiera unique ID, based on a 128bit random number
Definition hash-value.h:40
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
Lumiera public interface.
Definition advice.hpp:102
PlacementRef< MObject > RefPlacement
frequently-used shorthand
Steam-Layer implementation namespace root.
Core abstraction: placement of a media object into session context.
Implementation level session API: resolve a Placement by hash-ID.