1 // File: Config_PropManager.cpp
2 // Created: 13 Aug 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "Config_PropManager.h"
8 std::map<std::string, Config_Properties> Config_PropManager::myPropMap;
12 bool Config_PropManager::registerProp(const std::string& theOwnerId,
13 const std::string& theSection,
14 const std::string& theName,
15 const std::string& theTitle,
16 Config_Prop::PropType theType,
17 const std::string& theValue)
19 Config_Prop* aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
20 return registerProp(theOwnerId, aProp);
23 bool Config_PropManager::registerProp(const std::string& theOwnerId,
26 if (myPropMap.find(theOwnerId) == myPropMap.end()) {
27 Config_Properties aPropList;
28 aPropList.push_back(theProp);
29 myPropMap[theOwnerId] = aPropList;
31 myPropMap[theOwnerId].push_back(theProp);
36 std::list<std::string> Config_PropManager::getOwners()
38 std::list<std::string> aKeys;
39 std::map<std::string, Config_Properties>::const_iterator aIt;
40 for (aIt = myPropMap.cbegin(); aIt != myPropMap.cend(); ++aIt)
41 aKeys.push_back((*aIt).first);
45 Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId)
47 return myPropMap[theOwnerId];
51 std::list<std::string> Config_PropManager::getSections(const std::string& theOwnerId)
53 std::list<std::string> aSections;
54 Config_Properties aProps = getProperties(theOwnerId);
55 Config_Properties::const_iterator aIt;
56 for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) {
57 const Config_Prop* aProp = (*aIt);
58 aSections.push_back(aProp->section());
64 Config_Properties Config_PropManager::getProperties(const std::string& theOwnerId,
65 const std::string& theSection)
67 Config_Properties aProps = getProperties(theOwnerId);
68 Config_Properties aRes;
69 Config_Properties::iterator aIt;
70 for (aIt = aProps.begin(); aIt != aProps.end(); aIt++) {
71 Config_Prop* aProp = (*aIt);
72 if (aProp->section() == theSection)
73 aRes.push_back(aProp);
79 std::string Config_PropManager::value(const std::string& theOwnerId,
80 const std::string& theSection,
81 const std::string& theName,
82 const std::string& theDefault)
84 Config_Properties aProps = getProperties(theOwnerId, theSection);
85 Config_Properties::const_iterator aIt;
86 for (aIt = aProps.cbegin(); aIt != aProps.cend(); aIt++) {
87 Config_Prop* aProp = (*aIt);
88 if (aProp->name() == theName)
89 return aProp->value();
95 std::vector<int> stringToRGB(const std::string& theColor)
97 std::vector<int> aRes(3);
99 int aPos = theColor.find(",");
102 std::size_t length = theColor.copy(aBuf, aPos, 0);
108 int aNPos = theColor.find(",", aPos + 1);
109 length = theColor.copy(aBuf, aNPos - aPos - 1, aPos + 1);
115 length = theColor.copy(aBuf, theColor.length() - aNPos - 1, aNPos + 1);