Lumiera  0.pre.03
»edit your freedom«
model-port-registry.hpp
Go to the documentation of this file.
1 /*
2  MODEL-PORT-REGISTRY.hpp - creating and organising and accessing model ports
3 
4  Copyright (C) Lumiera.org
5  2010, 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 
49 #ifndef STEAM_FIXTURE_MODEL_PORT_REGISTRY_H
50 #define STEAM_FIXTURE_MODEL_PORT_REGISTRY_H
51 
52 #include "lib/error.hpp"
53 #include "lib/optional-ref.hpp"
54 #include "steam/asset/pipe.hpp"
55 #include "steam/asset/struct.hpp"
57 
58 #include <map>
59 
60 namespace steam {
61 namespace fixture {
62 
63  using asset::ID;
64  using asset::Pipe;
65  using asset::Struct;
66 
67  LUMIERA_ERROR_DECLARE (DUPLICATE_MODEL_PORT);
68 
69 
81  {
82 
83  typedef ID<Pipe> PID;
84  typedef ID<Struct> StID;
85 
86  public:
87 
89  class ModelPortDescriptor;
90 
91 
92  static void shutdown ();
93 
94  static ModelPortRegistry*
95  setActiveInstance (ModelPortRegistry& newRegistry);
96 
97  static ModelPortRegistry&
99 
100  static ModelPortDescriptor const&
101  accessDescriptor (PID);
102 
103 
104  ModelPortDescriptor const&
105  definePort (PID pipe, StID element_exposing_this_port);
106 
107  bool contains (PID) const;
108  bool isRegistered (PID) const;
109 
110  ModelPortDescriptor const&
111  get (PID) const;
112 
113 
114  void remove (PID);
115  void clear();
116 
117 
123  void commit();
124 
128  void rollback();
129 
130 
131  private:
133 
134  typedef std::map<PID, ModelPortDescriptor> MPTable;
135 
136  MPTable currentReg_;
137  MPTable transaction_;
138  };
139 
140 
141 
142 
148  {
149  PID id_;
150  StID holder_;
151 
152  protected:
153  ModelPortDescriptor (PID pipe, StID element_exposing_this_port)
154  : id_(pipe)
155  , holder_(element_exposing_this_port)
156  { }
157 
158  friend class ModelPortRegistry;
159 
160  public:
162  : id_(PID::INVALID)
163  , holder_(StID::INVALID)
164  { }
165 
166  // default copy operations permitted
167 
168  bool
169  isValid() const
170  {
171  return bool(id_);
172  }
173 
174  const PID id() const { return id_; }
175  const StID holder() const { return holder_; }
176  };
177 
178 
179 
180 }} // namespace steam::fixture
181 #endif /*STEAM_FIXTURE_MODEL_PORT_REGISTRY_H*/
Organising the output data calculation possibilities.
ModelPortDescriptor const & definePort(PID pipe, StID element_exposing_this_port)
create and register a new model port entry, within the pending transaction
A "processing pipe" represented as Asset.
void clear()
schedule removal of all registry contents.
Optional or switchable link to an existing object.
bool contains(PID) const
does the transaction currently being built already contain a model port registration for the given ID...
void commit()
activate pending model port changes.
a checked, switchable reference.
static lib::OptionalRef< ModelPortRegistry > theGlobalRegistry
storage for the link to the global Registry instance currently in charge
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
static ModelPortDescriptor const & accessDescriptor(PID)
access the globally valid model port for the given pipe.
Steam-Layer implementation namespace root.
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:79
ModelPortDescriptor records are used as actual storage within the model port registration table; they...
static ModelPortRegistry * setActiveInstance(ModelPortRegistry &newRegistry)
switch the implicit link to the global ModelPort registry to point to the given implementation instan...
static void shutdown()
globally deactivate access to model ports
Management facility for tracking model ports.
LUMIERA_ERROR_DECLARE(DUPLICATE_MODEL_PORT)
Attempt to define a new model port with an pipe-ID already denoting an existing port.
static ID INVALID
marker constant denoting a NIL asset
Definition: asset.hpp:116
Lumiera error handling (C++ interface).
static ModelPortRegistry & globalInstance()
access the globally valid registry instance.
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition: struct.hpp:113
void rollback()
discard pending changes.
Asset representation of structural elements within the model.
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:108