/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "BaseIUInput.hh" string BaseIUInput::biSeparator = "/" ; //! This function parses the input field content of the EPICS record //! for the BaseIU module and assigns the proper values to the //! data members of this class. BaseIUInput::BaseIUInput( const string strInp ) : biAddress(0) { size_t portBeg = strInp.find( "@" ) + 1; size_t portEnd = strInp.find( biSeparator, portBeg ); string portStr = strInp.substr( portBeg, portEnd - portBeg ); // size_t addrBeg = strInp.find( "A", busEnd ) + 1; size_t addrBeg = portEnd + 1; size_t addrEnd = strInp.find( biSeparator, addrBeg ); string addrStr = strInp.substr( addrBeg, addrEnd - addrBeg ); // size_t typeBeg = strInp.find( "T", addrEnd ) + 1; size_t typeBeg = addrEnd + 1; size_t typeEnd = strInp.find( biSeparator, typeBeg ); string typeStr = strInp.substr( typeBeg, typeEnd - typeBeg ); // size_t nameBeg = strInp.find( "N", typeEnd ) + 1; size_t nameBeg = typeEnd + 1; size_t nameEnd = strInp.find( biSeparator, nameBeg ); string nameStr = strInp.substr( nameBeg, nameEnd - nameBeg ); // size_t bitBeg = strInp.find( "B", nameEnd ) + 1; size_t bitBeg = nameEnd + 1; size_t bitEnd = strInp.find( biSeparator, bitBeg ); string bitStr = strInp.substr( bitBeg, bitEnd - bitBeg ); if( portBeg != string::npos && portEnd != string::npos && addrBeg != string::npos && addrEnd != string::npos && typeBeg != string::npos && typeEnd != string::npos && nameBeg != string::npos ) { //! If all parameter fields are found then assign the input parameters biPortName = portStr; stringstream( addrStr ) >> hex >> showbase >> biAddress ; biParType = typeStr; biParName = nameStr; if( nameEnd != string::npos && bitBeg != string::npos ) biBitName = bitStr; else biBitName = ""; } else { //! In case of failed parsing throw an exception. stringstream errStream; errStream << "Error in parsing input argument " << strInp; throw BadString( errStream.str() ); } return; } //! Copy constructor utilizing assignment operator BaseIUInput::BaseIUInput( const BaseIUInput& inp ) { *this = operator=( inp ); return; } //! Assignment operator BaseIUInput& BaseIUInput::operator=( const BaseIUInput& inp ) { if( this == &inp ) return *this; biPortName = inp.biPortName; biAddress = inp.biAddress; biParType = inp.biParType; biParName = inp.biParName; biBitName = inp.biBitName; return *this; }