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) 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 
31 #ifndef MOBJECT_SESSION_QUERY_FOCUS_STACK_H
32 #define MOBJECT_SESSION_QUERY_FOCUS_STACK_H
33 
35 #include "lib/nocopy.hpp"
36 
37 #include <list>
38 
39 using std::list;
40 
41 
42 namespace steam {
43 namespace mobject {
44 namespace session {
45 
46 
47 
71  {
72 
73  std::list<ScopePath> paths_;
74 
75  public:
77  : paths_()
78  {
80  }
81 
82 
83  bool empty () const;
84  size_t size () const;
85 
86  ScopePath& push (Scope const&);
87  ScopePath& top ();
88  void pop_unused ();
89  void clear ();
90 
91 
92  private:
93  void openDefaultFrame ();
94  };
95 
96 
97 
98 
99 
100 
101 
102  /* __implementation__ */
103 
104  bool
105  QueryFocusStack::empty () const
106  {
107  return paths_.empty();
108  }
109 
110 
111  size_t
112  QueryFocusStack::size () const
113  {
114  return paths_.size();
115  }
116 
117 
118  void
119  QueryFocusStack::clear ()
120  {
121  paths_.clear();
123  }
124 
125 
133  ScopePath&
134  QueryFocusStack::push (Scope const& newStartPoint)
135  {
136  ScopePath newPathFrame (newStartPoint); // may throw
137  ENSURE (newPathFrame.isValid() || newStartPoint.isRoot());
138 
139  paths_.push_back (newPathFrame);
140  ENSURE (0 < size());
141  return paths_.back();
142  }
143 
144 
149  ScopePath&
151  {
152  if ( 0 == size()
153  || 0 == paths_.back().ref_count()
154  )
155  pop_unused();
156 
157  ENSURE (!empty());
158  return paths_.back();
159  }
160 
161 
169  void
171  {
172  if (1 == size() && !paths_.front().isValid())
173  return; // unnecessary to evict a base frame repeatedly
174 
175  while (size() && (0 == paths_.back().ref_count()))
176  paths_.pop_back();
177 
178  if (0 == size())
180  ENSURE (!empty());
181  }
182 
183 
188  void
190  {
191  REQUIRE (0 == size());
192 
193  paths_.resize(1);
194 
195  ENSURE (!paths_.front().empty());
196  ENSURE (!paths_.front().isValid()); // i.e. just root scope
197  }
198 
199 
200 
201 
202 }}} // namespace mobject::session
203 #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:46
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
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:170
An Object representing a sequence of nested scopes within the Session.
A custom stack holding ScopePath »frames«.