.. _program_listing_file_include_yasmin_state.hpp: Program Listing for File state.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/yasmin/state.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright (C) 2023 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 . #ifndef YASMIN__STATE_HPP #define YASMIN__STATE_HPP #include #include #include #include #include #ifdef __GNUG__ // If using GCC/G++ #include // For abi::__cxa_demangle #endif #include "yasmin/blackboard/blackboard.hpp" #include "yasmin/logs.hpp" namespace yasmin { class State { protected: std::set outcomes; private: std::atomic_bool canceled{false}; std::atomic_bool running{false}; public: State(std::set outcomes); std::string operator()(std::shared_ptr blackboard); virtual std::string execute(std::shared_ptr blackboard) { (void)blackboard; // Suppress unused parameter warning return ""; } virtual void cancel_state() { YASMIN_LOG_INFO("Canceling state '%s'", this->to_string().c_str()); this->canceled.store(true); } bool is_canceled() const; bool is_running() const; std::set const &get_outcomes(); virtual std::string to_string() { std::string name = typeid(*this).name(); #ifdef __GNUG__ // If using GCC/G++ int status; // Demangle the name using GCC's demangling function char *demangled = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status); if (status == 0) { name = demangled; } free(demangled); #endif return name; // Return the demangled class name } }; } // namespace yasmin #endif // YASMIN__STATE_HPP