$darkmode
nil_event.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_TRIGGER_NIL_EVENT_HPP_
24 #define CLOE_TRIGGER_NIL_EVENT_HPP_
25 
26 #include <memory> // for unique_ptr<>, make_unique<>
27 #include <string> // for string
28 
29 #include <cloe/core.hpp> // for Conf, Json
30 #include <cloe/trigger.hpp> // for Event, EventFactory, Action, ActionFactory
31 #include <cloe/trigger/helper_macros.hpp> // for _X_FACTORY, _X_CALLBACK
32 
59 #define DEFINE_NIL_EVENT(xName, xname, xdescription) \
60  class xName : public ::cloe::Event { \
61  public: \
62  explicit xName(const std::string& name) : ::cloe::Event(name) {} \
63  ::cloe::EventPtr clone() const override { return std::make_unique<xName>(name()); } \
64  void to_json(::cloe::Json&) const override {} \
65  bool operator()(const ::cloe::Sync&) const { return true; } \
66  }; \
67  \
68  class _X_FACTORY(xName) : public ::cloe::EventFactory { \
69  public: \
70  using EventType = xName; \
71  \
72  _X_FACTORY(xName)() : ::cloe::EventFactory(xname, xdescription) {} \
73  \
74  std::unique_ptr<::cloe::Event> make(const ::cloe::Conf&) const override { \
75  return std::make_unique<xName>(this->name()); \
76  } \
77  \
78  std::unique_ptr<::cloe::Event> make(const std::string&) const override { \
79  return std::make_unique<xName>(this->name()); \
80  } \
81  }; \
82  \
83  using _X_CALLBACK(xName) = ::cloe::DirectCallback<xName>;
84 
85 #endif // CLOE_TRIGGER_NIL_EVENT_HPP_