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)
5  2015, 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 
30 #ifndef STAGE_CTRL_NEXUS_H
31 #define STAGE_CTRL_NEXUS_H
32 
33 
34 #include "lib/error.hpp"
35 #include "lib/nocopy.hpp"
36 #include "lib/idi/genfunc.hpp"
39 #include "stage/ctrl/bus-term.hpp"
40 #include "stage/model/tangible.hpp"
41 #include "lib/idi/entry-id.hpp"
42 
43 #include <unordered_map>
44 
45 
46 namespace stage {
47 namespace ctrl{
48 
49 
50 
67  class Nexus
68  : public BusTerm
70  {
71  typedef std::unordered_map<EntryID, Tangible*, EntryID::UseEmbeddedHash> RoutingTable;
72 
73  RoutingTable routingTable_;
74 
75 
76  protected:
82  virtual bool
83  mark (ID subject, GenNode const& mark) override
84  {
85  auto entry = routingTable_.find (subject);
86  if (entry == routingTable_.end())
87  return false;
88  else
89  {
90  entry->second->mark (mark);
91  return true;
92  }
93  }
94 
98  virtual size_t
99  markAll (GenNode const& mark) override
100  {
101  for (auto& entry : routingTable_)
102  this->mark (entry.first, mark);
103  return routingTable_.size();
104  }
105 
106 
115  virtual bool
116  change (ID subject, MutationMessage&& diff) override
117  {
118  auto entry = routingTable_.find (subject);
119  if (entry == routingTable_.end())
120  return false;
121  else
122  {
123  Tangible& target = *entry->second;
124  lib::diff::DiffApplicator<Tangible> applicator{target};
125  applicator.consume (move(diff));
126  return true;
127  }
128  }
129 
130 
141  virtual BusTerm&
142  routeAdd (ID identity, Tangible& newNode) override
143  {
144  routingTable_[identity] = &newNode;
145  return *this;
146  }
147 
148 
152  virtual void
153  routeDetach (ID node) noexcept override
154  {
155  routingTable_.erase (node);
156  }
157 
158 
159  virtual operator string() const
160  {
161  return lib::idi::instanceTypeID(this);
162  }
163 
164 
165  public:
166  size_t
167  size() const
168  {
169  return routingTable_.size();
170  }
171 
172  explicit
173  Nexus (BusTerm& uplink_to_CoreService, ID identity =lib::idi::EntryID<Nexus>())
174  : BusTerm(identity, uplink_to_CoreService)
175  { }
176 
177  ~Nexus()
178  {
179  if (0 < size())
180  ERROR (stage, "Some UI components are still connected to the backbone.");
181  }
182  };
183 
184 
185 
186 }} // namespace stage::ctrl
187 #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:96
virtual bool mark(ID subject, GenNode const &mark) override
route mark messages down to the individual Tangible.
Definition: nexus.hpp:83
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:142
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:126
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:99
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:116
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
virtual void routeDetach(ID node) noexcept override
deactivate and remove a down-link route.
Definition: nexus.hpp:153
Central hub of the UI-Bus.
Definition: nexus.hpp:67
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:116
Bare symbolic and hash ID used for accounting of asset like entries.
generic data element node within a tree
Definition: gen-node.hpp:222
generic builder to apply a diff description to a given target data structure.