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)
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 
78 #ifndef STEAM_MOBJECT_SESSION_SCOPE_PATH_H
79 #define STEAM_MOBJECT_SESSION_SCOPE_PATH_H
80 
82 #include "lib/iter-adapter.hpp"
83 #include "lib/error.hpp"
84 
85 #include <vector>
86 #include <string>
87 
88 
89 namespace lib {
90 namespace meta{
91 
93 
102  template<>
103  struct ValueTypeBinding<vector<Scope>::const_reverse_iterator>
104  {
105  typedef const Scope value_type;
106  typedef Scope const& reference;
107  typedef const Scope* pointer;
108  };
109 }}
110 
111 namespace steam {
112 namespace mobject {
113 namespace session {
114 
115 
126  class ScopePath
127  {
128  size_t refcount_;
129  std::vector<Scope> path_;
130 
131  typedef vector<Scope> _VType;
132  typedef _VType::const_reverse_iterator _VIter;
134 
135  public:
136  ~ScopePath ();
137  ScopePath ();
138  ScopePath (Scope const& leaf);
139 
140  ScopePath (ScopePath const&);
141  ScopePath&
142  operator= (ScopePath const&);
143 
144  static const ScopePath INVALID;
145 
146  explicit operator bool() const { return isValid(); }
147 
148 
149  /* == state diagnostics == */
150  bool isValid() const;
151  bool empty() const;
152  bool isRoot() const;
153  size_t size() const;
154  size_t length() const;
155  size_t ref_count()const;
156  operator string() const;
157 
159  typedef _IterType iterator;
160  iterator begin() const;
161  iterator end() const;
162 
163 
164  /* == relations == */
165  Scope const& getLeaf() const;
166  bool endsAt (Scope const&) const;
167  bool contains (Scope const&) const;
168  bool contains (ScopePath const&) const;
169 
170  friend ScopePath commonPrefix (ScopePath const&, ScopePath const&);
171  friend bool disjoint (ScopePath const&, ScopePath const&);
172 
173  friend bool operator== (ScopePath const&, ScopePath const&);
174 
175  friend void intrusive_ptr_add_ref (ScopePath*);
176  friend void intrusive_ptr_release (ScopePath*);
177 
178 
179  /* == mutations == */
180  void clear();
181  Scope const& moveUp();
182  Scope const& goRoot();
183  void navigate (Scope const&);
184 
185 
186  private:
187  bool hasValidRoot() const;
188  PlacementMO const& currModelRoot() const;
189  void appendScope (Scope const&);
190  };
191 
192 
193 
194 
195 
196 
197 
198  inline bool
199  operator== (ScopePath const& path1, ScopePath const& path2)
200  {
201  return path1.path_ == path2.path_;
202  }
203 
204  inline bool
205  operator!= (ScopePath const& path1, ScopePath const& path2)
206  {
207  return not (path1 == path2);
208  }
209 
210 
214  inline void
216  {
217  REQUIRE (pathFrame);
218  ++(pathFrame->refcount_);
219  }
220 
221  inline void
222  intrusive_ptr_release (ScopePath* pathFrame)
223  {
224  REQUIRE (pathFrame);
225  if (0 < pathFrame->refcount_)
226  --(pathFrame->refcount_);
227  }
228 
229 
230 
231  inline size_t
232  ScopePath::ref_count() const
233  {
234  return refcount_;
235  }
236 
237 
238  inline size_t
239  ScopePath::length() const
240  {
241  return path_.size();
242  }
243 
244 
245  inline size_t
246  ScopePath::size() const
247  {
248  return path_.size();
249  }
250 
255  inline bool
256  ScopePath::empty() const
257  {
258  return path_.empty();
259  }
260 
261  inline bool
262  ScopePath::isRoot() const
263  {
264  return (1 == size())
265 #if NOBUG_MODE_ALPHA
266  && path_[0].isRoot()
267 #endif
268  ;
269  }
270 
271 
272 
276  inline ScopePath::iterator
277  ScopePath::begin() const
278  {
279  return iterator (path_.rbegin(), path_.rend());
280  }
281 
282  inline ScopePath::iterator
283  ScopePath::end() const
284  {
285  return iterator();
286  }
287 
288 
289 }}} // namespace mobject::session
290 #endif
Helper template(s) for creating Lumiera Forward Iterators.
static const ScopePath INVALID
constant invalid path token.
Definition: scope-path.hpp:144
void intrusive_ptr_add_ref(ScopePath *pathFrame)
management function for boost::intrusive_ptr to be picked up by ADL
Definition: scope-path.hpp:215
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:65
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
Implementation namespace for support and library code.
_IterType iterator
Iteration is always ascending from leaf to root.
Definition: scope-path.hpp:159
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...