Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::objects::StatusManager Class Reference

status variables management class More...

#include <StatusManager.h>

Public Member Functions

void setValue (const char *name, const char *value)
 sets status value More...
 
const char * getValue (const char *name)
 gets status value More...
 
bool hasStatus (const char *name)
 returns true if there is status variable specified name More...
 
unsigned int getNumberOfStatuses ()
 gets the number of status variables More...
 
const char * getStatusName (const unsigned int index)
 gets status variable name More...
 
const char * getStatusValue (const unsigned int index)
 gets status value More...
 
void setToIniFile (kome::core::IniFile &ini, const char *section)
 sets status values to ini file information object More...
 
void getFromIniFile (kome::core::IniFile &ini, const char *section)
 gets status values from ini file information object More...
 

Static Public Member Functions

static StatusManagergetInstance ()
 gets status manager object More...
 

Protected Member Functions

 StatusManager ()
 constructor
 
virtual ~StatusManager ()
 destructor
 

Protected Attributes

std::map< std::string,
std::string > 
m_statusMap
 
std::vector< std::string > m_statuses
 

Detailed Description

status variables management class

Definition at line 24 of file StatusManager.h.

Member Function Documentation

void kome::objects::StatusManager::getFromIniFile ( kome::core::IniFile ini,
const char *  section 
)

gets status values from ini file information object

Parameters
[in]iniini file information object
[in]sectionsection name

Definition at line 116 of file StatusManager.cpp.

116  {
117  // get from ini file
118  for( unsigned int i = 0; i < ini.getNumberOfParameters( section ); i++ ) {
119  setValue( ini.getParameterName( section, i ), ini.getParameterValue( section, i ) );
120  }
121 }
const char * getParameterName(const char *section, const unsigned int index)
gets parameter name
Definition: IniFile.cpp:360
const char * getParameterValue(const char *section, const unsigned int index)
gets parameter value
Definition: IniFile.cpp:372
unsigned int getNumberOfParameters(const char *section)
gets the number of parameters specified section
Definition: IniFile.cpp:348
void setValue(const char *name, const char *value)
sets status value

Here is the call graph for this function:

static StatusManager & kome::objects::StatusManager::getInstance ( )
static

gets status manager object

Returns
status manager object (This is the only object.)

Definition at line 134 of file StatusManager.cpp.

134  {
135  // create object (This is the only object)
136  static StatusManager mgr;
137 
138  return mgr;
139 }
status variables management class
Definition: StatusManager.h:24
unsigned int kome::objects::StatusManager::getNumberOfStatuses ( )

gets the number of status variables

Returns
the number of status variables

Definition at line 93 of file StatusManager.cpp.

93  {
94  return m_statuses.size();
95 }
std::vector< std::string > m_statuses
Definition: StatusManager.h:43
const char * kome::objects::StatusManager::getStatusName ( const unsigned int  index)

gets status variable name

Parameters
[in]indexstatus variable index
Returns
status variable name (If the index is illegal, this method returns NULL.)

Definition at line 98 of file StatusManager.cpp.

98  {
99  // check the parameter
100  if( index >= m_statuses.size() ) {
101  return NULL;
102  }
103 
104  return m_statuses[ index ].c_str();
105 }
std::vector< std::string > m_statuses
Definition: StatusManager.h:43
#define NULL
Definition: CoreMacros.h:18
const char * kome::objects::StatusManager::getStatusValue ( const unsigned int  index)

gets status value

Parameters
[in]indexstatus variable index
Returns
status value (If the index is illegal, this method returns NULL.)

Definition at line 124 of file StatusManager.cpp.

124  {
125  // check the parameter
126  if( index >= m_statuses.size() ) {
127  return NULL;
128  }
129 
130  return m_statusMap[ m_statuses[ index ] ].c_str();
131 }
std::vector< std::string > m_statuses
Definition: StatusManager.h:43
#define NULL
Definition: CoreMacros.h:18
std::map< std::string, std::string > m_statusMap
Definition: StatusManager.h:40
const char * kome::objects::StatusManager::getValue ( const char *  name)

