mountcontrol/cxx/tests/fsm_test.cpp
2025-06-01 23:41:18 +03:00

131 lines
3.9 KiB
C++

#include <cxxabi.h>
#include <iostream>
#include <typeinfo>
#include "../mcc_finite_state_machine.h"
// #include "../mcc_fsm.h"
using namespace mcc;
struct S {
};
struct EV1 {
static constexpr std::string_view ID = "EV1";
// EV1() = default;
// EV1(EV1&&) = default;
// EV1& operator=(EV1&&) = default;
};
struct EV2 {
static constexpr std::string_view ID = "EV2";
};
struct EV3 {
static constexpr std::string_view ID = "EV3";
};
struct ST1;
struct ST2;
struct STN {
static constexpr std::string_view ID = "STN";
using transition_t = fsm::fsm_transition_table_t<std::pair<EV1, STN>, std::pair<EV2, ST2>>;
};
struct ST3 {
static constexpr std::string_view ID = "ST3";
using transition_t = fsm::fsm_transition_table_t<std::pair<EV1, ST1>, std::pair<EV2, ST2>>;
};
struct ST2 {
static constexpr std::string_view ID = "ST2";
using transition_t = fsm::fsm_transition_table_t<std::pair<EV2, STN>, std::pair<EV3, ST3>>;
};
struct ST1 {
static constexpr std::string_view ID = "ST1";
using transition_t =
fsm::fsm_transition_table_t<std::pair<EV1, ST2>, std::pair<EV2, STN>, std::pair<EV3, STN>, std::pair<EV3, STN>>;
};
// struct STN : fsm::MccFsmAbstractState {
// static constexpr std::string_view ID = "STN";
// using transition_t = trans_table_t<std::pair<EV1, STN>, std::pair<EV2, ST2>>;
// };
// struct ST3 : fsm::MccFsmAbstractState {
// static constexpr std::string_view ID = "ST3";
// using transition_t = trans_table_t<std::pair<EV1, ST1>, std::pair<EV2, ST2>>;
// };
// struct ST2 : fsm::MccFsmAbstractState {
// static constexpr std::string_view ID = "ST2";
// using transition_t = trans_table_t<std::pair<EV2, STN>, std::pair<EV3, ST3>>;
// };
// struct ST1 : fsm::MccFsmAbstractState {
// static constexpr std::string_view ID = "ST1";
// using transition_t = trans_table_t<std::pair<EV1, ST2>, std::pair<EV2, STN>>;
// };
// fsm::MccFiniteStateMachine<ST1> fsm;
int main()
{
/*
typedef fsm::unique_tuple_t<int, float, long, int, double, char, long> ut_t;
std::cout << "type index: " << fsm::unique_tuple_type_index_t<double, ut_t>::index << " (double)\n";
std::cout << "type index: " << fsm::unique_tuple_type_index_t<int, ut_t>::index << " (int)\n";
std::cout << "type index: " << fsm::unique_tuple_type_index_t<long, ut_t>::index << " (long)\n";
// std::cout << "type index: " << fsm::unique_tuple_type_index_t<S, ut_t>::index << " (struct S)\n";
std::cout << typeid(ut_t::tuple_t).name() << "\n";
std::cout << typeid(ut_t::non_unique_t).name() << "\n";
typedef fsm::pair_holder_t<std::pair<int, long>, std::pair<float, double>, std::pair<char, char*>> ph_t;
// using s_t = fsm::pair_holder_find_t<float, ph_t>::result_t;
using s_t = fsm::pair_holder_find_t<S, ph_t>::result_t;
if constexpr (std::is_null_pointer_v<s_t>) {
std::cout << "second type: invalid input type!\n";
} else {
std::cout << "second type: " << typeid(s_t).name() << "\n";
}
using t1_t = fsm::pair_holder_first_t<ph_t>::first_t;
std::cout << "first types: " << typeid(t1_t).name() << "\n";
using t2_t = fsm::pair_holder_second_t<ph_t>::second_t;
std::cout << "second types: " << typeid(t2_t).name() << "\n";
using tp1_t = std::tuple<int, float, long, char>;
using tp2_t = std::tuple<double, float, char*>;
int status;
char* aa = abi::__cxa_demangle(typeid(STN::transition_t::states_t).name(), NULL, NULL, &status);
std::cout << "aa = " << aa << "\n";
char* uu = abi::__cxa_demangle(typeid(STN::transition_t::unique_states_t).name(), NULL, NULL, &status);
std::cout << "uu = " << uu << "\n";
free(aa);
free(uu);
aa = abi::__cxa_demangle(typeid(fsm::MccFiniteStateMachine<ST1>::states_t).name(), NULL, NULL, &status);
std::cout << "states = " << aa << "\n";
free(aa);
*/
fsm::MccFiniteStateMachine(ST1{});
return 0;
}