iceoryx_doc  1.0.1
action.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_UTILS_DESIGN_PATTERN_ACTION_HPP
17 #define IOX_UTILS_DESIGN_PATTERN_ACTION_HPP
18 
19 namespace DesignPattern
20 {
21 // base class for void(Arg) calls - known as commands
24 template <typename Arg>
25 class Command
26 {
27  public:
28  void operator()(Arg& arg)
29  {
30  exec(arg);
31  }
32 
33  virtual ~Command()
34  {
35  }
36 
37  protected:
38  virtual void exec(Arg& arg)
39  {
40  (void)arg;
41  }
42 };
43 
44 // base class for void(void) calls - also known as actions
45 template <>
46 class Command<void>
47 {
48  public:
49  void operator()()
50  {
51  exec();
52  }
53 
54  virtual ~Command()
55  {
56  }
57 
58  protected:
59  virtual void exec(){};
60 };
61 
62 using Action = Command<void>;
63 } // namespace DesignPattern
64 
65 #endif // IOX_UTILS_DESIGN_PATTERN_ACTION_HPP
Definition: action.hpp:47
Definition: action.hpp:26