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

setting parameter values management class More...

#include <SettingParameterValues.h>

Classes

struct  SubSettingsKey
 sub settings key More...
 

Public Member Functions

 SettingParameterValues ()
 constructor
 
 SettingParameterValues (const SettingParameterValues &other)
 copy constructor More...
 
virtual ~SettingParameterValues ()
 destructor
 
SettingParameterValuesoperator= (const SettingParameterValues &other)
 the definition of assignment operator More...
 
void clear ()
 clears parameters
 
void setValue (const unsigned int index, const char *value)
 sets parameter value More...
 
void setValue (const char *name, const char *value)
 sets parameter value More...
 
unsigned int getNumberOfParameters ()
 gets the number of parameters More...
 
const char * getParameterName (const unsigned int index)
 gets parameter name More...
 
const char * getParameterValue (const unsigned int index)
 gets parameter value More...
 
const char * getParameterValue (const char *name)
 gets parameter value More...
 
bool getBoolValue (const unsigned int index, const bool df)
 gets boolean value More...
 
bool getBoolValue (const char *name, const bool df)
 gets boolean value More...
 
int getIntValue (const unsigned int index, const int df)
 gets integer value More...
 
int getIntValue (const char *name, const int df)
 gets integer value More...
 
double getDoubleValue (const unsigned int index, const double df)
 gets double value More...
 
double getDoubleValue (const char *name, const double df)
 gets double value More...
 
SettingParameterValuesgetSubParameterValues (const char *key, const char *val=NULL)
 gets sub parameter values More...
 
bool hasSubParameterValues (const char *key, const char *val=NULL)
 check the specified parameter has sub parameters More...
 

Static Public Member Functions

static void writeAllChildParameters (kome::objects::SettingParameterValues &settings, kome::core::Properties &props, const char *prefix)
 write all child parameters More...
 

Protected Member Functions

int getIndex (const char *name)
 gets parameter index from name More...
 

Protected Attributes

std::vector< std::pair
< std::string, std::string > > 
m_values
 
std::vector< std::pair
< SubSettingsKey,
SettingParameterValues * > > 
m_itemValues
 

Detailed Description

setting parameter values management class

Definition at line 33 of file SettingParameterValues.h.

Constructor & Destructor Documentation

kome::objects::SettingParameterValues::SettingParameterValues ( const SettingParameterValues other)

copy constructor

Parameters
[in]otherother settings object

Definition at line 32 of file SettingParameterValues.cpp.

32  {
33  // copy values
34  unsigned int valNum = other.m_values.size();
35  if( valNum > 0 ) {
36  m_values.reserve( valNum );
37 
38  for( unsigned int i = 0; i < valNum; i++ ) {
39  m_values.push_back( other.m_values[ i ] );
40  }
41  }
42 
43  // copy subitems
44  unsigned int itmNum = other.m_itemValues.size();
45  if( itmNum > 0 ) {
46  m_itemValues.reserve( itmNum );
47 
48  for( unsigned int i = 0; i < itmNum; i++ ) {
49  m_itemValues.push_back(
50  std::make_pair( other.m_itemValues[ i ].first, new SettingParameterValues( *( other.m_itemValues[ i ].second ) ))
51  );
52  }
53  }
54 }
setting parameter values management class
std::vector< std::pair< SubSettingsKey, SettingParameterValues * > > m_itemValues
std::vector< std::pair< std::string, std::string > > m_values

Member Function Documentation

bool kome::objects::SettingParameterValues::getBoolValue ( const unsigned int  index,
const bool  df 
)

gets boolean value

Parameters
[in]indexparameter index
[in]dfdefault value
Returns
boolean value

Definition at line 188 of file SettingParameterValues.cpp.

188  {
189  // value
190  const char* value = getParameterValue( index );
191  const bool ret = tobool( value, df );
192 
193  return ret;
194 }
bool tobool(const char *s, bool dfVal)
get true or false from character string.
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

bool kome::objects::SettingParameterValues::getBoolValue ( const char *  name,
const bool  df 
)

gets boolean value

Parameters
[in]nameparameter name
[in]dfdefault value
Returns
boolean value

Definition at line 197 of file SettingParameterValues.cpp.

