Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
command-registry.hpp
Go to the documentation of this file.
1/*
2 COMMAND-REGISTRY.hpp - steam-Command object registration and storage management
3
4 Copyright (C)
5 2009, 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
49#ifndef CONTROL_COMMAND_REGISTRY_H
50#define CONTROL_COMMAND_REGISTRY_H
51
52#include "lib/error.hpp"
53#include "lib/depend.hpp"
54#include "lib/sync.hpp"
55#include "include/logging.h"
56#include "lib/nocopy.hpp"
57#include "lib/util.hpp"
58
63
64#include <boost/functional/hash.hpp>
65#include <unordered_map>
66#include <memory>
67#include <string>
68#include <map>
69
70
71
72namespace steam {
73namespace control {
74
75 using boost::hash;
76 using std::shared_ptr;
77 using std::unordered_map;
80 using util::contains;
81 using std::string;
82 using std::map;
83
84
92 {
93 bool
94 operator() (const Command *pC1, const Command *pC2) const
95 {
96 return (!pC1 and pC2)
97 or ( pC1 and pC2 and (*pC1 < *pC2));
98 }
99 };
100
101
110 : public lib::Sync<>
112 {
113 // using a hashtable to implement the index
116
120
121
122 public:
124
125
127 {
128 if (0 < index_size())
129 TRACE (command, "Shutting down Command system...");
131 ridx_.clear();
132 index_.clear();
133 }
134
135
136
142 void
144 {
145 Lock sync{this};
146
148 if (contains (index_,cmdID) || contains(ridx_, &commandHandle))
149 commandHandle.duplicate_detected(cmdID);
150
151 Command& indexSlot = index_[cmdID];
153 ridx_[&indexSlot] = cmdID;
154
155 ENSURE (contains(ridx_, &indexSlot));
156 ENSURE (contains(index_, cmdID));
157 }
158
159
164 bool
166 {
167 Lock sync{this};
168
169 bool actually_remove = contains (index_,cmdID);
170 if (actually_remove)
171 {
172 ridx_.erase(& index_[cmdID]);
173 index_.erase(cmdID);
174 }
175 ENSURE (!contains (index_,cmdID));
176 return actually_remove;
177 }
178
179
188 Command
190 {
191 Lock sync{this};
192 return getValue_or_default (index_, cmdID, Command() );
193 } //if not found
194
195
200 Symbol
202 {
203 Lock sync{this};
204 return getValue_or_default (ridx_, &cmdInstance, Symbol::BOTTOM );
205 } //used as Key
206
207
208 size_t
210 {
211 return index_.size();
212 }
213
214
215 size_t
217 {
219 }
220
221
227 template< typename SIG_OPER
228 , typename SIG_CAPT
229 , typename SIG_UNDO
230 >
235 {
236
237 // derive the storage type necessary
238 // to hold the command arguments and UNDO memento
241
243
245 }
246
247
248
249
265
266
267 };
268
269
270}} // namespace steam::control
271#endif
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Token or Atom with distinct identity.
Definition symbol.hpp:120
static Symbol BOTTOM
Definition symbol.hpp:124
scoped guard to control the actual locking.
Definition sync.hpp:228
Facility for monitor object based locking.
Definition sync.hpp:210
Foundation for a custom allocation manager, tracking the created objects by smart-ptrs.
shared_ptr< XX > create(ARGS &&...args)
Steam-Layer Command implementation.
Registry managing command implementation objects (Singleton).
void track(Symbol cmdID, Command const &commandHandle)
register a command (Frontend) under the given ID.
unordered_map< Symbol, Command, hash< Symbol > > CmdIndex
map< const Command *, Symbol, order_by_impl > ReverseIndex
Symbol findDefinition(Command const &cmdInstance) const
search the command index for a definition
shared_ptr< CommandImpl > newCommandImpl(function< SIG_OPER > &operFunctor, function< SIG_CAPT > &captFunctor, function< SIG_UNDO > &undoFunctor)
set up a new command implementation frame
static lib::Depend< CommandRegistry > instance
storage for the singleton factory used to access CommandRegistry
Command queryIndex(Symbol cmdID)
query the command index by ID
shared_ptr< CommandImpl > createCloneImpl(CommandImpl const &refObject)
create an allocation for holding a clone of the given CommandImpl data.
Definition command.cpp:219
bool remove(Symbol cmdID)
remove the given command registration.
Handle object representing a single Command instance to be used by client code.
Definition command.hpp:120
Case< Ret, Args >::Memento Memento
Any copy and copy construction prohibited.
Definition nocopy.hpp:38
Metaprogramming helpers for deriving the precise function signatures necessary to implement a given c...
A passive container record holding the actual command arguments & UNDO state.
Steam-Layer command frontend.
Singleton services and Dependency Injection.
Lumiera error handling (C++ interface).
This header is for including and configuring NoBug.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Steam-Layer implementation namespace root.
MAP::mapped_type getValue_or_default(MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type defaultVal)
fetch value from a Map, or return a default if not found
Definition util.hpp:275
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Helper for building a std::map with Command* as keys.
bool operator()(const Command *pC1, const Command *pC2) const
Object Monitor based synchronisation.
Abstract foundation for building custom allocation managers.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...