SMACC2
Loading...
Searching...
No Matches
state_traits.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/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
23namespace smacc2
24{
25template <typename T, typename TransitionTagName>
27{
28 template <typename U, void (U::*)(TransitionTagName)>
29 struct Check;
30 template <typename U>
31 static char func(Check<U, &U::onExit> *);
32 template <typename U>
33 static int func(...);
34
35public:
37 enum
38 {
39 value = sizeof(func<T>(0)) == sizeof(char)
40 };
41};
42
43template <typename TState, typename TTransitionTagName>
44void specificNamedOnExit(TState & st, TTransitionTagName tn, std::true_type)
45{
46 st.onExit(tn);
47}
48
49template <typename TState, typename TTransitionTagName>
50void specificNamedOnExit(TState &, TTransitionTagName, std::false_type)
51{
52}
53
54template <typename TState, typename TTransitionTagName>
55void specificNamedOnExit(TState & m, TTransitionTagName tn)
56{
58 m, tn,
59 std::integral_constant<bool, HasSpecificNamedOnExit<TState, TTransitionTagName>::value>());
60}
61
62//-------------------------------------------------
63
64template <typename T>
66{
67 template <typename U, void (U::*)()>
68 struct Check;
69 template <typename U>
70 static char func(Check<U, &U::onExit> *);
71 template <typename U>
72 static int func(...);
73
74public:
76 enum
77 {
78 value = sizeof(func<T>(0)) == sizeof(char)
79 };
80};
81
82template <typename TState>
83void standardOnExit(TState & st, std::true_type)
84{
85 st.onExit();
86}
87
88template <typename TState>
89void standardOnExit(TState &, std::false_type)
90{
91}
92
93template <typename TState>
94void standardOnExit(TState & m)
95{
96 standardOnExit(m, std::integral_constant<bool, HasStandardOnExit<TState>::value>());
97}
98
99} // namespace smacc2
static char func(Check< U, &U::onExit > *)
HasSpecificNamedOnExit type
static char func(Check< U, &U::onExit > *)
HasStandardOnExit type
void specificNamedOnExit(TState &st, TTransitionTagName tn, std::true_type)
void standardOnExit(TState &st, std::true_type)