C++ YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// Copyright (C) 2025 Miguel Ángel González Santamarta
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#ifndef YASMIN__TYPES_HPP_
17#define YASMIN__TYPES_HPP_
18
19#include <functional>
20#include <memory>
21#include <set>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26namespace yasmin {
27
29#define YASMIN_SHARED_PTR_ALIAS(...) \
30 using SharedPtr = std::shared_ptr<__VA_ARGS__>; \
31 using ConstSharedPtr = std::shared_ptr<const __VA_ARGS__>; \
32 template <typename... Args> \
33 static std::shared_ptr<__VA_ARGS__> make_shared(Args &&...args) { \
34 return std::make_shared<__VA_ARGS__>(std::forward<Args>(args)...); \
35 }
36
38#define YASMIN_UNIQUE_PTR_ALIAS(...) \
39 using UniquePtr = std::unique_ptr<__VA_ARGS__>; \
40 template <typename... Args> \
41 static std::unique_ptr<__VA_ARGS__> make_unique(Args &&...args) { \
42 return std::unique_ptr<__VA_ARGS__>( \
43 new __VA_ARGS__(std::forward<Args>(args)...)); \
44 }
45
47#define YASMIN_WEAK_PTR_ALIAS(...) \
48 using WeakPtr = std::weak_ptr<__VA_ARGS__>; \
49 using ConstWeakPtr = std::weak_ptr<const __VA_ARGS__>;
50
52#define YASMIN_PTR_ALIASES(ClassName) \
53 \
56 YASMIN_SHARED_PTR_ALIAS(ClassName) \
57 \
58 \
61 YASMIN_UNIQUE_PTR_ALIAS(ClassName) \
62 \
63 \
66 YASMIN_WEAK_PTR_ALIAS(ClassName)
67
69class State;
71class Blackboard;
73class StateMachine;
75class Concurrence;
76
78using StringSet = std::set<std::string>;
80using StringMap = std::unordered_map<std::string, std::string>;
83using Outcomes = StringSet;
87using OutcomeMap = std::unordered_map<std::string, StateOutcomeMap>;
92using TransitionsMap = std::unordered_map<std::string, Transitions>;
94using Remappings = StringMap;
96using RemappingsMap = std::unordered_map<std::string, Remappings>;
101using BlackboardPtr = std::shared_ptr<Blackboard>;
103using StatePtr = std::shared_ptr<State>;
105using StateMachinePtr = std::shared_ptr<StateMachine>;
107using ConcurrencePtr = std::shared_ptr<Concurrence>;
108
110using StateMap = std::unordered_map<std::string, std::shared_ptr<State>>;
111
113using CbStateCallback = std::function<std::string(std::shared_ptr<Blackboard>)>;
114
115} // namespace yasmin
116
117#endif // YASMIN__TYPES_HPP_
Runs a series of states in parallel.
Definition concurrence.hpp:45
A class that implements a state machine with a set of states, transitions, and callback mechanisms fo...
Definition state_machine.hpp:40
Definition blackboard.hpp:31
std::unordered_map< std::string, StateOutcomeMap > OutcomeMap
Map of outcomes to state outcome maps.
Definition types.hpp:81
std::unordered_map< std::string, std::shared_ptr< State > > StateMap
Map of state names to state pointers.
Definition types.hpp:104
StringMap Transitions
Map of transitions (string to string)
Definition types.hpp:84
StringSet Outcomes
Set of possible outcomes for states.
Definition types.hpp:77
std::unordered_map< std::string, Remappings > RemappingsMap
Map of keys to remappings.
Definition types.hpp:90
std::shared_ptr< Concurrence > ConcurrencePtr
Shared pointer to Concurrence.
Definition types.hpp:101
StringMap StateOutcomeMap
Map of state names to their outcomes.
Definition types.hpp:79
std::shared_ptr< StateMachine > StateMachinePtr
Shared pointer to StateMachine.
Definition types.hpp:99
std::unordered_map< std::string, std::string > StringMap
Map from string to string.
Definition types.hpp:74
std::set< std::string > StringSet
Set of strings.
Definition types.hpp:72
std::unordered_map< std::string, Transitions > TransitionsMap
Map of state names to transitions.
Definition types.hpp:86
std::shared_ptr< State > StatePtr
Shared pointer to State.
Definition types.hpp:97
std::shared_ptr< Blackboard > BlackboardPtr
Shared pointer to Blackboard.
Definition types.hpp:95
StringMap Remappings
Map of remappings (string to string)
Definition types.hpp:88
std::function< std::string(std::shared_ptr< Blackboard >)> CbStateCallback
Callback function type for CbState.
Definition types.hpp:107
StringMap TypeRegistry
Registry for type information.
Definition types.hpp:92