Lumiera  0.pre.03
»edit your freedom«
scope-path.hpp
Go to the documentation of this file.
1 /*
2  SCOPE-PATH.hpp - logical access path down from Session root
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 
87 #ifndef STEAM_MOBJECT_SESSION_SCOPE_PATH_H
88 #define STEAM_MOBJECT_SESSION_SCOPE_PATH_H
89 
91 #include "lib/iter-adapter.hpp"
92 #include "lib/error.hpp"
93 
94 #include <vector>
95 #include <string>
96 
97 
98 namespace lib {
99 namespace meta{
100 
102 
111  template<>
112  struct ValueTypeBinding<vector<Scope>::const_reverse_iterator>
113  {
114  typedef const Scope value_type;
115  typedef Scope const& reference;
116  typedef const Scope* pointer;
117  };
118 }}
119 
120 namespace steam {
121 namespace mobject {
122 namespace session {
123 
124 
135  class ScopePath
136  {
137  size_t refcount_;
138  std::vector<Scope> path_;
139 
140  typedef vector<Scope> _VType;
141  typedef _VType::const_reverse_iterator _VIter;
143 
144  public:
145  ~ScopePath ();
146  ScopePath ();
147  ScopePath (Scope const& leaf);
148 
149  ScopePath (ScopePath const&);
150  ScopePath&
151  operator= (ScopePath const&);
152 
153  static const ScopePath INVALID;
154 
155  explicit operator bool() const { return isValid(); }
156 
157 
158  /* == state diagnostics == */
159  bool isValid() const;
160  bool empty() const;
161  bool isRoot() const;
162  size_t size() const;
163  size_t length() const;
164  size_t ref_count()const;
165  operator string() const;
166 
168  typedef _IterType iterator;
169  iterator begin() const;
170  iterator end() const;
171 
172 
173  /* == relations == */
174  Scope const& getLeaf() const;
175  bool endsAt (Scope const&) const;
176  bool contains (Scope const&) const;
177  bool contains (ScopePath const&) const;
178 
179  friend ScopePath commonPrefix (ScopePath const&, ScopePath const&);
180  friend bool disjoint (ScopePath const&, ScopePath const&);
181 
182  friend bool operator== (ScopePath const&, ScopePath const&);
183 
184  friend void intrusive_ptr_add_ref (ScopePath*);
185  friend void intrusive_ptr_release (ScopePath*);
186 
187 
188  /* == mutations == */
189  void clear();
190  Scope const& moveUp();
191  Scope const& goRoot();
192  void navigate (Scope const&);
193 
194 
195  private:
196  bool hasValidRoot() const;
197  PlacementMO const& currModelRoot() const;
198  void appendScope (Scope const&);
199  };
200 
201 
202 
203 
204 
205 
206 
207  inline bool
208  operator== (ScopePath const& path1, ScopePath const& path2)
209  {
210  return path1.path_ == path2.path_;
211  }
212 
213  inline bool
214  operator!= (ScopePath const& path1, ScopePath const& path2)
215  {
216  return not (path1 == path2);
217  }
218 
219 
223  inline void
225  {
226  REQUIRE (pathFrame);
227  ++(pathFrame->refcount_);
228  }
229 
230  inline void
231  intrusive_ptr_release (ScopePath* pathFrame)
232  {
233  REQUIRE (pathFrame);
234  if (0 < pathFrame->refcount_)
235  --(pathFrame->refcount_);
236  }
237 
238 
239 
240  inline size_t
241  ScopePath::ref_count() const
242  {
243  return refcount_;
244  }
245 
246 
247  inline size_t
248  ScopePath::length() const
249  {
250  return path_.size();
251  }
252 
253 
254  inline size_t
255  ScopePath::size() const
256  {
257  return path_.size();
258  }
259 
264  inline bool
265  ScopePath::empty() const
266  {
267  return path_.empty();
268  }
269 
270  inline bool
271  ScopePath::isRoot() const
272  {
273  return (1 == size())
274 #if NOBUG_MODE_ALPHA
275  && path_[0].isRoot()
276 #endif
277  ;
278  }
279 
280 
281 
285  inline ScopePath::iterator
286  ScopePath::begin() const
287  {
288  return iterator (path_.rbegin(), path_.rend());
289  }
290 
291  inline ScopePath::iterator
292  ScopePath::end() const
293  {
294  return iterator();
295  }
296 
297 
298 }}} // namespace mobject::session
299 #endif
Helper template(s) for creating Lumiera Forward Iterators.
static const ScopePath INVALID
constant invalid path token.
Definition: scope-path.hpp:153
void intrusive_ptr_add_ref(ScopePath *pathFrame)
management function for boost::intrusive_ptr to be picked up by ADL
Definition: scope-path.hpp:224
bool operator==(PtrDerefIter< I1 > const &il, PtrDerefIter< I2 > const &ir)
Supporting equality comparisons...
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
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
Implementation namespace for support and library code.
_IterType iterator
Iteration is always ascending from leaf to root.
Definition: scope-path.hpp:168
Lumiera error handling (C++ interface).
Accessing a STL element range through a Lumiera forward iterator, An instance of this iterator adapte...
Type re-binding helper template for creating nested typedefs usable by custom containers and iterator...