#include "Brooks0254Input.hh" //! There is going to be only one instance of this class //! This line initializes the instance with "zero" settings. //Brooks0254Input* Brooks0254Input::biInstance = new Brooks0254Input( "C0:S0:P0:F0" ); Brooks0254Input* Brooks0254Input::biInstance = Brooks0254Input::Instantiate( "C0:S0:P0:F0" ); //! This function parses the input field content of the EPICS record //! for the Brooks0254 module and assigns the proper values to the //! data members of this class. Brooks0254Input::Brooks0254Input( const char* input ) { string strInp( input ); size_t chasBeg = strInp.find( "C" ) + 1; size_t chasEnd = strInp.find( ":", chasBeg ); string chasStr = strInp.substr( chasBeg, chasEnd - chasBeg ); size_t slotBeg = strInp.find( "S", chasEnd ) + 1; size_t slotEnd = strInp.find( ":", slotBeg ); string slotStr = strInp.substr( slotBeg, slotEnd - slotBeg ); size_t portBeg = strInp.find( "P", slotEnd ) + 1; size_t portEnd = strInp.find( ":", portBeg ); string portStr = strInp.substr( portBeg, portEnd - portBeg ); size_t funcBeg = strInp.find( "F", portEnd ) + 1; size_t funcEnd = strInp.find( ":", funcBeg ); string funcStr = strInp.substr( funcBeg, funcEnd - funcBeg ); if( chasBeg != string::npos && chasEnd != string::npos && slotBeg != string::npos && slotEnd != string::npos && portBeg != string::npos && portEnd != string::npos && funcBeg != string::npos ) { stringstream( chasStr ) >> biChassis ; stringstream( slotStr ) >> biCard ; stringstream( portStr ) >> biPortType ; stringstream( funcStr ) >> biParam ; } else { cerr << "Error in parsing input argument " << input << endl; } return; } //! Method to instantiate the only object oth this class. If an object //! already exsists it is destroyed a a new one is created, and the //! parameters are set in the constructor Brooks0254Input* Brooks0254Input::Instantiate( const char* inp ) { if( Brooks0254Input::biInstance != 0 ) delete Brooks0254Input::biInstance; Brooks0254Input::biInstance = new Brooks0254Input( inp ); return Brooks0254Input::biInstance; } //! Interface with C extern "C" { #include "Brooks0254Input.h" /* This is the function to instntiate the object and extract */ /* the parameters from the string in the input field of the EPICS record */ int brooksInputSet( const char* inp ) { Brooks0254Input::Instantiate( inp ); return 0; } int brooksInputChassis() { return Brooks0254Input::GetInstance()->GetChassis(); } int brooksInputCard() { return Brooks0254Input::GetInstance()->GetCard(); } int brooksInputPortType() { return Brooks0254Input::GetInstance()->GetPortType(); } int brooksInputParameter() { return Brooks0254Input::GetInstance()->GetParam(); } };