gets status value

Parameters
[in]namestatus name
Returns
status value

Definition at line 76 of file StatusManager.cpp.

76  {
77  // check the map
78  if( m_statusMap.find( name ) != m_statusMap.end() ) {
79  return m_statusMap[ NVL( name, "" ) ].c_str();
80  }
81 
82  return NULL;
83 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
#define NULL
Definition: CoreMacros.h:18
std::map< std::string, std::string > m_statusMap
Definition: StatusManager.h:40
bool kome::objects::StatusManager::hasStatus ( const char *  name)

returns true if there is status variable specified name

Parameters
[in]namestatus name
Returns
true if there is status variable specified name

Definition at line 86 of file StatusManager.cpp.

86  {
87  const char* val = getValue( name );
88 
89  return ( val != NULL );
90 }
#define NULL
Definition: CoreMacros.h:18
const char * getValue(const char *name)
gets status value

Here is the call graph for this function:

void kome::objects::StatusManager::setToIniFile ( kome::core::IniFile ini,
const char *  section 
)

sets status values to ini file information object

Parameters
[out]iniini file information object to be stored values
[in]sectionsection name

Definition at line 108 of file StatusManager.cpp.

108  {
109  // set to ini file
110  for( unsigned int i = 0; i < m_statuses.size(); i++ ) {
111  ini.setString( section, m_statuses[ i ].c_str(), m_statusMap[ m_statuses[ i ] ].c_str() );
112  }
113 }
std::vector< std::string > m_statuses
Definition: StatusManager.h:43
void setString(const char *section, const char *key, const char *value)
sets string value
Definition: IniFile.cpp:64
std::map< std::string, std::string > m_statusMap
Definition: StatusManager.h:40

Here is the call graph for this function:

void kome::objects::StatusManager::setValue ( const char *  name,
const char *  value 
)

sets status value

Parameters
[in]namestatus name
[in]valuestatus value

Definition at line 35 of file StatusManager.cpp.

35  {
36  // create string object
37  std::string n = NVL( name, "" );
38  std::string v = NVL( value, "" );
39 
40  // get old value and add name to array
41  std::string oldValue;
42  bool flg = hasStatus( name );
43  if( flg ) {
44  oldValue = m_statusMap[ n ];
45  }
46  else {
47  m_statuses.push_back( n );
48  }
49 
50  // set value to map
51  if( value == NULL ) { // remove
52  m_statusMap.erase( n );
53  int idx = -1;
54  for( int i = 0; i < (int)m_statuses.size() && idx < 0; i++ ) {
55  if( m_statuses[ i ].compare( n ) == 0 ) {
56  idx = i;
57  }
58  }
59  if( idx >= 0 ) {
60  m_statuses.erase( m_statuses.begin() + idx );
61  }
62 
63  if( flg ) {
64  LOG_DEBUG( FMT( "Removing status value [%s=%s]", n.c_str(), oldValue.c_str() ) );
65  }
66  }
67  else { // update
68  m_statusMap[ n ] = v;
69  if( v.compare( oldValue ) != 0 ) {
70  LOG_DEBUG( FMT( "Setting status value [%s=%s]", n.c_str(), v.c_str() ) );
71  }
72  }
73 }
std::vector< std::string > m_statuses
Definition: StatusManager.h:43
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
#define NULL
Definition: CoreMacros.h:18
bool hasStatus(const char *name)
returns true if there is status variable specified name
std::map< std::string, std::string > m_statusMap
Definition: StatusManager.h:40

Here is the call graph for this function:

Member Data Documentation

std::vector< std::string > kome::objects::StatusManager::m_statuses
protected

the array of status name

Definition at line 43 of file StatusManager.h.

std::map< std::string, std::string > kome::objects::StatusManager::m_statusMap
protected

status values map

Definition at line 40 of file StatusManager.h.


The documentation for this class was generated from the following files: