Lumiera  0.pre.03
»edit your freedom«
state-recorder.hpp
Go to the documentation of this file.
1 /*
2  STATE-RECORDER.hpp - map based recording of presentation state
3 
4  Copyright (C) Lumiera.org
5  2016, 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 
52 #ifndef STAGE_CTRL_STATE_RECORDER_H
53 #define STAGE_CTRL_STATE_RECORDER_H
54 
55 
56 #include "lib/error.hpp"
57 #include "lib/idi/entry-id.hpp"
58 #include "lib/diff/gen-node.hpp"
59 #include "stage/ctrl/bus-term.hpp"
62 #include "include/ui-protocol.hpp"
63 
64 #include <string>
65 
66 
67 namespace stage {
68 namespace ctrl {
69 
71  using lib::diff::GenNode;
72  using lib::diff::Ref;
73  using std::string;
74 
75 
76 
77 
93  : public StateManager
94  {
96  using Record = Storage::Record const&;
97 
98  BusTerm& uiBus_;
99  Storage storage_;
100 
101 
102 
103  /* === PresentationStateManager interface === */
104 
105  virtual StateMark
106  currentState (ID uiElm, string propertyKey) const override
107  {
108  return storage_.retrieve (uiElm, propertyKey);
109  }
110 
111 
112  virtual void
113  replayState (ID uiElm, string propertyKey) override
114  {
115  StateMark state = storage_.retrieve (uiElm, propertyKey);
116  if (state != Ref::NO)
117  uiBus_.mark (uiElm, state);
118  }
119 
120 
121  virtual void
122  replayAllState() override
123  {
124  for (Record entry : storage_)
126  }
127 
128 
132  virtual void
133  replayAllState (string propertyKey) override
134  {
135  for (Record entry : storage_)
136  {
137  StateMark state = Storage::getState (entry, propertyKey);
138  if (state != Ref::NO)
139  uiBus_.mark (Storage::getID (entry), state);
140  }
141  }
142 
143 
145  virtual void
146  replayAllProperties (ID uiElm) override
147  {
148  auto entry = storage_.find (uiElm);
149  if (entry != storage_.end())
151  }
152 
153 
154  virtual void
155  clearState() override
156  {
157  storage_.clear();
158  }
159 
160 
161  public:
162  StateRecorder (BusTerm& busConnection)
163  : uiBus_(busConnection)
164  , storage_()
165  { }
166 
175  void
176  recordState (ID uiElm, StateMark stateMark)
177  {
178  if (MARK_reset == stateMark.idi.getSym())
179  storage_.clearState (uiElm);
180  else
181  if (MARK_clearErr == stateMark.idi.getSym())
182  storage_.clearProperty (uiElm, string{MARK_Error});
183  else
184  if (MARK_clearMsg == stateMark.idi.getSym())
185  storage_.clearProperty (uiElm, string{MARK_Message});
186  else
187  storage_.record (uiElm, stateMark);
188  }
189 
190  private:
199  void
201  {
202  ID uiElm = Storage::getID (entry);
203  for (auto& stateMark : Storage::getState (entry))
204  uiBus_.mark (uiElm, stateMark);
205  }
206  };
207 
208 
209 
210 }} // namespace stage::ctrl
211 #endif /*STAGE_CTRL_STATE_RECORDER_H*/
Simple map based implementation of the PresentationStateManager interface.
Constructor for a specially crafted &#39;ref GenNode&#39;.
Definition: gen-node.hpp:849
Hard wired key constants and basic definitions for communication with the GUI.
void record(BareEntryID const &elementID, GenNode const &stateMark)
remember the state mark for the denoted element
connection point at the UI-Bus.
Definition: bus-term.hpp:105
virtual void replayAllProperties(ID uiElm) override
replay all captured state from the given element.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
Implementation of storage for captured presentation state.
Interface: a component to maintain persistent interface state.
void clearProperty(BareEntryID const &elementID, string propertyKey)
clear previously recorded state for a given element and specific property
void clearState(BareEntryID const &elementID)
clear any previously recorded state for a given element
Attachment point to the UI-Bus.
virtual void replayAllState(string propertyKey) override
replay all captured state from any element, but captured especially for the given property ...
Map storage for captured presentation state information.
virtual bool mark(ID subject, GenNode const &mark)
route a state update or notification to the given subject.
Definition: ui-bus.cpp:177
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
void replayPropertiesOf(Record entry)
Generic building block for tree shaped (meta)data structures.
static const Ref NO
symbolic ID ref "_NO_"
Definition: gen-node.hpp:870
GenNode const & retrieve(BareEntryID const &elementID, string propertyKey) const
retrieve captured state
Interface: handling of persistent interface state.
Lumiera error handling (C++ interface).
void recordState(ID uiElm, StateMark stateMark)
Interface for the operating facility (CoreService) to feed state mark messages to be remembered...
Bare symbolic and hash ID used for accounting of asset like entries.
generic data element node within a tree
Definition: gen-node.hpp:231