Mercurial > hg > aimc
comparison src/Support/Parameters.cc @ 8:fcbf85ce59fb
- Lots of changes to make cpplint happy. It still complains about header guards, but that's pretty much it now.
author | tomwalters |
---|---|
date | Thu, 18 Feb 2010 21:12:41 +0000 |
parents | bc394a985042 |
children | 491b1b1d1dc5 |
comparison
equal
deleted
inserted
replaced
7:1a1988ec40e7 | 8:fcbf85ce59fb |
---|---|
14 // GNU General Public License for more details. | 14 // GNU General Public License for more details. |
15 // | 15 // |
16 // You should have received a copy of the GNU General Public License | 16 // You should have received a copy of the GNU General Public License |
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 //! | 19 /*! |
20 //! \file | 20 * \file |
21 //! \brief Main parameters store | 21 * \brief Main parameters store |
22 //! | 22 * |
23 //! \author Willem van Engen <cnbh@willem.engen.nl> | 23 * \author Willem van Engen <cnbh@willem.engen.nl> |
24 //! \date created 2006/09/21 | 24 * \date created 2006/09/21 |
25 //! \version \$Id: Parameters.cc 4 2010-02-03 18:44:58Z tcw $ | 25 * \version \$Id: Parameters.cc 4 2010-02-03 18:44:58Z tcw $ |
26 */ | |
26 | 27 |
27 #include <stdio.h> | 28 #include <stdio.h> |
28 #include <stdlib.h> | 29 #include <stdlib.h> |
29 #include <string.h> | 30 #include <string.h> |
30 | 31 |
128 unsigned int Parameters::GetUInt(const char *sName) { | 129 unsigned int Parameters::GetUInt(const char *sName) { |
129 return atoi(GetString(sName)); | 130 return atoi(GetString(sName)); |
130 } | 131 } |
131 | 132 |
132 float Parameters::GetFloat(const char *sName) { | 133 float Parameters::GetFloat(const char *sName) { |
133 return (float)atof(GetString(sName)); | 134 return atof(GetString(sName)); |
134 } | 135 } |
135 | 136 |
136 bool Parameters::GetBool(const char *sName) { | 137 bool Parameters::GetBool(const char *sName) { |
137 const char *sVal = GetString(sName); | 138 const char *sVal = GetString(sName); |
138 if (strcmp(sVal, "true")==0 || strcmp(sVal, "on")==0 || | 139 if (strcmp(sVal, "true") == 0 || strcmp(sVal, "on") == 0 || |
139 strcmp(sVal, "yes")==0 || strcmp(sVal, "1")==0 || | 140 strcmp(sVal, "yes") == 0 || strcmp(sVal, "1") == 0 || |
140 strcmp(sVal, "y")==0 || strcmp(sVal, "t")==0) | 141 strcmp(sVal, "y") == 0 || strcmp(sVal, "t") == 0) |
141 return true; | 142 return true; |
142 else | 143 else |
143 return false; | 144 return false; |
144 } | 145 } |
145 | 146 |
146 bool Parameters::IsSet(const char *sName) { | 147 bool Parameters::IsSet(const char *sName) { |
147 AIM_ASSERT(m_pIni); | 148 AIM_ASSERT(m_pIni); |
148 return m_pIni->GetValue(m_SDefaultIniSection, sName, NULL)!=NULL; | 149 return m_pIni->GetValue(m_SDefaultIniSection, sName, NULL) != NULL; |
149 } | 150 } |
150 | 151 |
151 bool Parameters::Parse(const char *sCmd) { | 152 bool Parameters::Parse(const char *sCmd) { |
152 //! \todo There is some code duplication here from Parameters::Merge() | 153 /*! \todo There is some code duplication here from Parameters::Merge() |
154 */ | |
153 | 155 |
154 CSimpleIniCase *pIni2 = new CSimpleIniCase(false, false, true); | 156 CSimpleIniCase *pIni2 = new CSimpleIniCase(false, false, true); |
155 AIM_ASSERT(pIni2); | 157 AIM_ASSERT(pIni2); |
156 if (pIni2->Load(sCmd, strlen(sCmd)) < 0) { | 158 if (pIni2->Load(sCmd, strlen(sCmd)) < 0) { |
157 LOG_ERROR(_T("Could not parse option '%s'"), sCmd); | 159 LOG_ERROR(_T("Could not parse option '%s'"), sCmd); |
191 sParamFilename, m_iNestCount); | 193 sParamFilename, m_iNestCount); |
192 return false; | 194 return false; |
193 } | 195 } |
194 m_iNestCount++; | 196 m_iNestCount++; |
195 | 197 |
196 if ( (siErr=m_pIni->LoadFile(sParamFilename))<0 ) { | 198 if ((siErr=m_pIni->LoadFile(sParamFilename)) < 0) { |
197 // Don't complain if file not found, but do return error | 199 // Don't complain if file not found, but do return error |
198 if (siErr!=SI_FILE) | 200 if (siErr != SI_FILE) |
199 LOG_ERROR(_T("Couldn't parse parameters from '%s'"), sParamFilename); | 201 LOG_ERROR(_T("Couldn't parse parameters from '%s'"), sParamFilename); |
200 m_iNestCount--; | 202 m_iNestCount--; |
201 return false; | 203 return false; |
202 } | 204 } |
203 | 205 |
253 LOG_ERROR(_T("Couldn't create parameters file '%s' to save to"), | 255 LOG_ERROR(_T("Couldn't create parameters file '%s' to save to"), |
254 sParamFilename); | 256 sParamFilename); |
255 return false; | 257 return false; |
256 } | 258 } |
257 | 259 |
258 if ((siErr = m_pIni->SaveFile(pSaveFile)) < 0 ) { | 260 if ((siErr = m_pIni->SaveFile(pSaveFile)) < 0) { |
259 LOG_ERROR(_T("Couldn't save parameters in file '%s'"), sParamFilename); | 261 LOG_ERROR(_T("Couldn't save parameters in file '%s'"), sParamFilename); |
260 return false; | 262 return false; |
261 } | 263 } |
262 | 264 |
263 fclose(pSaveFile); | 265 fclose(pSaveFile); |
268 std::string Parameters::WriteString() { | 270 std::string Parameters::WriteString() { |
269 AIM_ASSERT(m_pIni); | 271 AIM_ASSERT(m_pIni); |
270 SI_Error siErr; | 272 SI_Error siErr; |
271 std::string output_string; | 273 std::string output_string; |
272 | 274 |
273 if ((siErr = m_pIni->Save(output_string)) < 0 ) { | 275 if ((siErr = m_pIni->Save(output_string)) < 0) { |
274 LOG_ERROR(_T("Couldn't write parameters to string")); | 276 LOG_ERROR(_T("Couldn't write parameters to string")); |
275 return false; | 277 return false; |
276 } | 278 } |
277 return output_string; | 279 return output_string; |
278 } | 280 } |