コード例 #1
0
ファイル: HumanClientFSM.cpp プロジェクト: matt474/freeorion
void HumanClientFSM::unconsumed_event(const boost::statechart::event_base &event) {
    std::string most_derived_message_type_str = "[ERROR: Unknown Event]";
    const boost::statechart::event_base* event_ptr = &event;
    if (dynamic_cast<const Disconnection*>(event_ptr))
        most_derived_message_type_str = "Disconnection";
#define EVENT_CASE(r, data, name)                                       \
    else if (dynamic_cast<const name*>(event_ptr))                      \
        most_derived_message_type_str = BOOST_PP_STRINGIZE(name);
    BOOST_PP_SEQ_FOR_EACH(EVENT_CASE, _, HUMAN_CLIENT_FSM_EVENTS)
    BOOST_PP_SEQ_FOR_EACH(EVENT_CASE, _, MESSAGE_EVENTS)
#undef EVENT_CASE

    if (terminated()) {
        ErrorLogger(FSM) << "A " << most_derived_message_type_str << " event was passed to "
            "the HumanClientFSM.  The FSM has terminated.  The event is being ignored.";
        return;
    }

    std::stringstream ss;
    ss << "[";
    for (auto leaf_state_it = state_begin(); leaf_state_it != state_end();) {
        // The following use of typeid assumes that
        // BOOST_STATECHART_USE_NATIVE_RTTI is defined
        const auto& leaf_state = *leaf_state_it;
        ss << typeid(leaf_state).name();
        ++leaf_state_it;
        if (leaf_state_it != state_end())
            ss << ", ";
    }
    ss << "]";

    ErrorLogger(FSM) << "A " << most_derived_message_type_str
                     << " event was not handled by any of these states : "
                     << ss.str() << ".  It is being ignored.";
}
コード例 #2
0
ファイル: machine.cpp プロジェクト: jbytheway/nibbles
void Machine::dump()
{
    std::string result = "State machine dump:\n";
    for (auto leaf = state_begin(); leaf != state_end(); ++leaf) {
        result += typeid(*leaf).name();
        result += "\n";
    }
    messageHandler_.message(utility::Verbosity::debug, result);
}
コード例 #3
0
    void AssertInState( const std::string & stateNames ) const
    {
      stateNamesCache_.clear();

      for ( state_iterator currentState = state_begin();
        currentState != state_end(); ++currentState )
      {
        const StateNamesMap::const_iterator found =
          stateNamesMap_.find( currentState->dynamic_type() );
        BOOST_REQUIRE( found != stateNamesMap_.end() );
        stateNamesCache_.insert( found->second );
      }

      std::string::const_iterator expectedName = stateNames.begin();

      BOOST_REQUIRE( stateNames.size() == stateNamesCache_.size() );

      for ( StateNamesCache::const_iterator actualName =
        stateNamesCache_.begin();
        actualName != stateNamesCache_.end(); ++actualName, ++expectedName )
      {
        BOOST_REQUIRE( ( *actualName )[ 0 ] == *expectedName );
      }
    }