#ifndef __INERTIAL_DELAY_ATOMIC_CELL_H #define __INERTIAL_DELAY_ATOMIC_CELL_H #include "atomcell.h" // base class header #include "JackyDebugStream.h" //jacky-debug-mode & jacky-sync #define INERTIAL_DELAY_CELL_NAME "InertialDelayCell" class IDCellState : public AtomicCellState { public: typedef pair ValueWithFlag; typedef map StateValues; StateValues futureValue; StateValues actualValue; VTime recordTime; StateValues recordActual; AtomicState::State recordState; //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; IDCellState(){}; virtual ~IDCellState(){}; IDCellState& operator=(IDCellState& thisState); //Assignment void copyState(BasicState *); int getSize() const; bool isAtomic(); bool isAtomic() const; }; 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 futureValue( const string& ) const; bool futureValueFlag( const string& ) const; void futureValue( const string&, const Real&, const bool &flag = false ); Real actualValue( const string& ) const; bool actualValueFlag( const string& ) const; void actualValue( const string&, const Real&, const bool &flag = false ); void resetValueFlags( IDCellState::StateValues & ); //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; //function to get the futureValue in the state IDCellState::StateValues &futureMap() const; //get the StateVars in the AtomicCellState class StateVars &cellStateVariables(); //get the StateVars in the IDCellState class, which is a record of the StateVars in AtomicCellState // at the beginning of Round 0 StateVars &recordStateVariables(); } ; // InertialDelayCell inline const VTime &InertialDelayCell::getRecordTime() const{ return ((IDCellState*)getCurrentState())->recordTime; } inline void InertialDelayCell::setRecordTime( const VTime& newTime){ ((IDCellState*)getCurrentState())->recordTime = newTime; } inline const AtomicState::State &InertialDelayCell::getRecordState() const{ return ((IDCellState*)getCurrentState())->recordState; } inline void InertialDelayCell::setRecordState( const AtomicState::State& newState){ ((IDCellState*)getCurrentState())->recordState = newState; } 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; } inline IDCellState::StateValues &InertialDelayCell::actualMap() const { return ((IDCellState*)getCurrentState())->actualValue; } inline IDCellState::StateValues &InertialDelayCell::futureMap() const { return ((IDCellState*)getCurrentState())->futureValue; } //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; } inline Real InertialDelayCell::futureValue(const string &port) const { return (((IDCellState*)getCurrentState())->futureValue[port]).first; } //Nov. 29, 2005 //function to get the flag value for the value of the given port inline bool InertialDelayCell::futureValueFlag( const string &port ) const{ return (((IDCellState*)getCurrentState())->futureValue[port]).second; } inline void InertialDelayCell::futureValue (const string &port, const Real &r, const bool &flag){ (((IDCellState*)getCurrentState())->futureValue[port]).first = r; (((IDCellState*)getCurrentState())->futureValue[port]).second = flag; } 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