Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
CommonParameterManager.cpp
Go to the documentation of this file.
1 
11 #include "stdafx.h"
12 #include "CommonParameterManager.h"
13 #include "MsppManager.h"
14 #include "IniFile.h"
15 
16 #include <iostream>
17 #include <boost/regex.hpp>
18 #include <boost/algorithm/string/case_conv.hpp>
19 
20 
21 using namespace kome::core;
22 
23 
24 #include <crtdbg.h>
25 #ifdef _DEBUG
26  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
27  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
28 #endif // _DEBUG
29 
30 
31 #define SECTION "Common Parameters"
32 
33 // constructor
35  m_paramInfo.clear();
36 }
37 
38 // destructor
40 }
41 
42 // get number of parameters
44  return m_paramInfo.size();
45 }
46 
47 // get parameter name
48 std::string CommonParameterManager::getParameterName( unsigned int index ){
49  if( index >= m_paramInfo.size() ) {
50  return NULL;
51  }
52 
53  return m_paramInfo[ index ].paramName;
54 }
55 
56 // set parameter
57 void CommonParameterManager::setParameter( std::string paramName, std::string paramValue, bool tempFlg ){
58  for( unsigned int i=0; i < m_paramInfo.size(); i++ ){
59  if( paramName.compare( m_paramInfo[i].paramName ) == 0 ){
60  return;
61  }
62  }
63 
64  ParamInfo info;
65  info.paramName = paramName;
66  info.paramValue = paramValue;
67  info.tempFlg = tempFlg;
68 
69  m_paramInfo.push_back( info );
70 
71  if( !tempFlg ){
72  setIniString( paramName, paramValue );
73  }
74 }
75 
76 // set ini strign
77 void CommonParameterManager::setIniString( std::string strKey, std::string strValue ){
78  // ini file
80  kome::core::IniFile* ini = msppMgr.getIniFile();
81 
82  const char* strRegex = "([^0-9a-zA-Z])";
83  boost::regex reg_exp(strRegex);
84 
85  std::string replace = "_";
86  std::string result = "";
87 
88  // replace
89  result = boost::regex_replace( strKey, reg_exp, replace, boost::format_all );
90  // Converted to uppercase.
91  boost::algorithm::to_upper(result);
92 
93  // set string
94  ini->setString( SECTION, result.c_str(), strValue.c_str() );
95 }
96 
97 // get parameter
98 std::string CommonParameterManager::getParameter( std::string paramName, std::string defaultName ){
99  std::string str = defaultName;
100  for( unsigned int i=0; i < m_paramInfo.size(); i++ ){
101  if( paramName.compare( m_paramInfo[i].paramName ) == 0 ){
102  if( !m_paramInfo[i].paramValue.empty() ){
103  str = m_paramInfo[i].paramValue;
104  }
105  break;
106  }
107  }
108 
109  return str;
110 }
111 
112 // is temporary parameter
114  if( index >= m_paramInfo.size() ) {
115  return true;
116  }
117 
118  return m_paramInfo[ index ].tempFlg;
119 }
120 
121 // get instance
123  // create object (This is the only object.)
124  static CommonParameterManager mgr;
125 
126  return mgr;
127 }
static MsppManager & getInstance()
gets MsppManager object (This is the only object.)
int getNumberOfParameters()
gets the number of parameters variables
Mass++ manager class.
Definition: MsppManager.h:28
IniFile * getIniFile()
gets ini file
void setParameter(std::string paramName, std::string paramValue, bool tempFlg)
sets parameter
interfaces of IniFile class
#define NULL
Definition: CoreMacros.h:18
implements of MsppManager class
std::string getParameter(std::string paramName, std::string defaultName)
gets parameter
bool isTemporaryParameter(unsigned int index)
is temporary parameter
common parameter manager class
static CommonParameterManager & getInstance()
gets common parameter management object.
std::string getParameterName(unsigned int index)
gets parameters variable name
interfaces of common parameter manager class
ini file management class
Definition: IniFile.h:30
void setString(const char *section, const char *key, const char *value)
sets string value
Definition: IniFile.cpp:64