LCOV - code coverage report
Current view: top level - INDI/libcommon - IndiElement.cpp (source / functions) Coverage Total Hit
Test: MagAOX Lines: 23.9 % 352 84
Test Date: 2026-01-03 21:03:39 Functions: 35.7 % 56 20

            Line data    Source code
       1              : /// IndiElement.cpp
       2              : ///
       3              : /// @author Paul Grenz
       4              : ///
       5              : ////////////////////////////////////////////////////////////////////////////////
       6              : 
       7              : #include <string>
       8              : #include <sstream>
       9              : #include <iostream>           // for std::cerr
      10              : #include <stdexcept>          // for std::runtime_error
      11              : #include "IndiElement.hpp"
      12              : 
      13              : using std::boolalpha;
      14              : using std::runtime_error;
      15              : using std::string;
      16              : using std::stringstream;
      17              : using pcf::IndiElement;
      18              : 
      19              : ////////////////////////////////////////////////////////////////////////////////
      20              : /// Constructor.
      21              : 
      22         2761 : IndiElement::IndiElement()
      23              : {
      24          251 : }
      25              : 
      26              : ////////////////////////////////////////////////////////////////////////////////
      27              : /// Constructor with a name - this will be used often.
      28              : 
      29         1881 : IndiElement::IndiElement( const string &szName ) : m_szName(szName)
      30              : {
      31          171 : }
      32              : 
      33              : ////////////////////////////////////////////////////////////////////////////////
      34              : /// Constructor with a name and a string value.
      35              : 
      36           24 : IndiElement::IndiElement( const string &szName,
      37          264 :                           const string &szValue ) : m_szName(szName), m_szValue(szValue)
      38              : {
      39           24 : }
      40              : 
      41              : ////////////////////////////////////////////////////////////////////////////////
      42              : /// Constructor with a name and a char pointer value.
      43              : 
      44            0 : IndiElement::IndiElement( const string &szName,
      45            0 :                           const char *pcValue ) : m_szName(szName), m_szValue(pcValue)
      46              : {
      47            0 : }
      48              : 
      49              : ////////////////////////////////////////////////////////////////////////////////
      50              : /// Constructor with a name and a LightStateType value.
      51              : 
      52            0 : IndiElement::IndiElement( const string &szName,
      53            0 :                           const LightStateType &tValue ) : m_szName(szName), m_lsValue(tValue)
      54              : {
      55            0 : }
      56              : 
      57              : ////////////////////////////////////////////////////////////////////////////////
      58              : /// Constructor with a name and a SwitchStateType value.
      59              : 
      60           32 : IndiElement::IndiElement( const string &szName,
      61          352 :                           const SwitchStateType &tValue ) : m_szName(szName), m_ssValue(tValue)
      62              : {
      63           32 : }
      64              : 
      65              : ////////////////////////////////////////////////////////////////////////////////
      66              : ///  Copy constructor.
      67              : 
      68            9 : IndiElement::IndiElement( const IndiElement &ieRhs ) : m_szFormat(ieRhs.m_szFormat), m_szLabel(ieRhs.m_szLabel),
      69            9 :                                                          m_szMax(ieRhs.m_szMax), m_szMin(ieRhs.m_szMin), m_szName(ieRhs.m_szName),
      70            9 :                                                           m_szSize(ieRhs.m_szSize), m_szStep(ieRhs.m_szStep), m_szValue(ieRhs.m_szValue),
      71           18 :                                                            m_lsValue(ieRhs.m_lsValue), m_ssValue(ieRhs.m_ssValue)
      72              : {
      73            9 : }
      74              : 
      75              : ////////////////////////////////////////////////////////////////////////////////
      76              : /// Destructor.
      77              : 
      78          511 : IndiElement::~IndiElement()
      79              : {
      80          511 : }
      81              : 
      82              : ////////////////////////////////////////////////////////////////////////////////
      83              : /// Assigns the internal data of this object from an existing one.
      84              : 
      85          251 : const IndiElement &IndiElement::operator=( const IndiElement &ieRhs )
      86              : {
      87          251 :   if ( &ieRhs != this )
      88              :   {
      89          251 :     pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
      90              : 
      91          251 :     m_szFormat = ieRhs.m_szFormat;
      92          251 :     m_szLabel = ieRhs.m_szLabel;
      93          251 :     m_szMax = ieRhs.m_szMax;
      94          251 :     m_szMin = ieRhs.m_szMin;
      95          251 :     m_szName = ieRhs.m_szName;
      96          251 :     m_szSize = ieRhs.m_szSize;
      97          251 :     m_szStep = ieRhs.m_szStep;
      98          251 :     m_szValue = ieRhs.m_szValue;
      99          251 :     m_lsValue = ieRhs.m_lsValue;
     100          251 :     m_ssValue = ieRhs.m_ssValue;
     101          251 :   }
     102          251 :   return *this;
     103              : }
     104              : 
     105              : ////////////////////////////////////////////////////////////////////////////////
     106              : /// Returns true if we have an exact match (value as well).
     107              : 
     108            0 : bool IndiElement::operator==( const IndiElement &ieRhs ) const
     109              : {
     110            0 :   if ( &ieRhs == this )
     111            0 :     return true;
     112              : 
     113            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     114              : 
     115            0 :   return ( m_szFormat == ieRhs.m_szFormat &&
     116            0 :            m_szLabel == ieRhs.m_szLabel &&
     117            0 :            m_szMax == ieRhs.m_szMax &&
     118            0 :            m_szMin == ieRhs.m_szMin &&
     119            0 :            m_szName == ieRhs.m_szName &&
     120            0 :            m_szSize == ieRhs.m_szSize &&
     121            0 :            m_szStep == ieRhs.m_szStep &&
     122            0 :            m_szValue == ieRhs.m_szValue &&
     123            0 :            m_lsValue == ieRhs.m_lsValue &&
     124            0 :            m_ssValue == ieRhs.m_ssValue );
     125            0 : }
     126              : 
     127              : ////////////////////////////////////////////////////////////////////////////////
     128              : 
     129            0 : string IndiElement::createString() const
     130              : {
     131            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     132              : 
     133            0 :   stringstream ssOutput;
     134              :   ssOutput << "{ "
     135            0 :            << "\"name\" : \"" << m_szName << "\" , "
     136            0 :            << "\"value\" : \"" << m_szValue << "\" , "
     137            0 :            << "\"lightstate\" : \"" << getLightStateString( m_lsValue ) << "\" , "
     138            0 :            << "\"switchstate\" : \"" << getSwitchStateString( m_ssValue ) << "\" , "
     139            0 :            << "\"label\" : \"" << m_szLabel << "\" , "
     140            0 :            << "\"format\" : \"" << m_szFormat << "\" , "
     141            0 :            << "\"max\" : \"" << m_szMax << "\" , "
     142            0 :            << "\"min\" : \"" << m_szMin << "\" , "
     143            0 :            << "\"size\" : \"" << m_szSize << "\" , "
     144            0 :            << "\"step\" : \"" << m_szStep << "\" "
     145            0 :            << "} ";
     146            0 :   return ssOutput.str();
     147            0 : }
     148              : 
     149              : 
     150              : ////////////////////////////////////////////////////////////////////////////////
     151              : /// Remove all attributes and reset this object.
     152              : 
     153            0 : void IndiElement::clear()
     154              : {
     155            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     156              : 
     157            0 :   m_szFormat = "%g";
     158            0 :   m_szLabel = "";
     159            0 :   m_szMax = "0";
     160            0 :   m_szMin = "0";
     161            0 :   m_szName = "";
     162            0 :   m_szSize = "0";
     163            0 :   m_szStep = "0";
     164            0 :   m_szValue = "";
     165            0 :   m_lsValue = UnknownLightState;
     166            0 :   m_ssValue = UnknownSwitchState;
     167            0 : }
     168              : 
     169              : ////////////////////////////////////////////////////////////////////////////////
     170              : /// Returns the format attribute.
     171              : 
     172            2 : const string &IndiElement::getFormat() const
     173              : {
     174            2 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     175            2 :   return m_szFormat;
     176            2 : }
     177              : 
     178              : ////////////////////////////////////////////////////////////////////////////////
     179              : /// Returns the label attribute.
     180              : 
     181            7 : const string &IndiElement::getLabel() const
     182              : {
     183            7 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     184            7 :   return m_szLabel;
     185            7 : }
     186              : 
     187              : ////////////////////////////////////////////////////////////////////////////////
     188              : /// Returns the state of a light.
     189              : 
     190            0 : IndiElement::operator IndiElement::LightStateType() const
     191              : {
     192            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     193            0 :   return m_lsValue;
     194            0 : }
     195              : 
     196              : ////////////////////////////////////////////////////////////////////////////////
     197              : /// Returns the state of a light.
     198              : 
     199            0 : IndiElement::LightStateType IndiElement::getLightState() const
     200              : {
     201            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     202            0 :   return m_lsValue;
     203            0 : }
     204              : 
     205              : ////////////////////////////////////////////////////////////////////////////////
     206              : /// Returns the max attribute.
     207              : 
     208            2 : const string &IndiElement::getMax() const
     209              : {
     210            2 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     211            2 :   return m_szMax;
     212            2 : }
     213              : 
     214              : ////////////////////////////////////////////////////////////////////////////////
     215              : /// Returns the min attribute.
     216              : 
     217            2 : const string &IndiElement::getMin() const
     218              : {
     219            2 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     220            2 :   return m_szMin;
     221            2 : }
     222              : 
     223              : ////////////////////////////////////////////////////////////////////////////////
     224              : /// Returns the name attribute.
     225              : 
     226          510 : const string &IndiElement::getName() const
     227              : {
     228          510 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     229          510 :   return m_szName;
     230          510 : }
     231              : 
     232              : ////////////////////////////////////////////////////////////////////////////////
     233              : /// Returns the step attribute.
     234              : 
     235            2 : const string &IndiElement::getStep() const
     236              : {
     237            2 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     238            2 :   return m_szStep;
     239            2 : }
     240              : 
     241              : ////////////////////////////////////////////////////////////////////////////////
     242              : /// Returns the size attribute.
     243              : 
     244            0 : const std::string & IndiElement::getSize() const
     245              : {
     246            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     247            0 :   return m_szSize;
     248            0 : }
     249              : 
     250              : ////////////////////////////////////////////////////////////////////////////////
     251              : /// Returns the state of a switch.
     252              : 
     253            0 : IndiElement::operator IndiElement::SwitchStateType() const
     254              : {
     255            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     256            0 :   return m_ssValue;
     257            0 : }
     258              : 
     259              : ////////////////////////////////////////////////////////////////////////////////
     260              : /// Returns the state of a switch.
     261              : 
     262           62 : IndiElement::SwitchStateType IndiElement::getSwitchState() const
     263              : {
     264           62 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     265           62 :   return m_ssValue;
     266           62 : }
     267              : 
     268              : ////////////////////////////////////////////////////////////////////////////////
     269              : /// Is the value (not LightState or SwitchState) a numeric?
     270              : 
     271            0 : bool IndiElement::isNumeric() const
     272              : {
     273            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     274              : 
     275              :   int iValue;
     276            0 :   std::stringstream ssValue( m_szValue );
     277              : 
     278              :   // Try to stream the data into the int variable.
     279              :   // If we fail, this value is not numeric.
     280            0 :   ssValue >> iValue;
     281            0 :   return ssValue.good();
     282              : //  return ( ssValue >> iValue );
     283            0 : }
     284              : 
     285              : ////////////////////////////////////////////////////////////////////////////////
     286              : /// Returns the bool value. If the value is 0, "false", or any other non-value.
     287              : /*
     288              : IndiElement::operator bool() const
     289              : {
     290              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     291              : 
     292              :   bool oValue;
     293              :   std::stringstream ssValue( m_szValue );
     294              : 
     295              :   // Try to stream the data into the variable.
     296              :   ssValue >> oValue;
     297              :   if ( ssValue.fail() == true )
     298              :   {
     299              :     throw ( runtime_error( string( "IndiElement '" ) + m_szName + "' value '" +
     300              :                            m_szValue + "' is not a bool.") );
     301              :   }
     302              : 
     303              :   return oValue;
     304              : }
     305              : 
     306              : ////////////////////////////////////////////////////////////////////////////////
     307              : /// Returns the double value.
     308              : 
     309              : IndiElement::operator double() const
     310              : {
     311              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     312              : 
     313              :   double xValue;
     314              :   std::stringstream ssValue( m_szValue );
     315              : 
     316              :   // Try to stream the data into the variable.
     317              :   ssValue >> xValue;
     318              :   if ( ssValue.fail() == true )
     319              :   {
     320              :     throw ( runtime_error( string( "IndiElement '" ) + m_szName + "' value '" +
     321              :                            m_szValue + "' is not a double.") );
     322              :   }
     323              : 
     324              :   return xValue;
     325              : }
     326              : 
     327              : ////////////////////////////////////////////////////////////////////////////////
     328              : /// Returns the float value.
     329              : 
     330              : IndiElement::operator float() const
     331              : {
     332              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     333              : 
     334              :   float eValue;
     335              :   std::stringstream ssValue( m_szValue );
     336              : 
     337              :   // Try to stream the data into the variable.
     338              :   ssValue >> eValue;
     339              :   if ( ssValue.fail() == true )
     340              :   {
     341              :     throw ( runtime_error( string( "IndiElement '" ) + m_szName + "' value '" +
     342              :                            m_szValue + "' is not a float.") );
     343              :   }
     344              : 
     345              :   return eValue;
     346              : }
     347              : 
     348              : ////////////////////////////////////////////////////////////////////////////////
     349              : /// Returns the int value.
     350              : 
     351              : IndiElement::operator int() const
     352              : {
     353              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     354              : 
     355              :   int iValue;
     356              :   std::stringstream ssValue( m_szValue );
     357              : 
     358              :   // Try to stream the data into the variable.
     359              :   ssValue >> iValue;
     360              :   if ( ssValue.fail() == true )
     361              :   {
     362              :     throw ( runtime_error( string( "IndiElement '" ) + m_szName + "' value '" +
     363              :                            m_szValue + "' is not an int.") );
     364              :   }
     365              : 
     366              :   return iValue;
     367              : }
     368              : 
     369              : ////////////////////////////////////////////////////////////////////////////////
     370              : /// Returns the string value.
     371              : 
     372              : IndiElement::operator string() const
     373              : {
     374              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     375              :   return m_szValue;
     376              : }
     377              : 
     378              : ////////////////////////////////////////////////////////////////////////////////
     379              : /// Returns the unsigned int value.
     380              : 
     381              : IndiElement::operator unsigned int() const
     382              : {
     383              :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     384              : 
     385              :   unsigned int uiValue;
     386              :   std::stringstream ssValue( m_szValue );
     387              : 
     388              :   // Try to stream the data into the variable.
     389              :   ssValue >> uiValue;
     390              :   if ( ssValue.fail() == true )
     391              :   {
     392              :     throw ( runtime_error( string( "IndiElement '" ) + m_szName + "' value '" +
     393              :                            m_szValue + "' is not an unsigned int.") );
     394              :   }
     395              : 
     396              :   return uiValue;
     397              : }
     398              : */
     399              : ////////////////////////////////////////////////////////////////////////////////
     400              : /// Returns the value as type string.
     401              : 
     402           30 : string IndiElement::get() const
     403              : {
     404           30 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     405           60 :   return m_szValue;
     406           30 : }
     407              : 
     408              : ////////////////////////////////////////////////////////////////////////////////
     409              : /// Returns the value as type string.
     410              : 
     411           16 : string IndiElement::getValue() const
     412              : {
     413           16 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     414           32 :   return m_szValue;
     415           16 : }
     416              : 
     417              : ////////////////////////////////////////////////////////////////////////////////
     418              : /// Returns the string value as an array of char. The size argument should
     419              : /// contain the number of bytes in the buffer 'pcValue', it will be returned
     420              : /// with the number of bytes actually copied.
     421              : 
     422            0 : void IndiElement::getValue( char *pcValue, unsigned int &uiSize ) const
     423              : {
     424            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     425              : 
     426              :   // Modify the number of bytes to copy. It will be the lesser of the two sizes.
     427            0 :   uiSize = ( uiSize > m_szValue.size() ) ? ( m_szValue.size() ) : ( uiSize );
     428              : 
     429            0 :   ::memcpy( pcValue, m_szValue.c_str(), uiSize );
     430            0 : }
     431              : 
     432              : ////////////////////////////////////////////////////////////////////////////////
     433              : 
     434            2 : void IndiElement::setFormat( const string &szFormat )
     435              : {
     436            2 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     437            2 :   m_szFormat = szFormat;
     438            2 : }
     439              : 
     440              : ////////////////////////////////////////////////////////////////////////////////
     441              : 
     442            6 : void IndiElement::setLabel( const string &szLabel )
     443              : {
     444            6 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     445            6 :   m_szLabel = szLabel;
     446            6 : }
     447              : 
     448              : ////////////////////////////////////////////////////////////////////////////////
     449              : 
     450            0 : void IndiElement::setMax( const string &szMax )
     451              : {
     452            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     453            0 :   m_szMax = szMax;
     454            0 : }
     455              : 
     456              : ////////////////////////////////////////////////////////////////////////////////
     457              : 
     458            0 : void IndiElement::setMin( const string &szMin )
     459              : {
     460            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     461            0 :   m_szMin = szMin;
     462            0 : }
     463              : 
     464              : ////////////////////////////////////////////////////////////////////////////////
     465              : 
     466            0 : void IndiElement::setName( const string &szName )
     467              : {
     468            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     469            0 :   m_szName = szName;
     470            0 : }
     471              : 
     472              : ////////////////////////////////////////////////////////////////////////////////
     473              : 
     474            0 : void IndiElement::setStep( const string &szStep )
     475              : {
     476            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     477            0 :   m_szStep = szStep;
     478            0 : }
     479              : 
     480              : ////////////////////////////////////////////////////////////////////////////////
     481              : 
     482            0 : void IndiElement::setSize( const string &szSize )
     483              : {
     484            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     485            0 :   m_szSize = szSize;
     486            0 : }
     487              : 
     488              : ////////////////////////////////////////////////////////////////////////////////
     489              : /// This is an alternate way of calling 'setLightState'.
     490              : 
     491            0 : const IndiElement::LightStateType &IndiElement::operator=( const LightStateType &tValue )
     492              : {
     493            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     494            0 :   m_lsValue = tValue;
     495            0 :   return tValue;
     496            0 : }
     497              : 
     498              : ////////////////////////////////////////////////////////////////////////////////
     499              : 
     500            0 : void IndiElement::setLightState( const LightStateType &tValue )
     501              : {
     502            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     503            0 :   m_lsValue = tValue;
     504            0 : }
     505              : 
     506              : ////////////////////////////////////////////////////////////////////////////////
     507              : /// This is an alternate way of calling 'setSwitchState'.
     508              : 
     509            0 : const IndiElement::SwitchStateType &IndiElement::operator=( const SwitchStateType &tValue )
     510              : {
     511            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     512            0 :   m_ssValue = tValue;
     513            0 :   return tValue;
     514            0 : }
     515              : 
     516              : ////////////////////////////////////////////////////////////////////////////////
     517              : 
     518           54 : void IndiElement::setSwitchState( const SwitchStateType &tValue )
     519              : {
     520           54 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     521           54 :   m_ssValue = tValue;
     522           54 : }
     523              : 
     524              : ////////////////////////////////////////////////////////////////////////////////
     525              : /// Sets the data contained in the value as a string.
     526              : 
     527           12 : void IndiElement::setValue( const string &szValue )
     528              : {
     529           12 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     530           12 :   m_szValue = szValue;
     531           12 : }
     532              : 
     533              : ////////////////////////////////////////////////////////////////////////////////
     534              : /// Sets the data contained in the value as a string.
     535              : 
     536            0 : void IndiElement::setValue( const char *pcValue,
     537              :                             const unsigned int &uiSize )
     538              : {
     539            0 :   pcf::ReadWriteLock::AutoWLock rwAuto( &m_rwData );
     540            0 :   m_szValue.assign( const_cast<char *>( pcValue ), uiSize );
     541            0 : }
     542              : 
     543              : ////////////////////////////////////////////////////////////////////////////////
     544              : 
     545            0 : bool IndiElement::hasValidFormat() const
     546              : {
     547            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     548            0 :   return ( m_szFormat.size() > 0 );
     549            0 : }
     550              : 
     551              : ////////////////////////////////////////////////////////////////////////////////
     552              : 
     553            0 : bool IndiElement::hasValidLabel() const
     554              : {
     555            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     556            0 :   return ( m_szLabel.size() > 0 );
     557            0 : }
     558              : 
     559              : ////////////////////////////////////////////////////////////////////////////////
     560              : 
     561            0 : bool IndiElement::hasValidLightState() const
     562              : {
     563            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     564            0 :   return ( m_lsValue != UnknownLightState );
     565            0 : }
     566              : 
     567              : ////////////////////////////////////////////////////////////////////////////////
     568              : 
     569            0 : bool IndiElement::hasValidMax() const
     570              : {
     571            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     572            0 :   return ( m_szMax.size() > 0 );
     573            0 : }
     574              : 
     575              : ////////////////////////////////////////////////////////////////////////////////
     576              : 
     577            0 : bool IndiElement::hasValidMin() const
     578              : {
     579            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     580            0 :   return ( m_szMin.size() > 0 );
     581            0 : }
     582              : 
     583              : ////////////////////////////////////////////////////////////////////////////////
     584              : 
     585            0 : bool IndiElement::hasValidName() const
     586              : {
     587            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     588            0 :   return ( m_szName.size() > 0 );
     589            0 : }
     590              : 
     591              : ////////////////////////////////////////////////////////////////////////////////
     592              : 
     593            0 : bool IndiElement::hasValidSize() const
     594              : {
     595            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     596            0 :   return ( m_szSize.size() > 0 );
     597            0 : }
     598              : 
     599              : ////////////////////////////////////////////////////////////////////////////////
     600              : 
     601            0 : bool IndiElement::hasValidStep() const
     602              : {
     603            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     604            0 :   return ( m_szStep.size() > 0 );
     605            0 : }
     606              : 
     607              : ////////////////////////////////////////////////////////////////////////////////
     608              : 
     609            0 : bool IndiElement::hasValidSwitchState() const
     610              : {
     611            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     612            0 :   return ( m_ssValue != UnknownSwitchState );
     613            0 : }
     614              : 
     615              : ////////////////////////////////////////////////////////////////////////////////
     616              : 
     617            0 : bool IndiElement::hasValidValue() const
     618              : {
     619            0 :   pcf::ReadWriteLock::AutoRLock rwAuto( &m_rwData );
     620            0 :   return ( m_szValue.size() > 0 );
     621            0 : }
     622              : 
     623              : ////////////////////////////////////////////////////////////////////////////////
     624              : /// Returns the enumerated type given the string type.
     625              : 
     626            0 : IndiElement::LightStateType IndiElement::getLightStateType( const string &szType )
     627              : {
     628            0 :   LightStateType tType = UnknownLightState;
     629              : 
     630            0 :   if ( szType == "Idle" )
     631            0 :     tType = Idle;
     632            0 :   else if ( szType == "Ok" )
     633            0 :     tType = Ok;
     634            0 :   else if ( szType == "Busy" )
     635            0 :     tType = Busy;
     636            0 :   else if ( szType == "Alert" )
     637            0 :     tType = Alert;
     638              : 
     639            0 :   return tType;
     640              : }
     641              : 
     642              : ////////////////////////////////////////////////////////////////////////////////
     643              : /// Returns the string type given the enumerated type.
     644              : 
     645            0 : string IndiElement::getLightStateString( const LightStateType &tType )
     646              : {
     647            0 :   string szType = "";
     648              : 
     649            0 :   switch ( tType )
     650              :   {
     651            0 :     case UnknownLightState:
     652            0 :       szType = "";
     653            0 :       break;
     654            0 :     case Idle:
     655            0 :       szType = "Idle";
     656            0 :       break;
     657            0 :     case Ok:
     658            0 :       szType = "Ok";
     659            0 :       break;
     660            0 :     case Busy:
     661            0 :       szType = "Busy";
     662            0 :       break;
     663            0 :     case Alert:
     664            0 :       szType = "Alert";
     665            0 :       break;
     666              :   }
     667              : 
     668            0 :   return szType;
     669            0 : }
     670              : 
     671              : ////////////////////////////////////////////////////////////////////////////////
     672              : /// Returns the enumerated type given the string type.
     673              : 
     674            0 : IndiElement::SwitchStateType IndiElement::getSwitchStateType( const string &szType )
     675              : {
     676            0 :   SwitchStateType tType = UnknownSwitchState;
     677              : 
     678            0 :   if ( szType == "Off" )
     679            0 :     tType = Off;
     680            0 :   else if ( szType == "On" )
     681            0 :     tType = On;
     682              : 
     683            0 :   return tType;
     684              : }
     685              : 
     686              : ////////////////////////////////////////////////////////////////////////////////
     687              : /// Returns the string type given the enumerated type.
     688              : 
     689            0 : string IndiElement::getSwitchStateString( const SwitchStateType &tType )
     690              : {
     691            0 :   string szType = "";
     692              : 
     693            0 :   switch ( tType )
     694              :   {
     695            0 :     case UnknownSwitchState:
     696            0 :       szType = "";
     697            0 :       break;
     698            0 :     case Off:
     699            0 :       szType = "Off";
     700            0 :       break;
     701            0 :     case On:
     702            0 :       szType = "On";
     703            0 :       break;
     704              :   }
     705              : 
     706            0 :   return szType;
     707            0 : }
     708              : 
     709              : ////////////////////////////////////////////////////////////////////////////////
     710              : /// Returns the string type given the enumerated type.
     711              : 
     712            0 : string IndiElement::convertTypeToString( const Type &tType )
     713              : {
     714            0 :   string szType = "UnknownType";
     715              : 
     716            0 :   switch ( tType )
     717              :   {
     718            0 :     case UnknownType:
     719            0 :       szType = "";
     720            0 :       break;
     721              : 
     722              :     // Define properties.
     723            0 :     case DefBLOB:
     724            0 :       szType = "defBLOB";
     725            0 :       break;
     726            0 :     case DefLight:
     727            0 :       szType = "defLight";
     728            0 :       break;
     729            0 :     case DefNumber:
     730            0 :       szType = "defNumber";
     731            0 :       break;
     732            0 :     case DefSwitch:
     733            0 :       szType = "defSwitch";
     734            0 :       break;
     735            0 :     case DefText:
     736            0 :       szType = "defText";
     737            0 :       break;
     738              : 
     739              :     // Update or set properties.
     740            0 :     case OneBLOB:
     741            0 :       szType = "oneBLOB";
     742            0 :       break;
     743            0 :     case OneLight:
     744            0 :       szType = "oneLight";
     745            0 :       break;
     746            0 :     case OneNumber:
     747            0 :       szType = "oneNumber";
     748            0 :       break;
     749            0 :     case OneSwitch:
     750            0 :       szType = "oneSwitch";
     751            0 :       break;
     752            0 :     case OneText:
     753            0 :       szType = "oneText";
     754            0 :       break;
     755              :   }
     756              : 
     757            0 :   return szType;
     758            0 : }
     759              : 
     760              : ////////////////////////////////////////////////////////////////////////////////
     761              : /// Returns the enumerated type given the tag.
     762              : 
     763            0 : IndiElement::Type IndiElement::convertStringToType( const string &szTag )
     764              : {
     765            0 :   Type tType = UnknownType;
     766              : 
     767              :   // Define properties.
     768            0 :   if ( szTag == "defBLOB" )
     769            0 :     tType = DefBLOB;
     770            0 :   else if ( szTag == "defLight" )
     771            0 :     tType = DefLight;
     772            0 :   else if ( szTag == "defNumber" )
     773            0 :     tType = DefNumber;
     774            0 :   else if ( szTag == "defSwitch" )
     775            0 :     tType = DefSwitch;
     776            0 :   else if ( szTag == "defText" )
     777            0 :     tType = DefText;
     778              : 
     779              :   // Update or set properties.
     780            0 :   else if ( szTag == "oneBLOB" )
     781            0 :     tType = OneBLOB;
     782            0 :   else if ( szTag == "oneLight" )
     783            0 :     tType = OneLight;
     784            0 :   else if ( szTag == "oneNumber" )
     785            0 :     tType = OneNumber;
     786            0 :   else if ( szTag == "oneSwitch" )
     787            0 :     tType = OneSwitch;
     788            0 :   else if ( szTag == "oneText" )
     789            0 :     tType = OneText;
     790              : 
     791            0 :   return tType;
     792              : }
     793              : 
     794              : ////////////////////////////////////////////////////////////////////////////////
        

Generated by: LCOV version 2.0-1