Lumiera  0.pre.03
»edit your freedom«
query-focus-stack.hpp
Go to the documentation of this file.
1 /*
2  QUERY-FOCUS-STACK.hpp - management of current scope within the Session
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 
22 #ifndef MOBJECT_SESSION_QUERY_FOCUS_STACK_H
23 #define MOBJECT_SESSION_QUERY_FOCUS_STACK_H
24 
26 #include "lib/nocopy.hpp"
27 
28 #include <list>
29 
30 using std::list;
31 
32 
33 namespace steam {
34 namespace mobject {
35 namespace session {
36 
37 
38 
62  {
63 
64  std::list<ScopePath> paths_;
65 
66  public:
68  : paths_()
69  {
71  }
72 
73 
74  bool empty () const;
75  size_t size () const;
76 
77  ScopePath& push (Scope const&);
78  ScopePath& top ();
79  void pop_unused ();
80  void clear ();
81 
82 
83  private:
84  void openDefaultFrame ();
85  };
86 
87 
88 
89 
90 
91 
92 
93  /* __implementation__ */
94 
95  bool
96  QueryFocusStack::empty () const
97  {
98  return paths_.empty();
99  }
100 
101 
102  size_t
103  QueryFocusStack::size () const
104  {
105  return paths_.size();
106  }
107 
108 
109  void
110  QueryFocusStack::clear ()
111  {
112  paths_.clear();
114  }
115 
116 
124  ScopePath&
125  QueryFocusStack::push (Scope const& newStartPoint)
126  {
127  ScopePath newPathFrame (newStartPoint); // may throw
128  ENSURE (newPathFrame.isValid() || newStartPoint.isRoot());
129 
130  paths_.push_back (newPathFrame);
131  ENSURE (0 < size());
132  return paths_.back();
133  }
134 
135 
140  ScopePath&
142  {
143  if ( 0 == size()
144  || 0 == paths_.back().ref_count()
145  )
146  pop_unused();
147 
148  ENSURE (!empty());
149  return paths_.back();
150  }
151 
152 
160  void
162  {
163  if (1 == size() && !paths_.front().isValid())
164  return; // unnecessary to evict a base frame repeatedly
165 
166  while (size() && (0 == paths_.back().ref_count()))
167  paths_.pop_back();
168 
169  if (0 == size())
171  ENSURE (!empty());
172  }
173 
174 
179  void
181  {
182  REQUIRE (0 == size());
183 
184  paths_.resize(1);
185 
186  ENSURE (!paths_.front().empty());
187  ENSURE (!paths_.front().isValid()); // i.e. just root scope
188  }
189 
190 
191 
192 
193 }}} // namespace mobject::session
194 #endif /*MOBJECT_SESSION_QUERY_FOCUS_STACK_H*/
ScopePath & push(Scope const &)
Open a new path frame, pushing down the current frame.
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
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
Mix-Ins to allow or prohibit various degrees of copying and cloning.
void pop_unused()
investigate the stack top and discard any path frames which aren&#39;t referred anymore (as indicated by ...
bool isValid() const
a valid path consists of more than just the root element.
Definition: scope-path.cpp:161
An Object representing a sequence of nested scopes within the Session.
A custom stack holding ScopePath »frames«.