+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
// File: Config_PropManager.cpp
// Created: 13 Aug 2014
// Author: Vitaly SMETANNIKOV
std::vector<int> stringToRGB(const std::string& theColor);
int stringToInteger(const std::string& theInt);
double stringToDouble(const std::string& theDouble);
+bool stringToBoolean(const std::string& theInt);
Config_Properties Config_PropManager::myProps;
-bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType,
- const std::string& theValue)
+Config_Prop* Config_PropManager::registerProp(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theTitle,
+ Config_Prop::PropType theType,
+ const std::string& theDefaultValue)
{
Config_Prop* aProp = findProp(theSection, theName);
+
if (aProp) {
+ if (aProp->value() == "") {
+ aProp->setValue(theDefaultValue);
+ }
+ if (aProp->defaultValue() == "") {
+ aProp->setDefaultValue(theDefaultValue);
+ }
if (aProp->type() == Config_Prop::Disabled) {
aProp->setType(theType);
aProp->setTitle(theTitle);
- return true;
}
- return false;
}
- aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
- myProps.push_back(aProp);
- return true;
+ else {
+ aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue);
+ myProps.push_back(aProp);
+ }
+ return aProp;
}
Config_Prop* Config_PropManager::findProp(const std::string& theSection, const std::string& theName)
return stringToDouble(aStr);
}
+bool Config_PropManager::boolean(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault)
+{
+ std::string aStr = string(theSection, theName, theDefault);
+ return stringToBoolean(aStr);
+}
+
std::vector<int> stringToRGB(const std::string& theColor)
{
std::vector<int> aRes(3);
aBuf[1] = theColor[6];
aRes[2] = strtol(aBuf, &aP, 16);
} else {
- int aPos = theColor.find(",");
+ int aPos = (int)theColor.find(",");
char aBuf[10];
// Get Red
std::size_t length = theColor.copy(aBuf, aPos, 0);
aRes[0] = atoi(aBuf);
// Get Green
- int aNPos = theColor.find(",", aPos + 1);
+ int aNPos = (int)theColor.find(",", aPos + 1);
length = theColor.copy(aBuf, aNPos - aPos - 1, aPos + 1);
aBuf[length] = '\0';
aRes[1] = atoi(aBuf);
char* p;
return strtod(theDouble.c_str(), &p);
}
+
+bool stringToBoolean(const std::string& theBoolean)
+{
+ return theBoolean == "true";
+}