Lumiera  0.pre.03
»edit your freedom«
scope.cpp
Go to the documentation of this file.
1 /*
2  Scope - nested search scope for properties of placement
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 
37 #include "lib/iter-source.hpp"
39 
40 #include <vector>
41 
42 using std::string;
43 using std::vector;
44 using lib::IterSource;
46 
47 
48 namespace lumiera {
49 namespace error {
50  LUMIERA_ERROR_DEFINE (INVALID_SCOPE, "Placement scope invalid and not locatable within model");
51  LUMIERA_ERROR_DEFINE (NO_PARENT_SCOPE, "Parent scope of root not accessible");
52  LUMIERA_ERROR_DEFINE (EMPTY_SCOPE_PATH, "Placement scope not locatable (empty model path)");
53 }}
54 
55 namespace steam {
56 namespace mobject {
57 namespace session {
58 
59 
60 
64  Scope::Scope (PlacementMO const& constitutingPlacement)
65  : anchor_(constitutingPlacement)
66  { }
67 
68  Scope::Scope (PlacementMO::ID const& constitutingPlacement)
69  : anchor_(constitutingPlacement)
70  { }
71 
72 
74  : anchor_()
75  {
76  REQUIRE (!anchor_.isValid());
77  }
78 
79 
80  Scope::Scope (Scope const& o)
81  : anchor_(o.anchor_)
82  {
83  ENSURE (anchor_.isValid());
84  }
85 
86 
87  Scope&
88  Scope::operator= (Scope const& o)
89  {
90  anchor_ = o.anchor_; // note: actually we're just assigning an hash value
91  ENSURE (o.isValid());
92  return *this;
93  }
94 
95 
97  const Scope Scope::INVALID = Scope();
98 
99 
100 
101  ScopeLocator::ScopeLocator()
102  : focusStack_(new QueryFocusStack)
103  { }
104 
105  ScopeLocator::~ScopeLocator() { }
106 
107 
110 
111 
120  {
122  }
123 
124 
125  size_t
126  ScopeLocator::stackSize() const
127  {
128  return focusStack_->size();
129  }
130 
131 
142  ScopePath&
144  {
145  return focusStack_->top();
146  }
147 
148 
153  ScopePath&
155  {
156  return focusStack_->push (SessionServiceExploreScope::getScopeRoot());
157  }
158 
159 
174  {
175  ScopePath& currentPath = focusStack_->top();
176  currentPath.navigate (scope);
177  return wrapIter (currentPath.begin());
178  }
179 
180 
181 
183  Scope
184  Scope::containing (PlacementMO const& aPlacement)
185  {
186  return SessionServiceExploreScope::getScope (aPlacement);
187  }
188 
189 
190  Scope
191  Scope::containing (RefPlacement const& refPlacement)
192  {
193  return containing (*refPlacement);
194  }
195 
196 
197  PlacementMO&
198  Scope::getTop() const
199  {
200  ASSERT (anchor_);
201  return *anchor_;
202  }
203 
204 
208  Scope
210  {
211  if (isRoot())
212  throw lumiera::error::Invalid ("can't get parent of root scope"
213  , LERR_(NO_PARENT_SCOPE));
214 
215  return SessionServiceExploreScope::getScope (*anchor_);
216  }
217 
218 
220  bool
222  {
223  return *anchor_ == SessionServiceExploreScope::getScopeRoot();
224  }
225 
226 
230  bool
232  {
233  return anchor_.isValid();
234  }
235 
236 
241  Scope::operator string() const
242  {
243  string res("[");
244  res += anchor_->shortID();
245  res += "]";
246  return res;
247  }
248 
249 
250 
251 
252 
253 }}} // namespace steam::mobject::session
Implementation level session API: query a scope.
_IterT< IT >::Iter wrapIter(IT &&source)
wraps a given Lumiera Forward Iterator, exposing just a IterSource based frontend.
static lumiera::QueryResolver const & getResolver()
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
Scope getParent() const
retrieve the parent scope which encloses this scope.
Definition: scope.cpp:209
Scope()
unlocated NIL scope
Definition: scope.cpp:73
framework and to resolve logical queries.
Core abstraction of the Session model: a media object.
static Scope containing(PlacementMO const &aPlacement)
discover the enclosing scope of a given Placement
Definition: scope.cpp:184
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:280
Sequence of nested scopes within the high-level model.
Definition: scope-path.hpp:126
A Placement scope within the high-level-model.
Definition: scope.hpp:69
bool isValid() const
check if this scope can be located.
Definition: scope.cpp:231
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
lumiera::QueryResolver const & theResolver()
Definition: scope.cpp:119
static PlacementMO & getScope(PlacementMO const &)
Iteration source interface to abstract a data source, which then can be accessed through IterAdapter ...
Definition: iter-source.hpp:79
lib::IterSource< const Scope >::iterator locate(Scope const &target)
navigate the current QueryFocus scope location.
Definition: scope.cpp:173
Implementation facility to work with and navigate nested scopes.
static const Scope INVALID
constant invalid scope token.
Definition: scope.hpp:83
ScopePath & pushPath()
push aside the current focus location and open a new ScopePath frame, to serve as current location un...
Definition: scope.cpp:154
ScopePath & currPath()
establishes the current query focus location.
Definition: scope.cpp:143
Service to build the notion of a current location within the Sesison model.
Lumiera public interface.
Definition: advice.cpp:104
static lib::Depend< ScopeLocator > instance
Storage holding the single ScopeLocator instance.
Extension module to build an opaque data source, accessible as Lumiera Forward Iterator.
A custom stack holding ScopePath »frames«.
#define LUMIERA_ERROR_DEFINE(err, msg)
Definition and initialisation of an error constant.
Definition: error.h:71