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