mountcontrol/cxx/tests/fsm_test.cpp
2025-05-30 12:48:15 +03:00

92 lines
2.8 KiB
C++

#include <cxxabi.h>
#include <iostream>
#include <typeinfo>
#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 STN : fsm::MccFsmAbstractState {
static constexpr std::string_view ID = "STN";
using transition_t = trans_table_t<std::pair<EV1, STN>, std::pair<EV2, STN>>;
};
struct ST2 : fsm::MccFsmAbstractState {
static constexpr std::string_view ID = "ST2";
using transition_t = trans_table_t<std::pair<EV2, STN>>;
};
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>>;
};
// using tr_t = fsm::MccFsmAbstractState::trans_table_t<std::pair<EV1, ST1>>;
// static_assert(fsm::traits::fsm_trans_table_c<tr_t>, "!!!!!!!!!!!!!");
// 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);
return 0;
}