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