together 6.2 不错啊,我的这个程序,用了很多template,竟然不像以前高晕,基本上给显示出来了。不过美中不足,类和类之间的关系,还是识别不出来。不过我得源文件自己都晕,就是为了让别人看不懂,嘿嘿,显摆一下
// xxxxx.hpp.
template <typename EXTERNAL_DATA_STORAGE_TYPE>
class SmfStateMachine : public StateMachine::StateMachine <
SmfStateMachineTraits<EXTERNAL_DATA_STORAGE_TYPE> > {
public:
typedef EXTERNAL_DATA_STORAGE_TYPE ExternalStorage;
typedef SmfStateMachineTraits<ExternalStorage> Traits;
typedef StateMachine::StateMachine<Traits> StateMachine;
typedef typename StateMachine::StateMachine::State State;
typedef typename StateMachine::StateMachine::Message Message;
SmfStateMachine(ExternalStorage & externalStorage,
State * const startState) :
StateMachine(externalStorage, startState) {}
};
template <typename EXTERNAL_DATA_STORAGE_TYPE>
class ShutdownableSmfStateMachine :
public SmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE> {
public:
typedef EXTERNAL_DATA_STORAGE_TYPE ExternalStorage;
typedef SmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE> SmfStateMachine;
typedef typename SmfStateMachine::State State;
typedef typename SmfStateMachine::Message Message;
ShutdownableSmfStateMachine(ExternalStorage & externalStorage,
State * const startState)
: SmfStateMachine(externalStorage, startState)
{
}
////////////////////////////////////////////////////////////////////////////
/**
* Class implementing task to be performed in any state
*/
class AsterixState : public State {
private:
typedef MessageHandler<AsterixState,
ExternalStorage,
Message> StateMessageHandler;
public:
AsterixState();
bool processMessage(ExternalStorage& externalDataStorage,
Message *&pMsg,
bool deleteMessageAfterProcessing = true);
bool defaultMessageHandler(ExternalStorage& externalDataStorage,
Message *&pMsg,
bool deleteMessageAfterProcessing = true);
virtual void shutdownHandler(ExternalStorage& externalDataStorage,
Message *&pMsg) = 0;
};
};
template <typename EXTERNAL_DATA_STORAGE_TYPE>
ShutdownableSmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE>::AsterixState::
AsterixState() {
typename std::auto_ptr<typename State::MessageHandlerInterface>
msgHandler(new StateMessageHandler(*this,
&AsterixState::shutdownHandler));
SMF::header_s dummy;
setMsgHandler(smfShutdown_m(dummy), msgHandler); // dummy msg passed
}
template <typename EXTERNAL_DATA_STORAGE_TYPE>
bool ShutdownableSmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE>::AsterixState::
processMessage(ExternalStorage& externalDataStorage,
Message *&pMsg,
bool deleteMessageAfterProcessing) {
bool thereIsMessageHandler = false;
try {
thereIsMessageHandler =
State::processMessage(externalDataStorage,pMsg, false);
} // try
// Catching std::exceptions and its derivates
catch (std::exception &e) {
// ERROR_WRITE2LOG(Log::Level::INFO,
std::cout << this->getName()
<< ": Standard exception has been caught: "
<< e.what() << std::endl;
} // standard exception
// Catching everything else what is possible
catch (...) {
// ERROR_WRITE2LOG(Log::Level::INFO,
std::cout << this->getName()
<< ": Unknown exception has been caught."
<< " No additional information is available."
<< std::endl;
} // unknown exception
if (deleteMessageAfterProcessing) {
delete pMsg;
}
return thereIsMessageHandler;
}
template <typename EXTERNAL_DATA_STORAGE_TYPE>
bool ShutdownableSmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE>::AsterixState::
defaultMessageHandler(ExternalStorage& externalDataStorage,
Message *&pMsg,
bool deleteMessageAfterProcessing) {
// CPPLOG_TRACER(LOGGER_NAME);
//
// CPPLOG_TRACER_OUT << "("
// << getName()
// << "::defaultMessageHandler): Unexpected msg received."
// << " IRP number: " << pMsg->getIRPNumber()
// << " Msg. number: " << pMsg->getMsgNumber() << std::endl;
return false;
}
template <typename EXTERNAL_DATA_STORAGE_TYPE>
class ShutdownableStatefulSmfMaster :
public smfMasterBase_c,
public ShutdownableSmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE> {
public:
typedef EXTERNAL_DATA_STORAGE_TYPE ExternalStorage;
typedef ShutdownableSmfStateMachine<ExternalStorage> ShutdownableSmfStateMachine;
typedef typename ShutdownableSmfStateMachine::State State;
typedef typename ShutdownableSmfStateMachine::Message Message;
class AsterixState : public ShutdownableSmfStateMachine::AsterixState {
private:
typedef MessageHandler<AsterixState,
ExternalStorage,
Message> StateMessageHandler;
public:
void shutdownHandler(ExternalStorage& externalDataStorage,
Message *&pMsg);
};
ShutdownableStatefulSmfMaster(ExternalStorage& externalStorage,
State * const startState) :
ShutdownableSmfStateMachine(externalStorage,
startState),
externalStorage(externalStorage) {}
void processMessage(smfMsgBase_c *pMsg) {
this->getState().processMessage(externalStorage,
pMsg,
true);
}
private:
ExternalStorage & externalStorage;
};
template <typename EXTERNAL_DATA_STORAGE_TYPE>
void ShutdownableStatefulSmfMaster<EXTERNAL_DATA_STORAGE_TYPE>::AsterixState::
shutdownHandler(ExternalStorage& externalDataStorage,
Message *&pMsg) {
// CPPLOG_TRACER(LOGGER_NAME);
smfShutdown_m *shutdownMsg = (smfShutdown_m *)pMsg;
// if(shutdownMsg->isForced()) {
// CPPLOG_TRACER_OUT << "smfShutdown_m message with FORCED flag received in "
// << externalDataStorage.getMyFamily()
// << " in state: "
// << externalDataStorage.getState().getName()
// << ". Master is being stopped."
// << std::endl;
// }
// else {
smfFamilyService_c::broadcastMsg(externalDataStorage.getMyComponent(),
shutdownMsg);
pMsg = 0; // not to delete it if it is broadcasted...
// }
externalDataStorage.smfMasterBase_c::stop();
}
template <typename EXTERNAL_DATA_STORAGE_TYPE>
class ShutdownableStatefulSmfHand :
public smfHandBase_c,
public ShutdownableSmfStateMachine<EXTERNAL_DATA_STORAGE_TYPE> {
public:
typedef EXTERNAL_DATA_STORAGE_TYPE ExternalStorage;
typedef ShutdownableSmfStateMachine<ExternalStorage> ShutdownableSmfStateMachine;
typedef typename ShutdownableSmfStateMachine::State State;
typedef typename ShutdownableSmfStateMachine::Message Message;
class AsterixState : public ShutdownableSmfStateMachine::AsterixState {
private:
typedef MessageHandler<AsterixState,
ExternalStorage,
Message> StateMessageHandler;
public:
void shutdownHandler(ExternalStorage& externalDataStorage,
Message *&pMsg);
};
ShutdownableStatefulSmfHand(ExternalStorage& externalStorage,
State * const startState) :
ShutdownableSmfStateMachine(externalStorage,
startState),
externalStorage(externalStorage) {}
void processMessage(smfMsgBase_c *pMsg) {
this->getState().processMessage(externalStorage,
pMsg,
true);
}
private:
ExternalStorage& externalStorage;
};
template <typename EXTERNAL_DATA_STORAGE_TYPE>
void ShutdownableStatefulSmfHand<EXTERNAL_DATA_STORAGE_TYPE>::AsterixState::
shutdownHandler(ExternalStorage& externalDataStorage,
Message *&pMsg) {
// CPPLOG_TRACER_OUT << ""smfShutdown_m message received in family: "
// << externalDataStorage.getMyFamily()
// << " in state: "
// << externalDataStorage.getState().getName()
// << ". Hand is being stopped."
// << std::endl;
externalDataStorage.smfHandBase_c::stop();
}
//====================================================
I don't mind if you r FAT.
I don't mind if you r UGLY.
I don't mind if you ACT CUTE.
But I can't STAND if you r FAT, UGLY and still ACT CUTE.