$darkmode
evaluate_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  */
46 #pragma once
47 #ifndef CLOE_TRIGGER_EVALUATE_EVENT_HPP_
48 #define CLOE_TRIGGER_EVALUATE_EVENT_HPP_
49 
50 #include <functional> // for function<>
51 #include <string> // for string
52 
53 #include <cloe/registrar.hpp> // for DirectCallback
54 #include <cloe/trigger.hpp> // for Event, EventFactory
55 
56 namespace cloe {
57 namespace events {
58 
59 class Evaluate : public Event {
60  public:
61  Evaluate(const std::string& name, const std::string& repr, std::function<bool(double)> f)
62  : Event(name), repr_(repr), func_(f) {}
63  EventPtr clone() const override { return std::make_unique<Evaluate>(name(), repr_, func_); }
64  bool operator()(const Sync&, double d);
65  void to_json(Json& j) const override;
66 
67  private:
68  std::string repr_;
69  std::function<bool(double)> func_;
70 };
71 
72 class EvaluateFactory : public EventFactory {
73  public:
74  using EventType = Evaluate;
75  EvaluateFactory(const std::string& name, const std::string& desc) : EventFactory(name, desc) {}
76  TriggerSchema schema() const override;
77  EventPtr make(const Conf& c) const override;
78  EventPtr make(const std::string& s) const override;
79 };
80 
82 
83 } // namespace events
84 } // namespace cloe
85 
86 #endif // CLOE_TRIGGER_EVALUATE_EVENT_HPP_
Definition: conf.hpp:74
Definition: registrar.hpp:45
Definition: evaluate_event.hpp:72
Definition: sync.hpp:35
Definition: coordinator.hpp:36
Definition: trigger.hpp:487
Definition: trigger.hpp:300
std::string name() const
Definition: entity.hpp:68
void to_json(Json &j) const override
Definition: evaluate_event.cpp:46
EventPtr clone() const override
Definition: evaluate_event.hpp:63
Definition: evaluate_event.hpp:59
Definition: trigger.hpp:207