Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
state-map-grouping-storage.hpp
Go to the documentation of this file.
1/*
2 STATE-MAP-GROUPING-STORAGE.hpp - grouping storage to track presentation state
3
4 Copyright (C)
5 2016, 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
27#ifndef STAGE_CTRL_STATE_MAP_GROUPING_STORAGE_H
28#define STAGE_CTRL_STATE_MAP_GROUPING_STORAGE_H
29
30
31#include "lib/error.hpp"
32#include "lib/nocopy.hpp"
33#include "lib/idi/entry-id.hpp"
34#include "lib/diff/gen-node.hpp"
35#include "lib/util.hpp"
36
37#include <unordered_map>
38#include <algorithm>
39#include <set>
40
41
42namespace stage {
43namespace ctrl {
44
47 using lib::diff::Ref;
48 using ::util::unConst;
49 using std::string;
50
51
52
67 {
68 using StateData = std::set<GenNode, GenNode::IDComparator>;
69 using Storage = std::unordered_map<BareEntryID, StateData, BareEntryID::UseEmbeddedHash>;
70
71
73
74 public:
75 using Record = Storage::value_type;
76
77 bool
78 empty() const
79 {
80 return elmTable_.empty();
81 }
82
83 size_t
84 size() const
85 {
86 size_t siz{0};
87 for (Record const& entry : elmTable_)
88 siz += entry.second.size();
89 return siz;
90 }
91
92 void
94 {
95 elmTable_.clear();
96 }
97
98
103 GenNode const&
104 retrieve (BareEntryID const& elementID, string propertyKey) const
105 {
106 iterator entry = find (elementID);
107 if (entry == elmTable_.end())
108 return Ref::NO;
109 else
110 return getState (*entry, propertyKey);
111 }
112
118 void
119 record (BareEntryID const& elementID, GenNode const& stateMark)
120 {
121 auto res = elmTable_[elementID].emplace (stateMark);
122 if (not res.second)
123 unConst(*res.first) = stateMark; // update existing contents
124 }
125
127 void
128 clearProperty (BareEntryID const& elementID, string propertyKey)
129 {
130 iterator entry = find (elementID);
131 if (entry != elmTable_.end())
132 {
133 StateData const& stateSet = entry->second;
134 auto propertyRecord = findProperty(stateSet, propertyKey);
135
136 if (propertyRecord != stateSet.end())
137 unConst(stateSet).erase (propertyRecord);
138 }
139 }
140
142 void
143 clearState (BareEntryID const& elementID)
144 {
145 iterator entry = find (elementID);
146 if (entry != elmTable_.end())
147 elmTable_.erase (entry);
148 }
149
150
151 using iterator = Storage::const_iterator;
152
153 iterator begin() const { return elmTable_.begin(); }
154 iterator end() const { return elmTable_.end(); }
155
157 find (BareEntryID const& elementID) const
158 {
159 return elmTable_.find (elementID);
160 }
161
162 static BareEntryID const&
163 getID (Record const& entry)
164 {
165 return entry.first;
166 }
167
168 static StateData const&
169 getState (Record const& entry)
170 {
171 return entry.second;
172 }
173
174
189 static GenNode const&
190 getState (Record const& entry, string propertyKey)
191 {
192 StateData const& stateSet = entry.second;
193 StateData::const_iterator propertyRecord = findProperty (stateSet, propertyKey);
194
195 if (propertyRecord == stateSet.end())
196 return Ref::NO;
197 else
198 return *propertyRecord;
199 }
200
201 private:
202 static StateData::const_iterator
203 findProperty (StateData const& stateSet, string propertyKey)
204 {
205 return std::find_if (stateSet.begin()
206 ,stateSet.end()
207 ,[=](GenNode const& stateMark)
208 {
209 return propertyKey == stateMark.idi.getSym();
210 });
211 }
212 };
213
214
215
216}} // namespace stage::ctrl
217#endif /*STAGE_CTRL_STATE_MAP_GROUPING_STORAGE_H*/
type erased baseclass for building a combined hash and symbolic ID.
Definition entry-id.hpp:134
Map storage for captured presentation state information.
void clearState(BareEntryID const &elementID)
clear any previously recorded state for a given element
std::unordered_map< BareEntryID, StateData, BareEntryID::UseEmbeddedHash > Storage
std::set< GenNode, GenNode::IDComparator > StateData
static StateData const & getState(Record const &entry)
void clearProperty(BareEntryID const &elementID, string propertyKey)
clear previously recorded state for a given element and specific property
static BareEntryID const & getID(Record const &entry)
static StateData::const_iterator findProperty(StateData const &stateSet, string propertyKey)
static GenNode const & getState(Record const &entry, string propertyKey)
Access the recorded state mark, if any.
void record(BareEntryID const &elementID, GenNode const &stateMark)
remember the state mark for the denoted element
GenNode const & retrieve(BareEntryID const &elementID, string propertyKey) const
retrieve captured state
iterator find(BareEntryID const &elementID) const
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Bare symbolic and hash ID used for accounting of asset like entries.
Lumiera error handling (C++ interface).
Generic building block for tree shaped (meta)data structures.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Mix-Ins to allow or prohibit various degrees of copying and cloning.
generic data element node within a tree
Definition gen-node.hpp:224
Constructor for a specially crafted 'ref GenNode'.
Definition gen-node.hpp:843
static const Ref NO
symbolic ID ref "_NO_"
Definition gen-node.hpp:862
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...