Skip to content

Commit

Permalink
Feature/erikzenker/fill unexpected event handler only when needed (#164)
Browse files Browse the repository at this point in the history
* fix: Set correct benchmark include
* feat: Fill unexpected event handlers only when unexpected event handler is present
  • Loading branch information
erikzenker authored Jun 29, 2021
1 parent d32a4dd commit d673f66
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion benchmark/complex/euml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
#define FUSION_MAX_VECTOR_SIZE 50
#define BOOST_MPL_LIMIT_VECTOR_SIZE 50
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/euml/euml.hpp>
#include <boost/msm/front/euml/stl.hpp>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/complex/euml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define BOOST_MPL_LIMIT_LIST_SIZE 50
#define BOOST_MPL_LIMIT_STRING_SIZE 64
#define MPLLIBS_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/euml2/euml2.hpp>
#include <boost/msm/front/state_machine_def.hpp>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/complex/sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/statechart/event.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state_machine.hpp>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/complex/sml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/sml.hpp>
#include <cstdlib>

Expand Down
2 changes: 1 addition & 1 deletion benchmark/complex/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <cstdlib>

struct e1 {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/complex/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <cstdio>
#include <cstdlib>
#include <type_traits>
Expand Down
7 changes: 5 additions & 2 deletions benchmark/components/fill_dispatch_table_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ using namespace hsm;

int main()
{
auto statesMap = make_states_map(state<ComplexStateMachine>);
auto rootState = state<ComplexStateMachine>;
auto statesMap = make_states_map(rootState);
auto dispatchTables = make_dispatch_tables(rootState);
auto optionalDependencies = boost::hana::make_tuple();

fill_dispatch_table_with_external_transitions(
state<ComplexStateMachine>, statesMap, boost::hana::make_tuple());
rootState, dispatchTables, statesMap, optionalDependencies);

return 0;
}
4 changes: 2 additions & 2 deletions benchmark/simple/euml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/euml/euml.hpp>
#include <boost/msm/front/euml/stl.hpp>
#include <boost/msm/front/state_machine_def.hpp>

namespace msm = boost::msm;
namespace mpl = boost::mpl;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/simple/euml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_MPL_LIMIT_STRING_SIZE 64
#define MPLLIBS_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/euml2/euml2.hpp>
#include <boost/msm/front/state_machine_def.hpp>

namespace msm = boost::msm;

Expand Down
2 changes: 1 addition & 1 deletion benchmark/simple/hsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <hsm/hsm.h>

using namespace hsm;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/simple/sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/statechart/event.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/transition.hpp>

namespace sc = boost::statechart;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/simple/sml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "benchmark.hpp"
#include "../benchmark.hpp"
#include <boost/sml.hpp>

namespace sml = boost::sml;
Expand Down
27 changes: 16 additions & 11 deletions include/hsm/details/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ template <class RootState, class... OptionalParameters> class sm {
"Transition table needs to have at least one initial state");

auto optionalDependency = bh::make_basic_tuple(std::ref(optionalParameters)...);
// std::cout << (bh::at_c<0>(optionalDependency).get().callCount) << std::endl;
fill_unexpected_event_handler_tables(
rootState,
m_statesMap,
m_unexpectedEventHandlerTables,
get_unexpected_event_handler(rootState),
optionalDependency);

if constexpr (has_unexpected_event_handler(rootState)) {
fill_unexpected_event_handler_tables(
rootState,
m_statesMap,
m_unexpectedEventHandlerTables,
get_unexpected_event_handler(rootState),
optionalDependency);
}

fill_dispatch_table(optionalDependency);
fill_initial_state_table(rootState, m_initial_states);
fill_initial_state_table(rootState, m_history);
Expand Down Expand Up @@ -272,10 +275,12 @@ template <class RootState, class... OptionalParameters> class sm {

template <class Event> auto call_unexpected_event_handler(Event& event)
{
// TODO: What todo in a multi region state machine?
m_unexpectedEventHandlerTables[bh::typeid_(event)]
.at(m_currentCombinedState.at(0))
->executeHandler(event);
if constexpr (has_unexpected_event_handler(rootState)) {
// TODO: What todo in a multi region state machine?
m_unexpectedEventHandlerTables[bh::typeid_(event)]
.at(m_currentCombinedState.at(0))
->executeHandler(event);
}
}

auto currentState(Region region)
Expand Down

0 comments on commit d673f66

Please sign in to comment.