Lumiera  0.pre.03
»edit your freedom«
nexus.hpp
Go to the documentation of this file.
1 /*
2  NEXUS.hpp - UI-Bus central hub and routing table
3 
4  Copyright (C) Lumiera.org
5  2015, 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 
39 #ifndef STAGE_CTRL_NEXUS_H
40 #define STAGE_CTRL_NEXUS_H
41 
42 
43 #include "lib/error.hpp"
44 #include "lib/nocopy.hpp"
45 #include "lib/idi/genfunc.hpp"
48 #include "stage/ctrl/bus-term.hpp"
49 #include "stage/model/tangible.hpp"
50 #include "lib/idi/entry-id.hpp"
51 
52 #include <unordered_map>
53 
54 
55 namespace stage {
56 namespace ctrl{
57 
58 
59 
76  class Nexus
77  : public BusTerm
79  {
80  typedef std::unordered_map<EntryID, Tangible*, EntryID::UseEmbeddedHash> RoutingTable;
81 
82  RoutingTable routingTable_;
83 
84 
85  protected:
91  virtual bool
92  mark (ID subject, GenNode const& mark) override
93  {
94  auto entry = routingTable_.find (subject);
95  if (entry == routingTable_.end())
96  return false;
97  else
98  {
99  entry->second->mark (mark);
100  return true;
101  }
102  }
103 
107  virtual size_t
108  markAll (GenNode const& mark) override
109  {
110  for (auto& entry : routingTable_)
111  this->mark (entry.first, mark);
112  return routingTable_.size();
113  }
114 
115 
124  virtual bool
125  change (ID subject, MutationMessage&& diff) override
126  {
127  auto entry = routingTable_.find (subject);
128  if (entry == routingTable_.end())
129  return false;
130  else
131  {
132  Tangible& target = *entry->second;
133  lib::diff::DiffApplicator<Tangible> applicator{target};
134  applicator.consume (move(diff));
135  return true;
136  }
137  }
138 
139 
150  virtual BusTerm&
151  routeAdd (ID identity, Tangible& newNode) override
152  {
153  routingTable_[identity] = &newNode;
154  return *this;
155  }
156 
157 
161  virtual void
162  routeDetach (ID node) noexcept override
163  {
164  routingTable_.erase (node);
165  }
166 
167 
168  virtual operator string() const
169  {
170  return lib::idi::instanceTypeID(this);
171  }
172 
173 
174  public:
175  size_t
176  size() const
177  {
178  return routingTable_.size();
179  }
180 
181  explicit
182  Nexus (BusTerm& uplink_to_CoreService, ID identity =lib::idi::EntryID<Nexus>())
183  : BusTerm(identity, uplink_to_CoreService)
184  { }
185 
186  ~Nexus()
187  {
188  if (0 < size())
189  ERROR (stage, "Some UI components are still connected to the backbone.");
190  }
191  };
192 
193 
194 
195 }} // namespace stage::ctrl
196 #endif /*STAGE_CTRL_NEXUS_H*/
Concrete implementation to apply structural changes to hierarchical data structures.
Generic Message with an embedded diff, to describe changes to model elements.
Abstraction: a tangible element of the User Interface.
connection point at the UI-Bus.
Definition: bus-term.hpp:105
virtual bool mark(ID subject, GenNode const &mark) override
route mark messages down to the individual Tangible.
Definition: nexus.hpp:92
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
virtual BusTerm & routeAdd(ID identity, Tangible &newNode) override
add a new down-link connection to the routing table
Definition: nexus.hpp:151
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
Opaque message to effect a structural change on a target, which is likewise only known in an abstract...
Generic functions to build identification schemes.
Attachment point to the UI-Bus.
virtual size_t markAll(GenNode const &mark) override
broadcast a notification to all connected terminal nodes.
Definition: nexus.hpp:108
Mix-Ins to allow or prohibit various degrees of copying and cloning.
virtual bool change(ID subject, MutationMessage &&diff) override
direct a mutation message towards the indicated Tangible.
Definition: nexus.hpp:125
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
virtual void routeDetach(ID node) noexcept override
deactivate and remove a down-link route.
Definition: nexus.hpp:162
Central hub of the UI-Bus.
Definition: nexus.hpp:76
BusTerm(BusTerm &&)=default
may be moved, but not copied, due to the embedded identity
Lumiera error handling (C++ interface).
string instanceTypeID(const TY *const obj)
designation of an distinct object instance
Definition: genfunc.hpp:125
Bare symbolic and hash ID used for accounting of asset like entries.
generic data element node within a tree
Definition: gen-node.hpp:231
generic builder to apply a diff description to a given target data structure.