/////////////////////////////////////////////////////////////// // state.cpp - defines states in terms of the events // // that trigger transitions to another state // // // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium 200, NT 4.0 // // Application: Design Patterns - property pattern, Su98 // // Author: Jim Fawcett, CST 2-187, (314) 443-3948 // // fawcett@neptune.syr.edu // /////////////////////////////////////////////////////////////// #include #include "state.h" using namespace std; vector ElevBase::registry(numStates); ElevBase* getEvent(ElevBase *pState) { int eventType; cout << "Enter (upButton=1, arrived=2, dnButton=3, quit = 4) > "; cin >> eventType; switch(eventType) { case 1 : return (pState->upButton()); case 2 : return (pState-> arrived()); case 3 : return (pState->dnButton()); case 4 : cout << " end of simulation\n\n"; return 0; default : cout << " no such state - try again\n"; return (getEvent(pState)); } } void main() { onFirstFloor onFirstFloorState; ElevBase *pCurrElevState = onFirstFloorState.makeState(onFF); goingUp goingUpState; goingUpState.makeState(goUp); onSecondFloor onSecondFloorState; onSecondFloorState.makeState(onSF); goingDown goingDownState; goingDownState.makeState(goDn); while(pCurrElevState = getEvent(pCurrElevState)) ; cout << endl; }