SMACC2
smacc_state_info.cpp
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#include <smacc2/common.hpp>
23
24namespace smacc2
25{
26using namespace smacc2::introspection;
27
28std::map<const std::type_info *, std::vector<ClientBehaviorInfoEntry>>
30std::map<
31 const std::type_info *,
32 std::vector<std::shared_ptr<smacc2::introspection::SmaccStateReactorInfo>>>
34std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>>
36
38 const std::type_info * tid, std::shared_ptr<SmaccStateInfo> parentState,
39 std::shared_ptr<SmaccStateMachineInfo> stateMachineInfo)
40{
41 tid_ = tid;
42 parentState_ = parentState;
43 stateMachine_ = stateMachineInfo;
44
45 if (parentState_ != nullptr) depth_ = parentState->depth_ + 1;
46}
47
48void SmaccStateInfo::getAncestors(std::list<const SmaccStateInfo *> & ancestorsList) const
49{
50 ancestorsList.push_front(this);
51 if (parentState_ != nullptr)
52 {
53 this->parentState_->getAncestors(ancestorsList);
54 }
55}
56
58{
59 if (this->children_.size() == 0)
60 {
61 if (this->parentState_ != nullptr)
62 {
64 }
65 else
66 {
68 }
69 }
70 else
71 {
73 }
74}
75
76rclcpp::Node::SharedPtr SmaccStateInfo::getNode() { return this->stateMachine_->getNode(); }
77
79{
80 if (parentState_ == nullptr)
81 return this->toShortName();
82 else
83 return this->parentState_->getFullPath() + "/" + this->toShortName();
84}
85
86const std::string & SmaccStateInfo::toShortName() const { return this->demangledStateName; }
87
89{
90 return demangleSymbol(this->fullStateName.c_str());
91}
92//---------------------------------------------
93SmaccEventInfo::SmaccEventInfo(std::shared_ptr<TypeInfo> eventType) { this->eventType = eventType; }
94
96{
97 if (eventType->templateParameters.size() > 0)
98 {
99 auto eventsourcename = demangleSymbol(eventType->templateParameters[0]->getFullName().c_str());
100 return eventsourcename;
101 }
102 else
103 {
104 return "";
105 }
106}
107
109{
110 return demangleSymbol(eventType->getNonTemplatedTypeName().c_str());
111}
112
114{
115 if (eventType->templateParameters.size() > 1)
116 {
117 return demangleSymbol(eventType->templateParameters[1]->getFullName().c_str());
118 }
119 else
120 {
121 return "";
122 }
123}
124
125} // namespace smacc2
SmaccStateInfo(const std::type_info *tid, std::shared_ptr< SmaccStateInfo > parentState, std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo)
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
void getAncestors(std::list< const SmaccStateInfo * > &ancestorsList) const
const std::string & toShortName() const
std::vector< std::shared_ptr< SmaccStateInfo > > children_
std::shared_ptr< SmaccStateInfo > parentState_
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
std::shared_ptr< SmaccStateMachineInfo > stateMachine_
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo
std::string demangleSymbol(const std::string &name)
SmaccEventInfo(std::shared_ptr< TypeInfo > eventType)
std::shared_ptr< TypeInfo > eventType