//Jacky: This is based on the simplified Lopez's version // No FutureValue is used in this version! /******************************************************************* * * DESCRIPTION: class InertialDelayCell * * AUTHOR: Amir Barylko & Jorge Beyoglonian * Version 2: Daniel Rodriguez. * Version 3: Qi (Jacky) Liu * * EMAIL: mailto://amir@dc.uba.ar * mailto://jbeyoglo@dc.uba.ar * mailto://drodrigu@dc.uba.ar * mailto://liuqi@sce.carleton.ca * * DATE: 27/6/1998 * DATE: 17/9/1999 (v2) * DATE: 09/10/2005 (v3) * *******************************************************************/ #ifndef __INERTIAL_DELAY_ATOMIC_CELL_H #define __INERTIAL_DELAY_ATOMIC_CELL_H /** include files **/ #include "atomcell.h" // base class header #include "JackyDebugStream.h" //jacky-debug-mode & jacky-sync /** foward declarations **/ #define INERTIAL_DELAY_CELL_NAME "InertialDelayCell" /** declarations **/ class IDCellState : public AtomicCellState { public: typedef pair ValueWithFlag; typedef map StateValues; StateValues actualValue; //A VTime recordTime; //RT StateValues recordActual; //RA AtomicState::State recordState; //RS //add a StateVars here to record the values of the state variables at the beginning of Round 0 //[see macro JACKY_STATE_VAR in JackyDebugStream.h for more information] StateVars vars_round0; //RV //this is to record the delay of the cell when it first enters R0 at a given time //[see "change back" in idcell.cpp for further information.] VTime recordDelay; //RD IDCellState(){}; virtual ~IDCellState(){}; IDCellState& operator=(IDCellState& thisState); //Assignment void copyState(BasicState *); int getSize() const; bool isAtomic(); bool isAtomic() const; #ifdef JACKY_DEBUG //Jacky: this function will be defined in all state classes for ParallelProcesses & Models // to show (print) the content of the state for debugging purpose virtual void showStateContent( ostream& ) const; void showActualValues( ostream& ) const; //void showFutureValues( ostream& ) const; void showRecordActualValues( ostream& ) const; #endif }; #ifdef JACKY_DEBUG //============================================================================ inline void IDCellState::showActualValues( ostream& out ) const{ out << "\t\t ActualValues -> " << flush; IDCellState::StateValues::const_iterator it = actualValue.begin(); for( ; it != actualValue.end(); it++){ out << "<" << it->first << " = " << (it->second).first.value() << flush; if( (it->second).second == true ){ out << " / flag = TRUE>" << flush; } else { out << " / flag = FALSE>" << flush; } } out << endl << flush; } inline void IDCellState::showRecordActualValues( ostream& out ) const{ out << "\t\t RA -> " << flush; IDCellState::StateValues::const_iterator it = recordActual.begin(); for( ; it != recordActual.end(); it++){ out << "<" << it->first << " = " << (it->second).first.value() << flush; if( (it->second).second == true ){ out << " / flag = TRUE>" << flush; } else { out << " / flag = FALSE>" << flush; } } out << endl << flush; } inline void IDCellState::showStateContent( ostream& out) const{ //1> first call the counterpart function in the base class AtomicCellState::showStateContent(out); //2> show content defined in this class out << "\t\tIDCellState : " << endl << flush; showActualValues( out ); out << "\t\t RT = " << recordTime.asString() << " / RS = " << flush; if( recordState == AtomicState::active ){ out << "active" << endl << flush; } else if( recordState == AtomicState::passive ){ out << "passive" << endl << flush; } out << "\t\t RD = " << recordDelay.asString() << endl << flush; showRecordActualValues( out ); //show the state variables in the AtomicCellState out << "\t[2006-01-10] State Variables in AtomicCellState = " << variables.asString() << endl << flush; //show the recorded values of these state variables out << "\t[2006-01-10] Recorded State Variables in IDCellState = " << vars_round0.asString() << endl << flush; } #endif //end JACKY_DEBUG =================================================================== class InertialDelayCell: public AtomicCell { public: InertialDelayCell( const CellPosition& cellPos, const string &name = INERTIAL_DELAY_CELL_NAME , const LocalTransAdmin::Function &fn = LocalTransAdmin::InvalidFn ) : AtomicCell( cellPos, name, fn ) {} string className() const {return INERTIAL_DELAY_CELL_NAME;} protected: Model &initFunction(); Model &internalFunction( const InternalMessage & ); Model &externalFunction( const MessageBag & ) ; Model &outputFunction( const CollectMessage & ); ModelState* allocateState() { return new IDCellState;} void initializeCell(); private: Real actualValue( const string& ) const; bool actualValueFlag( const string& ) const; void actualValue( const string&, const Real&, const bool &flag = false ); void resetValueFlags( IDCellState::StateValues & ); #if defined(JACKY_DEBUG) || defined (JACKY_WRITER) void printValues(const IDCellState::StateValues &, ostream &) const; #endif //end JACKY_DEBUG //function to get/set the RT (recordTime) in the state const VTime &getRecordTime() const; void setRecordTime( const VTime& ); //function to get/set the RS (recordState) in the state const AtomicState::State &getRecordState() const; void setRecordState( const AtomicState::State& ); //function to get/set the value in the RA (recordActual) in the state Real getRecordActual( const string& ) const; void setRecordActual( const string&, const Real&, const bool &flag = false ); //function to get the recordActual in the state IDCellState::StateValues &recordActualVal() const; //function to get the actualValue in the state IDCellState::StateValues &actualMap() const; //get the StateVars in the AtomicCellState class (RV) StateVars &cellStateVariables(); //get the StateVars in the IDCellState class, a record of the StateVars in AtomicCellState at R0 StateVars &recordStateVariables(); //this is to record the delay of the cell when it first enters R0 at a given time //[see "change back" in idcell.cpp for further information.] VTime &getRecordDelay() const; void setRecordDelay(const VTime&); #ifdef JACKY_DEBUG //this is the number to record the number of the Round in the multiple-round message passing int roundNum; #endif //end JACKY_DEBUG } ; // InertialDelayCell /** inline **/ //1. RT inline const VTime &InertialDelayCell::getRecordTime() const{ return ((IDCellState*)getCurrentState())->recordTime; } inline void InertialDelayCell::setRecordTime( const VTime& newTime){ ((IDCellState*)getCurrentState())->recordTime = newTime; } //2. RS inline const AtomicState::State &InertialDelayCell::getRecordState() const{ return ((IDCellState*)getCurrentState())->recordState; } inline void InertialDelayCell::setRecordState( const AtomicState::State& newState){ ((IDCellState*)getCurrentState())->recordState = newState; } //3. RA inline Real InertialDelayCell::getRecordActual( const string &port ) const{ return (((IDCellState*)getCurrentState())->recordActual[port]).first; } inline void InertialDelayCell::setRecordActual( const string &port, const Real &r, const bool &flag ){ (((IDCellState*)getCurrentState())->recordActual[port]).first = r; (((IDCellState*)getCurrentState())->recordActual[port]).second = flag; } inline IDCellState::StateValues &InertialDelayCell::recordActualVal() const { return ((IDCellState*)getCurrentState())->recordActual; } //4. RV //get the StateVars in the AtomicCellState class inline StateVars &InertialDelayCell::cellStateVariables(){ return ((IDCellState*)getCurrentState())->variables; } //get the StateVars in the TDCellState class, which is a record of the StateVars in AtomicCellState //at the beginning of Round 0 inline StateVars &InertialDelayCell::recordStateVariables(){ return ((IDCellState*)getCurrentState())->vars_round0; } //5. RD //get the delay recorded whenever ther is a time change and the cell's phase is Active inline VTime &InertialDelayCell::getRecordDelay() const { return ((IDCellState*)getCurrentState())->recordDelay; } //record the value of the delay whenever there is a time change and the cell's phase is Active inline void InertialDelayCell::setRecordDelay( const VTime &delay ){ ((IDCellState*)getCurrentState())->recordDelay = delay; } //6. A inline IDCellState::StateValues &InertialDelayCell::actualMap() const { return ((IDCellState*)getCurrentState())->actualValue; } inline Real InertialDelayCell::actualValue(const string &port) const { return (((IDCellState*)getCurrentState())->actualValue[port]).first; } //Nov. 29, 2005 //function to get the flag value for the value of the given port inline bool InertialDelayCell::actualValueFlag( const string &port ) const{ return (((IDCellState*)getCurrentState())->actualValue[port]).second; } inline void InertialDelayCell::actualValue (const string &port, const Real &r, const bool &flag) { (((IDCellState*)getCurrentState())->actualValue[port]).first = r; (((IDCellState*)getCurrentState())->actualValue[port]).second = flag; } #endif // __INERTIAL_DELAY_ATOMIC_CELL_H