Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
handling-pattern.hpp
Go to the documentation of this file.
1/*
2 HANDLILNG-PATTERN.hpp - A skeleton for executing commands, including standard implementations
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
35#ifndef CONTROL_HANDLING_PATTERN_H
36#define CONTROL_HANDLING_PATTERN_H
37
38#include "lib/error.hpp"
39#include "lib/symbol.hpp"
40
41#include <string>
42
43
44
45namespace steam {
46namespace control {
47
48 using std::string;
49 using lib::Symbol;
50
51
52 class CommandImpl;
53
54
63 {
64 const string log_;
65
66 public:
67 bool isValid() const;
68 void maybeThrow() const;
69 operator bool() const { return isValid(); }
70
71 protected:
72 ExecResult () { }
73 ExecResult (lumiera::Error const&);
74
75 friend class HandlingPattern;
76 };
77
78
79
88 {
89 public:
90 virtual ~HandlingPattern() {}
91
100
101 static ID defaultID() { return DUMMY; }
102
104 static HandlingPattern const& get (ID id);
105
106
107
112 ExecResult exec (CommandImpl& command, string) const;
113
115 ExecResult undo (CommandImpl& command, string) const;
116
117 explicit operator bool() const { return isValid(); }
118 virtual bool isValid() const =0;
119
120 protected:
121
122 virtual void performExec (CommandImpl& command) const =0;
123 virtual void performUndo (CommandImpl& command) const =0;
124
125 private:
127
128 ExecResult invoke (CommandImpl&, string id, Action) const;
129 };
130
131
132
133 inline ExecResult
135 {
136 return this->invoke (command, id, &HandlingPattern::performExec);
137 }
138
139 inline ExecResult
141 {
142 return this->invoke (command, id, &HandlingPattern::performUndo);
143 }
144
145
146
147
148}} // namespace steam::control
149#endif
Token or Atom with distinct identity.
Definition symbol.hpp:120
Interface and Base definition for all Lumiera Exceptions.
Definition error.hpp:65
Steam-Layer Command implementation.
Result (Status) of command execution.
ExecResult()
default: command executed successfully
Interface: Operation Skeleton how to invoke or undo a command.
virtual ~HandlingPattern()
this is an interface
ExecResult undo(CommandImpl &command, string) const
likewise invoke the configured UNDO operation
virtual bool isValid() const =0
virtual void performUndo(CommandImpl &command) const =0
ExecResult invoke(CommandImpl &, string id, Action) const
virtual void performExec(CommandImpl &command) const =0
ExecResult exec(CommandImpl &command, string) const
main functionality: invoke a command, detect errors.
void(HandlingPattern::* Action)(CommandImpl &) const
Lumiera error handling (C++ interface).
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.
Marker types to indicate a literal string and a Symbol.