2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
24 $Date: 2007/04/07 13:29:07 $
35 #include "common_settings.h"
38 //-----------------------------------------------------------------------------
39 COMMON_SETTINGS::COMMON_SETTINGS()
43 //-----------------------------------------------------------------------------
44 COMMON_SETTINGS::~COMMON_SETTINGS()
48 //-----------------------------------------------------------------------------
49 int COMMON_SETTINGS::ParseYesNo(const string & value, bool * val)
51 if (0 == strcasecmp(value.c_str(), "yes"))
56 if (0 == strcasecmp(value.c_str(), "no"))
62 strError = "Incorrect value \'" + value + "\'.";
65 //-----------------------------------------------------------------------------
66 int COMMON_SETTINGS::ParseInt(const string & value, int * val)
69 *val = strtol(value.c_str(), &res, 10);
72 strError = "Cannot convert \'" + value + "\' to integer.";
77 //-----------------------------------------------------------------------------
78 int COMMON_SETTINGS::ParseIntInRange(const string & value, int min, int max, int * val)
80 if (ParseInt(value, val) != 0)
83 if (*val < min || *val > max)
85 strError = "Value \'" + value + "\' out of range.";
91 //-----------------------------------------------------------------------------
92 int COMMON_SETTINGS::ParseDouble(const std::string & value, double * val)
95 *val = strtod(value.c_str(), &res);
98 strError = "Cannot convert \'" + value + "\' to double.";
103 //-----------------------------------------------------------------------------
104 int COMMON_SETTINGS::ParseDoubleInRange(const std::string & value, double min, double max, double * val)
106 if (ParseDouble(value, val) != 0)
109 if (*val < min || *val > max)
111 strError = "Value \'" + value + "\' out of range.";
117 //-----------------------------------------------------------------------------
118 string COMMON_SETTINGS::GetStrError() const
122 //-----------------------------------------------------------------------------
123 int COMMON_SETTINGS::Reload ()
125 return ReadSettings();
127 //-----------------------------------------------------------------------------