197  {
198  // value
199  const char* value = getParameterValue( name );
200  const bool ret = tobool( value, df );
201 
202  return ret;
203 }
bool tobool(const char *s, bool dfVal)
get true or false from character string.
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

double kome::objects::SettingParameterValues::getDoubleValue ( const unsigned int  index,
const double  df 
)

gets double value

Parameters
[in]indexparameter index
[in]dfdefault value
Returns
double value

Definition at line 224 of file SettingParameterValues.cpp.

224  {
225  // value
226  const char* value = getParameterValue( index );
227  const double ret = todouble( value, df );
228 
229  return ret;
230 }
const char * getParameterValue(const unsigned int index)
gets parameter value
double todouble(const char *s, const double dfval)
convert string into double

Here is the call graph for this function:

double kome::objects::SettingParameterValues::getDoubleValue ( const char *  name,
const double  df 
)

gets double value

Parameters
[in]nameparameter name
[in]dfdefault value
Returns
double value

Definition at line 233 of file SettingParameterValues.cpp.

233  {
234  // value
235  const char* value = getParameterValue( name );
236  const double ret = todouble( value, df );
237 
238  return ret;
239 }
const char * getParameterValue(const unsigned int index)
gets parameter value
double todouble(const char *s, const double dfval)
convert string into double

Here is the call graph for this function:

int kome::objects::SettingParameterValues::getIndex ( const char *  name)
protected

gets parameter index from name

Parameters
[in]nameparameter name
Returns
parameter index (If negative value, specified parameter name was not found.)

Definition at line 102 of file SettingParameterValues.cpp.

