#ifndef _Brooks0254ParID_ #define _Brooks0254ParID_ #include #include #include #include #include #include #include #include using namespace std; //! Supplemental class to identify Brooks0254 parameter //! Idenitifcation is by the port direction (intput or ouput ) //! by parameter number //! by the variable type //! Also eaqch parameter should specify its tolerance which defines //! wether an synchronizing action needs to be taken when there is a //! descrepancy between the values in the hardware and in the driver. //! This class does not use mutex locks because it is not expected //! that the same object of this class will be accessed from different //! threads without accessing it through another lockable class. class Brooks0254ParID { public: enum bpiDirType { bpiGlobal, bpiInput, bpiOutput, bpiFlow, bpiNowhere }; enum bpiVarType { bpiBool, bpiInt, bpiDouble, bpiStrange }; protected: bpiDirType bpiDir; // port direction (intput or ouput ) int bpiNum; // parameter number double bpiTlr; // Tolerance for this parameter //! Map that holds the variable type versus a pair of the Brooks port type and //! the parameter number. static map< pair, bpiVarType > bpiTypeMap; static map< pair, double > bpiLoLim; static map< pair, double > bpiHiLim; static bpiVarType GetVarType( bpiDirType dir, int num ) { return bpiTypeMap[ pair( dir, num ) ]; } //! This function defines a formal "measure" to define "less than" //! operator so that this class can be used as a key in the ordered map STL class. inline int Measure() const { return ( bpiDir*10000 + bpiNum ) ; } public: static int bpiDummyInt; //! Default Constructor Brooks0254ParID() : bpiDir(bpiInput), bpiNum(0), bpiTlr(0.1) {;} //! Constructor that is normally is expected to be used in this driver Brooks0254ParID( bpiDirType dir, int num, double tlr = 0.5 ) : bpiDir( dir ), bpiNum( num ), bpiTlr(tlr) {;} //! Copy constructor Brooks0254ParID( const Brooks0254ParID& parID ) : bpiDir( parID.bpiDir ), bpiNum( parID.bpiNum ), bpiTlr( parID.bpiTlr ) {;} //! Copy operator Brooks0254ParID& operator=( const Brooks0254ParID& parID ) { bpiDir = parID.bpiDir; bpiNum = parID.bpiNum; bpiTlr = parID.bpiTlr; return (*this); } //! This function checks if the values are within the range of the //! parameter limits bool BadRange( double val ); static int InitMap(); //! Less than comparison operator inline bool operator<( const Brooks0254ParID& parID ) const { return ( this->Measure() < parID.Measure() ); } //! Greater than comparison operator inline bool operator>( const Brooks0254ParID& parID ) const { return ( this->Measure() > parID.Measure() ); } //! Boolean equal operator inline bool operator==( const Brooks0254ParID& parID ) const { return ( this->Measure() == parID.Measure() ); } inline bpiDirType GetDir() const { return bpiDir; } inline int GetNum() const { return bpiNum; } inline double GetTolerance() const { return bpiTlr; } inline pair* CreatePair() { return (new pair( bpiDir, bpiNum) ); } inline bpiVarType GetType() const { return GetVarType( bpiDir, bpiTlr ); } inline bpiDirType SetDir( const bpiDirType dir ) { return ( bpiDir = dir ); } inline int SetNum( const int num ) { return ( bpiNum = num ) ; } inline double SetTolerance( const double tlr ) { return (bpiTlr = tlr); } }; #endif