Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
placement-index.hpp
Go to the documentation of this file.
1/*
2 PLACEMENT-INDEX.hpp - tracking individual Placements and their relations
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
97#ifndef STEAM_MOBJECT_PLACEMENT_INDEX_H
98#define STEAM_MOBJECT_PLACEMENT_INDEX_H
99
100#include "lib/error.hpp"
101#include "lib/symbol.hpp"
102#include "lib/itertools.hpp"
105#include "lib/nocopy.hpp"
106#include "lib/util.hpp"
107
108#include <unordered_map>
109#include <memory>
110#include <vector>
111
112namespace std {
113
115 template<>
116 struct hash<steam::mobject::PlacementMO::ID>
117 {
118 size_t
119 operator() (steam::mobject::PlacementMO::ID const& val) const noexcept
120 {
121 return hash_value(val);
122 }
123 };
124}
125
126
127namespace lumiera {
128namespace error {
129 LUMIERA_ERROR_DECLARE (NOT_IN_SESSION);
130 LUMIERA_ERROR_DECLARE (PLACEMENT_TYPE);
131 LUMIERA_ERROR_DECLARE (NONEMPTY_SCOPE);
132}}
133
134namespace steam {
135namespace mobject {
136
137 class MObject;
138
139namespace session {
140
141 using std::unique_ptr;
142
143
148 template<typename PLA>
149 struct BuildID;
150
152 template<typename MO, typename BMO>
153 struct BuildID<Placement<MO,BMO>>
154 {
155 using Type = PlacementMO::Id<MO>;
156 using Target = MO ;
157 };
158
159
160
174 {
175 class Table;
176 class Validator;
177
178 unique_ptr<Table> pTab_;
179
180
181 using _PID = PlacementMO::ID;
182 using ScopeIter = std::unordered_multimap<_PID,_PID>::const_iterator;
185
186
187
188 public:
190 using ID = PlacementMO::ID const&;
191
193
194
195 /* == query operations == */
196
197 PlacementMO& find (ID) const;
198
199 template<class MO>
200 Placement<MO>& find (PlacementMO::Id<MO>) const;
201 template<class MO>
202 Placement<MO>& find (PlacementRef<MO> const&) const;
203
204 PlacementMO& getScope (PlacementMO const&) const;
205 PlacementMO& getScope (ID) const;
206
207 iterator getReferrers (ID) const;
208
209
211 PlacementMO& getRoot() const;
212
213 size_t size() const;
214 bool contains (PlacementMO const&) const;
215 bool contains (ID) const;
216
217 bool isValid() const;
218
219
220
221
222 /* == mutating operations == */
223
224 ID insert (PlacementMO const& newObj, ID targetScope);
225 bool remove (PlacementMO&);
226 bool remove (ID);
227
228 template<class PLA>
229 BuildID<PLA>::Type insert (PLA const&, ID);
230
231
232
235
236 void clear (ID targetScope);
237 void clear ();
238
239 };
240
241
242
243
244
245
246
247
248 /* === forwarding implementations of the templated API === */
249
250
251 namespace { // shortcuts...
252
253 template<class MOX>
254 inline void
256 {
257 if (!questionable.isCompatible<MOX>())
258 throw lumiera::error::Logic ("Attempt to retrieve a Placement of specific type, "
259 "while the actual type of the pointee (MObject) "
260 "registered within the index isn't compatible with the "
261 "requested specific MObject subclass"
262 , LERR_(PLACEMENT_TYPE));
263 }
264
265 inline void
266 __check_knownID(PlacementIndex const& idx, PlacementMO::ID id)
267 {
268 if (!id)
269 throw lumiera::error::Logic ("Encountered a NIL Placement-ID marker"
270 , LERR_(BOTTOM_PLACEMENTREF));
271 if (!idx.contains (id))
272 throw lumiera::error::Invalid ("Accessing Placement not registered within the index"
273 , LERR_(NOT_IN_SESSION));
274 }
275 }//(End) shortcuts
276
277
278
279
280 template<class MO>
281 inline Placement<MO>&
282 PlacementIndex::find (PlacementMO::Id<MO> id) const
283 {
284 PlacementMO& result (find ((ID)id));
285
286 ___check_compatibleType<MO> (result);
287 return static_cast<Placement<MO>&> (result);
288 }
289
290
291 template<class MO>
292 inline Placement<MO>&
294 {
295 PlacementMO::Id<MO> id (pRef);
296 return find (id);
297 }
298
299
300 inline Placement<MObject>&
302 {
303 return getScope(p.getID());
304 }
305
306
307 inline bool
309 {
310 return contains (p.getID());
311 }
312
313
320 template<class PLA>
322 PlacementIndex::insert (PLA const& newObj, ID targetScope)
323 {
324 using TargetMO = BuildID<PLA>::Target;
325 PlacementMO const& genericPlacement(newObj);
326
327 return find (insert (genericPlacement, targetScope))
328 .template recastID<TargetMO>();
329 }
330
331
332 inline bool
334 {
335 return remove (p.getID());
336 }
337
338
339
340}}} // namespace steam::mobject::session
341#endif
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
Iterator tool treating pulled data by a custom transformation (function)
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Storage and implementation backing the PlacementIndex.
PlacementIndex self-verification code Executes all built-in checks automatically on object creation.
Structured compound of Placement instances with lookup capabilities.
bool isValid() const
validity self-check, used for sanity checks and the session self-check.
PlacementMO & getRoot() const
retrieve the logical root scope
bool contains(PlacementMO const &) const
PlacementMO & getScope(PlacementMO const &) const
std::unordered_multimap< _PID, _PID >::const_iterator ScopeIter
lib::TransformIter< ScopeRangeIter, PlacementMO & > _ID_TableIterator
iterator getReferrers(ID) const
Retrieve all the elements attached to the given entry (scope) Each element (Placement) can act as a s...
ID insert(PlacementMO const &newObj, ID targetScope)
Add a new Placement (Object "instance") into the index.
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
#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
Helpers for working with iterators based on the pipeline model.
LumieraError< LERR_(LOGIC)> Logic
Definition error.hpp:207
LumieraError< LERR_(INVALID)> Invalid
Definition error.hpp:211
Lumiera public interface.
Definition advice.hpp:102
STL namespace.
void __check_knownID(PlacementIndex const &idx, PlacementMO::ID id)
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Helper for building Placement-ID types.
Steam-Layer implementation namespace root.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A generic reference mechanism for Placements, as added to the current session.
Core abstraction: placement of a media object into session context.
Primary class template for std::hash.
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...