SMACC2
Loading...
Searching...
No Matches
sr_conditional.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16#include <boost/statechart/event.hpp>
17#include <map>
18#include <smacc2/common.hpp>
20#include <typeinfo>
21
22namespace smacc2
23{
24namespace state_reactors
25{
26template <typename TSource, typename TObjectTag = EmptyObjectTag>
27struct EvConditionalTrue : sc::event<EvConditionalTrue<TSource, TObjectTag>>
28{
29};
30
31template <typename TEv>
33{
34private:
35 std::map<const std::type_info *, bool> triggeredEvents;
36 bool conditionFlag = false;
37
38public:
39 SrConditional(std::function<bool(TEv *)> sr_conditionalFunction)
40 {
41 std::function<void(TEv *)> callback = [this, sr_conditionalFunction](TEv * ev)
42 {
43 bool condition = sr_conditionalFunction(ev);
44 this->conditionFlag = condition;
45 };
46
47 this->createEventCallback(callback);
48 }
49
50 bool triggers() { return this->conditionFlag; }
51};
52} // namespace state_reactors
53} // namespace smacc2
void createEventCallback(void(TClass::*callback)(T *), TClass *object)
SrConditional(std::function< bool(TEv *)> sr_conditionalFunction)
std::map< const std::type_info *, bool > triggeredEvents