$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 
24 #include <memory> // for unique_ptr<>, make_unique<>
25 #include <string> // for string
26 
27 #include <cloe/core.hpp> // for Conf, Json
28 #include <cloe/trigger.hpp> // for Event, EventFactory, Action, ActionFactory
29 #include <cloe/trigger/helper_macros.hpp> // for _X_FACTORY, _X_CALLBACK
30 
57 #define DEFINE_NIL_EVENT(xName, xname, xdescription) \
58  class xName : public ::cloe::Event { \
59  public: \
60  explicit xName(const std::string& name) : ::cloe::Event(name) {} \
61  ::cloe::EventPtr clone() const override { return std::make_unique<xName>(name()); } \
62  void to_json(::cloe::Json&) const override {} \
63  bool operator()(const ::cloe::Sync&) const { return true; } \
64  }; \
65  \
66  class _X_FACTORY(xName) : public ::cloe::EventFactory { \
67  public: \
68  using EventType = xName; \
69  \
70  _X_FACTORY(xName)() : ::cloe::EventFactory(xname, xdescription) {} \
71  \
72  std::unique_ptr<::cloe::Event> make(const ::cloe::Conf&) const override { \
73  return std::make_unique<xName>(this->name()); \
74  } \
75  \
76  std::unique_ptr<::cloe::Event> make(const std::string&) const override { \
77  return std::make_unique<xName>(this->name()); \
78  } \
79  }; \
80  \
81  using _X_CALLBACK(xName) = ::cloe::DirectCallback<xName>;