SMACC2
Loading...
Searching...
No Matches
eg_conditional_generator.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 <functional>
18#include <smacc2/common.hpp>
21#include <typeinfo>
22
23namespace smacc2
24{
25namespace event_generators
26{
27template <typename TSource, typename TState>
28struct EvTrue : sc::event<EvTrue<TSource, TState>>
29{
30};
31
32template <typename TSource, typename TState>
33struct EvFalse : sc::event<EvFalse<TSource, TState>>
34{
35};
36
38{
41};
42
43//-----------------------------------------------------------------------
45{
46public:
48 ConditionalGeneratorMode mode, std::function<bool()> updatePredicate = nullptr);
50
51 void onEntry() override;
52
53 template <typename TState, typename TSource>
55 {
56 this->postEventTrue = [this]() { this->postEvent<EvTrue<TSource, TState>>(); };
57 this->postEventFalse = [this]() { this->postEvent<EvFalse<TSource, TState>>(); };
58 }
59
60 virtual void update() override;
62
63 void setPredicateFunction(std::function<bool()> updatePredicate);
64
65private:
67 std::function<void()> postEventTrue;
68 std::function<void()> postEventFalse;
69 std::function<bool()> updatePredicate_;
70};
71} // namespace event_generators
72} // namespace smacc2
void setPredicateFunction(std::function< bool()> updatePredicate)