Lumiera  0.pre.03
»edit your freedom«
handling-patterns.hpp
Go to the documentation of this file.
1 /*
2  HANDLILNG-PATTERNS.hpp - Collection of predefined command handling patterns
3 
4  Copyright (C) Lumiera.org
5  2009, 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 
42 #ifndef CONTROL_HANDLING_PATTERNS_DEF_H
43 #define CONTROL_HANDLING_PATTERNS_DEF_H
44 
45 #include "lib/error.hpp"
46 #include "lib/multifact.hpp"
49 
50 
51 
52 namespace steam {
53 namespace control {
54 
55  namespace { // concrete command handling patterns
56 
57 
58 
59 
66  : public HandlingPattern
67  {
68  bool isValid() const { return true; }
69 
70  void
71  performExec (CommandImpl& command) const override
72  {
73  REQUIRE (command.canExec());
74  command.invokeCapture();
75  command.invokeOperation();
76  }
77 
78  void
79  performUndo (CommandImpl& command) const override
80  {
81  REQUIRE (command.canUndo());
82  command.invokeUndo();
83  }
84  };
85 
86 
87 
94  : public BasicHandlingPattern
95  {
96  void
97  performExec (CommandImpl& command) const override
98  {
99  UNIMPLEMENTED ("actually invoke a command, according to this pattern");
100  }
101 
102  void
103  performUndo (CommandImpl& command) const override
104  {
105  UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
106  }
107 
108  bool
109  isValid() const override
110  {
111  UNIMPLEMENTED ("is this pattern currently able to handle commands?");
112  }
113  };
114 
115 
116 
124  : public BasicHandlingPattern
125  {
126  void
127  performExec (CommandImpl& command) const override
128  {
129  UNIMPLEMENTED ("actually invoke a command, according to this pattern");
130  }
131 
132  void
133  performUndo (CommandImpl& command) const override
134  {
135  UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
136  }
137 
138  bool
139  isValid() const override
140  {
141  UNIMPLEMENTED ("is this pattern currently able to handle commands?");
142  }
143  };
144 
145 
146 
154  : public BasicHandlingPattern
155  {
156  void
157  performExec (CommandImpl& command) const override
158  {
159  UNIMPLEMENTED ("actually invoke a command, according to this pattern");
160  }
161 
162  void
163  performUndo (CommandImpl& command) const override
164  {
165  UNIMPLEMENTED ("actually undo the effect of a command, according to this pattern");
166  }
167 
168  bool
169  isValid() const override
170  {
171  UNIMPLEMENTED ("is this pattern currently able to handle commands?");
172  }
173  };
174 
175 
176 
177 
178 
179 
180  /* ======== Handling Pattern Table ========== */
181 
183 
185  HandlingPatternFactory patternTable;
186 
187  HandlingPatternFactory::Singleton<InvokeSyncNoThrow> holder1 (patternTable, HandlingPattern::SYNC);
188  HandlingPatternFactory::Singleton<InvokeSyncThrow> holder2 (patternTable, HandlingPattern::SYNC_THROW);
189  HandlingPatternFactory::Singleton<InvokeAsync> holder3 (patternTable, HandlingPattern::ASYNC);
190  HandlingPatternFactory::Singleton<BasicHandlingPattern> holder4 (patternTable, HandlingPattern::DUMMY);
191 
192 
194  inline HandlingPattern const&
195  getPatternInstance (HandlingPattern::ID id)
196  {
197  REQUIRE (patternTable.contains(id));
198 
199  return patternTable (id);
200  }
201 
202 
203  } // (END) definition of concrete handling patterns
204 
205 
206 
207 
208 
209 
210 
211 }} // namespace steam::control
212 #endif
Handling Pattern: invoke blocking, translate exceptions into an error state.
Handling Pattern: just schedule command to be invoked asynchronously.
Framework for building a configurable factory, to generate families of related objects.
bool canExec() const
< state check: sufficiently defined to be invoked
Top level of the command implementation.
Steam-Layer implementation namespace root.
Handling Pattern: invoke blocking, propagating any exceptions immediately.
HandlingPatternFactory patternTable
holds singleton pattern instances by ID
Factory for creating a family of objects by ID.
Definition: multifact.hpp:262
bool canUndo() const
< state check: has undo state been captured?
HandlingPattern const & getPatternInstance(HandlingPattern::ID id)
access the singleton instance for a given ID
Pre-defined command execution skeletons.
Lumiera error handling (C++ interface).
Handling Pattern Foundation: invoke command directly and without any external intervention.
Steam-Layer Command implementation.
Convenience shortcut for automatically setting up a production line, to fabricate a singleton instanc...
Definition: multifact.hpp:332
Interface: Operation Skeleton how to invoke or undo a command.