Program Listing for File types.hpp

Return to documentation for file (include/yasmin/types.hpp)

// Copyright (C) 2025 Miguel Ángel González Santamarta
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#ifndef YASMIN__TYPES_HPP_
#define YASMIN__TYPES_HPP_

#include <functional>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

namespace yasmin {

#define YASMIN_SHARED_PTR_ALIAS(...)                                           \
  using SharedPtr = std::shared_ptr<__VA_ARGS__>;                              \
  using ConstSharedPtr = std::shared_ptr<const __VA_ARGS__>;                   \
  template <typename... Args>                                                  \
  static std::shared_ptr<__VA_ARGS__> make_shared(Args &&...args) {            \
    return std::make_shared<__VA_ARGS__>(std::forward<Args>(args)...);         \
  }

#define YASMIN_UNIQUE_PTR_ALIAS(...)                                           \
  using UniquePtr = std::unique_ptr<__VA_ARGS__>;                              \
  template <typename... Args>                                                  \
  static std::unique_ptr<__VA_ARGS__> make_unique(Args &&...args) {            \
    return std::unique_ptr<__VA_ARGS__>(                                       \
        new __VA_ARGS__(std::forward<Args>(args)...));                         \
  }

#define YASMIN_WEAK_PTR_ALIAS(...)                                             \
  using WeakPtr = std::weak_ptr<__VA_ARGS__>;                                  \
  using ConstWeakPtr = std::weak_ptr<const __VA_ARGS__>;

#define YASMIN_PTR_ALIASES(ClassName)                                          \
                                                                          \
  YASMIN_SHARED_PTR_ALIAS(ClassName)                                           \
                                                                               \
                                                                          \
  YASMIN_UNIQUE_PTR_ALIAS(ClassName)                                           \
                                                                               \
                                                                          \
  YASMIN_WEAK_PTR_ALIAS(ClassName)

class State;
class Blackboard;
class StateMachine;
class Concurrence;

using StringSet = std::set<std::string>;
using StringMap = std::unordered_map<std::string, std::string>;

using Outcomes = StringSet;
using StateOutcomeMap = StringMap;
using OutcomeMap = std::unordered_map<std::string, StateOutcomeMap>;

using Transitions = StringMap;
using TransitionsMap = std::unordered_map<std::string, Transitions>;
using Remappings = StringMap;
using RemappingsMap = std::unordered_map<std::string, Remappings>;
using TypeRegistry = StringMap;

using BlackboardPtr = std::shared_ptr<Blackboard>;
using StatePtr = std::shared_ptr<State>;
using StateMachinePtr = std::shared_ptr<StateMachine>;
using ConcurrencePtr = std::shared_ptr<Concurrence>;

using StateMap = std::unordered_map<std::string, std::shared_ptr<State>>;

using CbStateCallback = std::function<std::string(std::shared_ptr<Blackboard>)>;

} // namespace yasmin

#endif // YASMIN__TYPES_HPP_