Skip to content

Commit 76a7933

Browse files
committed
extract to detail::shorten(); added payload_type<T>;
1 parent 60c1452 commit 76a7933

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

include/fsm_cxx/fsm-sm.hh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@ namespace fsm_cxx {
6565
namespace fsm_cxx {
6666
// struct dummy_event {};
6767

68+
namespace detail{
69+
inline std::string shorten(std::string const &s) {
70+
auto pos = s.rfind("::");
71+
return pos == std::string::npos ? s : s.substr(pos + 2);
72+
}
73+
}
74+
6875
struct event_t {
6976
virtual ~event_t() {}
7077
virtual std::string to_string() const { return ""; }
7178
};
7279
template<typename T>
7380
struct event_type : public event_t {
7481
virtual ~event_type() {}
75-
std::string to_string() const { return shorten(std::string(debug::type_name<T>())); }
76-
static std::string shorten(std::string const &s) {
77-
auto pos = s.rfind("::");
78-
return pos == std::string::npos ? s : s.substr(pos + 2);
79-
}
82+
std::string to_string() const { return detail::shorten(std::string(debug::type_name<T>())); }
8083
};
8184

8285
// template<typename EventT>
@@ -109,6 +112,13 @@ namespace fsm_cxx {
109112
friend std::ostream &operator<<(std::ostream &os, payload_t const &o) { return os << o.to_string(); }
110113
bool _ok;
111114
};
115+
116+
template<typename T>
117+
struct payload_type : public payload_t {
118+
virtual ~payload_type() {}
119+
std::string to_string() const { return detail::shorten(std::string(debug::type_name<T>())); }
120+
};
121+
112122
} // namespace fsm_cxx
113123

114124
#define FSM_DEFINE_EVENT(n) \
@@ -746,15 +756,10 @@ namespace fsm_cxx {
746756
}
747757

748758
public:
749-
static std::string state_to_sting(StateT const &state) { return shorten(to_string(state)); }
750-
static std::string state_to_sting(S const &state) { return shorten(to_string(state)); }
759+
static std::string state_to_sting(StateT const &state) { return detail::shorten(to_string(state)); }
760+
static std::string state_to_sting(S const &state) { return detail::shorten(to_string(state)); }
751761

752762
protected:
753-
static std::string shorten(std::string const &s) {
754-
auto pos = s.rfind("::");
755-
return pos == std::string::npos ? s : s.substr(pos + 2);
756-
}
757-
758763
friend std::basic_istream<CharT> &operator>>(std::basic_istream<CharT> &is, machine_t &o) {
759764
CharT c;
760765
is >> c; // TODO process the input stream (is >> c) and convert it to event and trigger

0 commit comments

Comments
 (0)