102  {
103  // string object
104  std::string s = NVL( name, "" );
105 
106  // search
107  int idx = -1;
108  for( unsigned int i = 0; i < m_values.size() && idx < 0; i++ ) {
109  if( s.compare( m_values[ i ].first ) == 0 ) {
110  idx = (int)i;
111  }
112  }
113 
114  return idx;
115 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::vector< std::pair< std::string, std::string > > m_values
int kome::objects::SettingParameterValues::getIntValue ( const unsigned int  index,
const int  df 
)

gets integer value

Parameters
[in]indexparameter index
[in]dfdefault value
Returns
integer value

Definition at line 206 of file SettingParameterValues.cpp.

206  {
207  // value
208  const char* value = getParameterValue( index );
209  const int ret = toint( value, 10, df );
210 
211  return ret;
212 }
int toint(const char *s, const int radix, const int dfval)
convert string into integer
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

int kome::objects::SettingParameterValues::getIntValue ( const char *  name,
const int  df 
)

gets integer value

Parameters
[in]nameparameter name
[in]dfdefault value
Returns
integer value

Definition at line 215 of file SettingParameterValues.cpp.

215  {
216  // value
217  const char* value = getParameterValue( name );
218  const int ret = toint( value, 10, df );
219 
220  return ret;
221 }
int toint(const char *s, const int radix, const int dfval)
convert string into integer
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

unsigned int kome::objects::SettingParameterValues::getNumberOfParameters ( )

gets the number of parameters

Returns
the number of parameters

Definition at line 155 of file SettingParameterValues.cpp.

155  {
156  return m_values.size();
157 }
std::vector< std::pair< std::string, std::string > > m_values
const char * kome::objects::SettingParameterValues::getParameterName ( const unsigned int  index)

gets parameter name

Parameters
[in]indexparameter index
Returns
parameter name

Definition at line 160 of file SettingParameterValues.cpp.

160  {
161  if( index >= m_values.size() ) {
162  return NULL;
163  }
164  return m_values[ index ].first.c_str();
165 }
#define NULL
Definition: CoreMacros.h:18
std::vector< std::pair< std::string, std::string > > m_values
const char * kome::objects::SettingParameterValues::getParameterValue ( const unsigned int  index)

gets parameter value

Parameters
[in]indexparameter index
Returns
parameter value

Definition at line 168 of file SettingParameterValues.cpp.

168  {
169  if( index >= m_values.size() ) {
170  return NULL;
171  }
172  return m_values[ index ].second.c_str(); //最終的にはこれがgetParameterValue( name )から返る
173 }
#define NULL
Definition: CoreMacros.h:18
std::vector< std::pair< std::string, std::string > > m_values
const char * kome::objects::SettingParameterValues::getParameterValue ( const char *  name)

gets parameter value

Parameters
[in]nameparameter name
Returns
parameter value (If NULL, there is no parameter that has specified name.)

Definition at line 176 of file SettingParameterValues.cpp.

176  {
177  // index
178  int idx = getIndex( name );
179  if( idx < 0 ) {
180  return NULL;
181  }
182 
183  // value
184  return getParameterValue( idx );
185 }
#define NULL
Definition: CoreMacros.h:18
int getIndex(const char *name)
gets parameter index from name
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

SettingParameterValues * kome::objects::SettingParameterValues::getSubParameterValues ( const char *  key,
const char *  val = NULL 
)

gets sub parameter values

Parameters
[in]keyparameter key
[in]valparameter value
Returns
sub parameter values

Definition at line 242 of file SettingParameterValues.cpp.

242  {
243  // parameters
244  if( val == NULL ) {
245  val = getParameterValue( key );
246  }
247 
248  // key, value
249  std::string k = NVL( key, "" );
250  if( val == NULL ) {
251  val = getParameterValue( key );
252  }
253  std::string v = NVL( val, "" );
254 
255  // search
256  int itemIdx = -1;
257  for( unsigned int i = 0; i < m_itemValues.size() && itemIdx < 0; i++ ) {
258  if( k.compare( m_itemValues[ i ].first.key ) == 0
259  && v.compare( m_itemValues[ i ].first.value ) == 0 ) {
260  itemIdx = (int)i;
261  }
262  }
263 
264  // create new sub settings
265  if( itemIdx < 0 ) {
266  itemIdx = (int)m_itemValues.size();
268 
269  m_itemValues.resize( m_itemValues.size() + 1 );
270 
271  m_itemValues.back().first.key = k;
272  m_itemValues.back().first.value = v;
273  m_itemValues.back().second = subVals;
274  }
275 
276  return m_itemValues[ itemIdx ].second;
277 }
setting parameter values management class
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::vector< std::pair< SubSettingsKey, SettingParameterValues * > > m_itemValues
#define NULL
Definition: CoreMacros.h:18
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

bool kome::objects::SettingParameterValues::hasSubParameterValues ( const char *  key,
const char *  val = NULL 
)

check the specified parameter has sub parameters

Parameters
[in]keyparameter key
[in]valparameter value
Returns
If true, the specified parameter has sub parameters

Definition at line 280 of file SettingParameterValues.cpp.

280  {
281  // parameters
282  if( val == NULL ) {
283  val = getParameterValue( key );
284  }
285 
286  // key, value
287  std::string k = NVL( key, "" );
288  if( val == NULL ) {
289  val = getParameterValue( key );
290  }
291  std::string v = NVL( val, "" );
292 
293  // search
294  int itemIdx = -1;
295  for( unsigned int i = 0; i < m_itemValues.size() && itemIdx < 0; i++ ) {
296  if( k.compare( m_itemValues[ i ].first.key ) == 0
297  && v.compare( m_itemValues[ i ].first.value ) == 0 ) {
298  itemIdx = (int)i;
299  }
300  }
301 
302  return ( itemIdx >= 0 );
303 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::vector< std::pair< SubSettingsKey, SettingParameterValues * > > m_itemValues
#define NULL
Definition: CoreMacros.h:18
const char * getParameterValue(const unsigned int index)
gets parameter value

Here is the call graph for this function:

SettingParameterValues & kome::objects::SettingParameterValues::operator= ( const SettingParameterValues other)

the definition of assignment operator

Parameters
[in]otherother settings object
Returns
assigned settings object

Definition at line 57 of file SettingParameterValues.cpp.

57  {
58  // copy values
59  unsigned int valNum = other.m_values.size();
60  if( valNum > 0 ) {
61  m_values.reserve( valNum );
62 
63  for( unsigned int i = 0; i < valNum; i++ ) {
64  m_values.push_back( other.m_values[ i ] );
65  }
66  }
67 
68  // copy subitems
69  unsigned int itmNum = other.m_itemValues.size();
70  if( itmNum > 0 ) {
71  m_itemValues.reserve( itmNum );
72 
73  for( unsigned int i = 0; i < itmNum; i++ ) {
74  m_itemValues.push_back(
75  std::make_pair(
76  other.m_itemValues[ i ].first,
77  new SettingParameterValues( *( other.m_itemValues[ i ].second ) )
78  )
79  );
80  }
81  }
82 
83  return *this;
84 }
setting parameter values management class
std::vector< std::pair< SubSettingsKey, SettingParameterValues * > > m_itemValues
std::vector< std::pair< std::string, std::string > > m_values
void kome::objects::SettingParameterValues::setValue ( const unsigned int  index,
const char *  value 
)

sets parameter value

Parameters
[in]indexparameter index
[in]valueparameter value

Definition at line 118 of file SettingParameterValues.cpp.

118  {
119  // check the index
120  if( index >= m_values.size() ) {
121  return;
122  }
123 
124  // value
125  std::string v = NVL( value, "" );
126  if( v.compare( MSPP_SETTINGS_NONE_VALUE ) == 0 ) {
127  v = "";
128  }
129 
130  // set value
131  m_values[ index ].second = v;
132 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::vector< std::pair< std::string, std::string > > m_values
void kome::objects::SettingParameterValues::setValue ( const char *  name,
const char *  value 
)

sets parameter value

Parameters
[in]nameparameter name
[in]valueparameter value

Definition at line 135 of file SettingParameterValues.cpp.

135  {
136  // index
137  int idx = getIndex( name );
138 
139  // value
140  std::string v = NVL( value, "" );
141  if( v.compare( MSPP_SETTINGS_NONE_VALUE ) == 0 ) {
142  v = "";
143  }
144 
145  // set value
146  if( idx < 0 ) {
147  m_values.push_back( std::make_pair ( NVL( name, "" ), v ) );
148  }
149  else {
150  setValue( idx, v.c_str() );
151  }
152 }
void setValue(const unsigned int index, const char *value)
sets parameter value
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
int getIndex(const char *name)
gets parameter index from name
std::vector< std::pair< std::string, std::string > > m_values

Here is the call graph for this function:

static void kome::objects::SettingParameterValues::writeAllChildParameters ( kome::objects::SettingParameterValues settings,
kome::core::Properties props,
const char *  prefix 
)
static

write all child parameters

Parameters
[in]settingsparameters
[out]propsproperty objects to be stored.
[in]prefixprefix string

Definition at line 306 of file SettingParameterValues.cpp.

310  {
311  // prefix
312  std::string p = NVL( prefix, "" );
313 
314  // write
315  for( unsigned int i = 0; i < settings.getNumberOfParameters(); i++ ) {
316  std::string name = settings.getParameterName( i );
317  std::string value = settings.getParameterValue( i );
318  std::string propName = name;
319  if( !p.empty() ) {
320  propName = FMT( "%s : %s", p.c_str(), name.c_str() );
321  }
322 
323  props.setValue( propName.c_str(), value.c_str() );
324 
325  // child
326  if( settings.hasSubParameterValues( name.c_str(), value.c_str() ) ) {
327  kome::objects::SettingParameterValues* child = settings.getSubParameterValues( name.c_str(), value.c_str() );
328  writeAllChildParameters( *child, props, propName.c_str() );
329  }
330  }
331 }
setting parameter values management class
bool hasSubParameterValues(const char *key, const char *val=NULL)
check the specified parameter has sub parameters
void setValue(const char *key, const char *value)
sets parameter value
Definition: Properties.cpp:39
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
const char * getParameterValue(const unsigned int index)
gets parameter value
const char * getParameterName(const unsigned int index)
gets parameter name
unsigned int getNumberOfParameters()
gets the number of parameters
static void writeAllChildParameters(kome::objects::SettingParameterValues &settings, kome::core::Properties &props, const char *prefix)
write all child parameters
SettingParameterValues * getSubParameterValues(const char *key, const char *val=NULL)
gets sub parameter values

Here is the call graph for this function:

Member Data Documentation

std::vector< std::pair< SubSettingsKey, SettingParameterValues* > > kome::objects::SettingParameterValues::m_itemValues
protected

item values

Definition at line 68 of file SettingParameterValues.h.

std::vector< std::pair< std::string, std::string > > kome::objects::SettingParameterValues::m_values
protected

values

Definition at line 65 of file SettingParameterValues.h.


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