From 5c1847adf480d8fe7c0f8cfa75f94d8f2795e381 Mon Sep 17 00:00:00 2001 From: doitux Date: Sat, 22 Sep 2007 23:58:17 +0000 Subject: [PATCH] add read/writeIntList support for ConfigFile (for blindslist) --- src/config/configfile.cpp | 180 ++++++++++++++++++++++++++++++++++---- src/config/configfile.h | 9 +- src/pokerth.cpp | 2 +- 3 files changed, 171 insertions(+), 20 deletions(-) diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 66b11640..89bd1e50 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -55,7 +55,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; } } // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 37; + configRev = 40; //standard defaults logOnOffDefault = "1"; @@ -175,6 +175,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) configList.push_back(ConfigInfo("RaiseSmallBlindEveryMinutes", CONFIG_TYPE_INT, "5")); configList.push_back(ConfigInfo("AlwaysDoubleBlinds", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ManualBlindsOrder", CONFIG_TYPE_INT, "0")); + configList.push_back(ConfigInfo("ManualBlindsList", CONFIG_TYPE_INT_LIST, "Blind")); configList.push_back(ConfigInfo("GameSpeed", CONFIG_TYPE_INT, "4")); configList.push_back(ConfigInfo("EngineVersion", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("PauseBetweenHands", CONFIG_TYPE_INT, "0")); @@ -188,6 +189,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) configList.push_back(ConfigInfo("NetRaiseSmallBlindEveryMinutes", CONFIG_TYPE_INT, "5")); configList.push_back(ConfigInfo("NetAlwaysDoubleBlinds", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("NetManualBlindsOrder", CONFIG_TYPE_INT, "0")); + configList.push_back(ConfigInfo("NetManualBlindsList", CONFIG_TYPE_INT_LIST, "NetBlind")); configList.push_back(ConfigInfo("NetGameSpeed", CONFIG_TYPE_INT, "4")); configList.push_back(ConfigInfo("NetEngineVersion", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("NetTimeOutPlayerAction", CONFIG_TYPE_INT, "20")); @@ -281,7 +283,8 @@ void ConfigFile::fillBuffer() { boost::mutex::scoped_lock lock(m_configMutex); size_t i; - string tempString(""); + string tempString1(""); + string tempString2(""); TiXmlDocument doc(configFileName); @@ -294,9 +297,28 @@ void ConfigFile::fillBuffer() { if ( conf ) { - const char *tmpStr = conf->Attribute("value"); - if (tmpStr) tempString = tmpStr; - configBufferList[i].defaultValue = tempString; + const char *tmpStr1 = conf->Attribute("value"); + if (tmpStr1) tempString1 = tmpStr1; + configBufferList[i].defaultValue = tempString1; + + const char *tmpStr2 = conf->Attribute("type"); + if (tmpStr2) { + tempString2 = tmpStr2; + if(tempString2 == "list") { + + list tempStringList2; + + TiXmlElement* confList = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement(); + + for( confList; confList; confList=confList->NextSiblingElement()) { + tempStringList2.push_back(confList->Attribute("value")); + } + + configBufferList[i].defaultListValue = tempStringList2; + } + } + + } else { cout << "Could not find the element to fill the config-buffer with!"; } @@ -328,6 +350,20 @@ void ConfigFile::writeBuffer() const { TiXmlElement *tmpElement = new TiXmlElement(configBufferList[i].name); config->LinkEndChild( tmpElement ); tmpElement->SetAttribute("value", configBufferList[i].defaultValue); + + if(configBufferList[i].type == CONFIG_TYPE_INT_LIST) { + + tmpElement->SetAttribute("type", "list"); + list tempList = configBufferList[i].defaultListValue; + list::iterator it; + for(it = tempList.begin(); it != tempList.end(); it++) { + + TiXmlElement *tmpSubElement = new TiXmlElement(configBufferList[i].defaultValue); + tmpElement->LinkEndChild( tmpSubElement ); + tmpSubElement->SetAttribute("value", *it); + } + + } } doc.SaveFile( configFileName ); @@ -359,6 +395,20 @@ void ConfigFile::updateConfig(ConfigState myConfigState) { TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); config->LinkEndChild( tmpElement ); tmpElement->SetAttribute("value", myQtToolsInterface->stringToUtf8(configList[i].defaultValue)); + + if(configList[i].type == CONFIG_TYPE_INT_LIST) { + + tmpElement->SetAttribute("type", "list"); + list tempList = configList[i].defaultListValue; + list::iterator it; + for(it = tempList.begin(); it != tempList.end(); it++) { + + TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue); + tmpElement->LinkEndChild( tmpSubElement ); + tmpSubElement->SetAttribute("value", *it); + } + + } } doc.SaveFile( configFileName ); @@ -372,8 +422,9 @@ void ConfigFile::updateConfig(ConfigState myConfigState) { //load the old one if(oldDoc.LoadFile()) { - string tempString(""); - + string tempString1(""); + string tempString2(""); + TiXmlDocument newDoc; //Create the new one @@ -396,14 +447,14 @@ void ConfigFile::updateConfig(ConfigState myConfigState) { config->LinkEndChild( confElement1 ); confElement1->SetAttribute("value", myQtToolsInterface->getDataPathStdString(startPath.remove_leaf().directory_string())); - TiXmlHandle docHandle( &oldDoc ); + TiXmlHandle oldDocHandle( &oldDoc ); for (i=0; iLinkEndChild( tmpElement ); - const char *tmpStr = conf->Attribute("value"); - if (tmpStr) tempString = tmpStr; - tmpElement->SetAttribute("value", tempString); + const char *tmpStr1 = oldConf->Attribute("value"); + if (tmpStr1) tempString1 = tmpStr1; + tmpElement->SetAttribute("value", tempString1); + + //for lists copy elements + const char *tmpStr2 = oldConf->Attribute("type"); + if (tmpStr2) { + tempString2 = tmpStr2; + if(tempString2 == "list") { + + list tempStringList2; + + TiXmlElement* oldConfList = oldDocHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).FirstChild().ToElement(); + + for( oldConfList; oldConfList; oldConfList=oldConfList->NextSiblingElement()) { + tempStringList2.push_back(oldConfList->Attribute("value")); + } + + tmpElement->SetAttribute("type", "list"); + list tempList = tempStringList2; + list::iterator it; + for(it = tempList.begin(); it != tempList.end(); it++) { + + TiXmlElement *tmpSubElement = new TiXmlElement(tempString1); + tmpElement->LinkEndChild( tmpSubElement ); + tmpSubElement->SetAttribute("value", *it); + } + } + } } - } + } else { // if element is not there --> set it with defaultValue TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); config->LinkEndChild( tmpElement ); tmpElement->SetAttribute("value", myQtToolsInterface->stringToUtf8(configList[i].defaultValue)); + + if(configList[i].type == CONFIG_TYPE_INT_LIST) { + + tmpElement->SetAttribute("type", "list"); + list tempList = configList[i].defaultListValue; + list::iterator it; + for(it = tempList.begin(); it != tempList.end(); it++) { + + TiXmlElement *tmpSubElement = new TiXmlElement(configList[i].defaultValue); + tmpElement->LinkEndChild( tmpSubElement ); + tmpSubElement->SetAttribute("value", *it); + } + } } - } - + } newDoc.SaveFile( configFileName ); } else { cout << "cannot update config file. did not found it" << endl; } @@ -471,6 +560,37 @@ int ConfigFile::readConfigInt(string varName) const return tempInt; } +list ConfigFile::readConfigIntList(string varName) const +{ + boost::mutex::scoped_lock lock(m_configMutex); + + size_t i; + list tempStringList; + list tempIntList; + + for (i=0; i::iterator it; + for(it = tempStringList.begin(); it != tempStringList.end(); it++) { + + isst.str(*it); + isst >> tempInt; + tempIntList.push_back(tempInt); + isst.str(""); + isst.clear(); + } + + return tempIntList; +} + void ConfigFile::writeConfigInt(string varName, int varCont) { @@ -489,6 +609,34 @@ void ConfigFile::writeConfigInt(string varName, int varCont) } } + +void ConfigFile::writeConfigIntList(string varName, list varCont) +{ + boost::mutex::scoped_lock lock(m_configMutex); + + size_t i; + ostringstream intToString; + list stringList; + + for (i=0; i::iterator it; + for(it = varCont.begin(); it != varCont.end(); it++) { + + intToString << (*it); + stringList.push_back(intToString.str()); + intToString.str(""); + intToString.clear(); + } + + configBufferList[i].defaultListValue = stringList; + } + } +} + + void ConfigFile::writeConfigString(string varName, string varCont) { boost::mutex::scoped_lock lock(m_configMutex); diff --git a/src/config/configfile.h b/src/config/configfile.h index 0098e545..fbf6ebf2 100644 --- a/src/config/configfile.h +++ b/src/config/configfile.h @@ -27,7 +27,7 @@ #include enum ConfigState { NONEXISTING, OLD }; -enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING }; +enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING, CONFIG_TYPE_INT_LIST }; class QtToolsInterface; @@ -46,8 +46,9 @@ public: void writeConfigString(std::string varName, std::string varCont); int readConfigInt(std::string varName) const; + std::list readConfigIntList(std::string varName) const; void writeConfigInt(std::string varName, int varCont); - + void writeConfigIntList(std::string varName, std::list varCont); private: @@ -55,10 +56,12 @@ private: struct ConfigInfo { - ConfigInfo(const std::string &n, ConfigType t, const std::string &d) : name(n), type(t), defaultValue(d) {} + ConfigInfo(const std::string &n, ConfigType t, const std::string &d, const std::list &l =std::list()) : name(n), type(t), defaultValue(d), defaultListValue(l) {} std::string name; ConfigType type; std::string defaultValue; + std::list defaultListValue; + }; std::vector configList; diff --git a/src/pokerth.cpp b/src/pokerth.cpp index 34b267c5..4a1c94d6 100755 --- a/src/pokerth.cpp +++ b/src/pokerth.cpp @@ -75,7 +75,7 @@ int main( int argc, char **argv ) //ENABLE_LEAK_CHECK(); //_CrtSetBreakAlloc(49937); - + socket_startup(); /////// can be removed for non-qt-guis ////////////