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) Lumiera.org
5  2009, 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 
46 #include "lib/iter-source.hpp"
48 
49 #include <vector>
50 
51 using std::string;
52 using std::vector;
53 using lib::IterSource;
55 
56 
57 namespace lumiera {
58 namespace error {
59  LUMIERA_ERROR_DEFINE (INVALID_SCOPE, "Placement scope invalid and not locatable within model");
60  LUMIERA_ERROR_DEFINE (NO_PARENT_SCOPE, "Parent scope of root not accessible");
61  LUMIERA_ERROR_DEFINE (EMPTY_SCOPE_PATH, "Placement scope not locatable (empty model path)");
62 }}
63 
64 namespace steam {
65 namespace mobject {
66 namespace session {
67 
68 
69 
73  Scope::Scope (PlacementMO const& constitutingPlacement)
74  : anchor_(constitutingPlacement)
75  { }
76 
77  Scope::Scope (PlacementMO::ID const& constitutingPlacement)
78  : anchor_(constitutingPlacement)
79  { }
80 
81 
83  : anchor_()
84  {
85  REQUIRE (!anchor_.isValid());
86  }
87 
88 
89  Scope::Scope (Scope const& o)
90  : anchor_(o.anchor_)
91  {
92  ENSURE (anchor_.isValid());
93  }
94 
95 
96  Scope&
97  Scope::operator= (Scope const& o)
98  {
99  anchor_ = o.anchor_; // note: actually we're just assigning an hash value
100  ENSURE (o.isValid());
101  return *this;
102  }
103 
104 
106  const Scope Scope::INVALID = Scope();
107 
108 
109 
110  ScopeLocator::ScopeLocator()
111  : focusStack_(new QueryFocusStack)
112  { }
113 
114  ScopeLocator::~ScopeLocator() { }
115 
116 
119 
120 
129  {
131  }
132 
133 
134  size_t
135  ScopeLocator::stackSize() const
136  {
137  return focusStack_->size();
138  }
139 
140 
151  ScopePath&
153  {
154  return focusStack_->top();
155  }
156 
157 
162  ScopePath&
164  {
165  return focusStack_->push (SessionServiceExploreScope::getScopeRoot());
166  }
167 
168 
183  {
184  ScopePath& currentPath = focusStack_->top();
185  currentPath.navigate (scope);
186  return wrapIter (currentPath.begin());
187  }
188 
189 
190 
192  Scope
193  Scope::containing (PlacementMO const& aPlacement)
194  {
195  return SessionServiceExploreScope::getScope (aPlacement);
196  }
197 
198 
199  Scope
200  Scope::containing (RefPlacement const& refPlacement)
201  {
202  return containing (*refPlacement);
203  }
204 
205 
206  PlacementMO&
207  Scope::getTop() const
208  {
209  ASSERT (anchor_);
210  return *anchor_;
211  }
212 
213 
217  Scope
219  {
220  if (isRoot())
221  throw lumiera::error::Invalid ("can't get parent of root scope"
222  , LERR_(NO_PARENT_SCOPE));
223 
224  return SessionServiceExploreScope::getScope (*anchor_);
225  }
226 
227 
229  bool
231  {
232  return *anchor_ == SessionServiceExploreScope::getScopeRoot();
233  }
234 
235 
239  bool
241  {
242  return anchor_.isValid();
243  }
244 
245 
250  Scope::operator string() const
251  {
252  string res("[");
253  res += anchor_->shortID();
254  res += "]";
255  return res;
256  }
257 
258 
259 
260 
261 
262 }}} // 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:218
Scope()
unlocated NIL scope
Definition: scope.cpp:82
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:193
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:289
Sequence of nested scopes within the high-level model.
Definition: scope-path.hpp:135
A Placement scope within the high-level-model.
Definition: scope.hpp:78
bool isValid() const
check if this scope can be located.
Definition: scope.cpp:240
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
lumiera::QueryResolver const & theResolver()
Definition: scope.cpp:128
static PlacementMO & getScope(PlacementMO const &)
Iteration source interface to abstract a data source, which then can be accessed through IterAdapter ...
Definition: iter-source.hpp:88
lib::IterSource< const Scope >::iterator locate(Scope const &target)
navigate the current QueryFocus scope location.
Definition: scope.cpp:182
Implementation facility to work with and navigate nested scopes.
static const Scope INVALID
constant invalid scope token.
Definition: scope.hpp:92
ScopePath & pushPath()
push aside the current focus location and open a new ScopePath frame, to serve as current location un...
Definition: scope.cpp:163
ScopePath & currPath()
establishes the current query focus location.
Definition: scope.cpp:152
Service to build the notion of a current location within the Sesison model.
Lumiera public interface.
Definition: advice.cpp:113
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:80