From 12536a918e4d2b45e9f8944b4881d893759bc92c Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 31 Dec 2012 19:27:14 -0800 Subject: [PATCH] Use plString in plConfigInfo and friends --- .../PubUtilLib/plContainer/plConfigInfo.cpp | 283 ++++++++---------- .../PubUtilLib/plContainer/plConfigInfo.h | 197 ++++++------ .../plContainer/plConfigInfoLogging.cpp | 82 +++-- .../plContainer/plKeysAndValues.cpp | 132 ++++---- .../PubUtilLib/plContainer/plKeysAndValues.h | 40 +-- .../plNetClient/plNetClientMgrSend.cpp | 2 +- 6 files changed, 343 insertions(+), 393 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp index 849a7a0d..09949990 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp @@ -48,9 +48,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -const std::string& plConfigInfo::GlobalSection() +const plString& plConfigInfo::GlobalSection() { - static std::string section("global"); + static plString section("global"); return section; } @@ -74,32 +74,32 @@ void plConfigInfo::Clear() fSections.clear(); } -void plConfigInfo::RemoveSection(const std::string & section) +void plConfigInfo::RemoveSection(const plString & section) { - fSections.erase(section.c_str()); + fSections.erase(section); } -void plConfigInfo::RemoveKey(const std::string & section, const std::string & key) +void plConfigInfo::RemoveKey(const plString & section, const plString & key) { - Sections::iterator si = fSections.find(section.c_str()); + Sections::iterator si = fSections.find(section); if (si != fSections.end()) - fSections[section.c_str()].RemoveKey(key); + fSections[section].RemoveKey(key); } -bool plConfigInfo::HasSection(const std::string & section) const +bool plConfigInfo::HasSection(const plString & section) const { - return fSections.find(section.c_str())!=fSections.end(); + return fSections.find(section)!=fSections.end(); } -bool plConfigInfo::HasKey(const std::string & section, const std::string & key) +bool plConfigInfo::HasKey(const plString & section, const plString & key) { - Sections::iterator si = fSections.find(section.c_str()); + Sections::iterator si = fSections.find(section); if (si == fSections.end()) return false; return (si->second.HasKey(key)); } -bool plConfigInfo::HasKeyAny(const std::string & key) +bool plConfigInfo::HasKeyAny(const plString & key) { for (Sections::iterator si=fSections.begin(); si!=fSections.end(); ++si) { @@ -109,12 +109,12 @@ bool plConfigInfo::HasKeyAny(const std::string & key) return false; } -bool plConfigInfo::HasKeyIn(const std::string & key, const char * section1, ...) +bool plConfigInfo::HasKeyIn(const plString & key, const char * section1, ...) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -124,114 +124,105 @@ bool plConfigInfo::HasKeyIn(const std::string & key, const char * section1, ...) return HasKeyIn( key, sections ); } -bool plConfigInfo::HasKeyIn(const std::string & key, const std::vector & sections ) +bool plConfigInfo::HasKeyIn(const plString & key, const std::vector & sections ) { for ( int i=0; isecond.KeyHasValue(key,value); } -bool plConfigInfo::KeyHasValue(const std::string & section, const std::string & key, int value) +bool plConfigInfo::KeyHasValue(const plString & section, const plString & key, int value) { - Sections::iterator si = fSections.find(section.c_str()); + Sections::iterator si = fSections.find(section); if (si == fSections.end()) return false; return si->second.KeyHasValue(key,value); } -bool plConfigInfo::KeyHasValue(const std::string & section, const std::string & key, double value) +bool plConfigInfo::KeyHasValue(const plString & section, const plString & key, double value) { - Sections::iterator si = fSections.find(section.c_str()); + Sections::iterator si = fSections.find(section); if (si == fSections.end()) return false; return si->second.KeyHasValue(key,value); } -bool plConfigInfo::AddValue(const std::string & section, const std::string & key, const std::string & value, KAddValueMode mode) +bool plConfigInfo::AddValue(const plString & section, const plString & key, const plString & value, KAddValueMode mode) { - fSections[section.c_str()].AddValue(key,value,mode); - return true; + return fSections[section].AddValue(key,value,mode); } -bool plConfigInfo::AddValue(const std::string & section, const std::string & key, int value, KAddValueMode mode) +bool plConfigInfo::AddValue(const plString & section, const plString & key, int value, KAddValueMode mode) { - char buf[20]; - sprintf(buf, "%d", value); - std::string v(buf); - return AddValue(section,key,v,mode); + return fSections[section].AddValue(key,value,mode); } -bool plConfigInfo::AddValue(const std::string & section, const std::string & key, double value, KAddValueMode mode) +bool plConfigInfo::AddValue(const plString & section, const plString & key, double value, KAddValueMode mode) { - char buf[30]; - sprintf(buf, "%f", value); - std::string v(buf); - return AddValue(section,key,v,mode); + return fSections[section].AddValue(key,value,mode); } -bool plConfigInfo::AddValues(const std::string & section, const std::string & key, const std::vector & values, KAddValueMode mode) +bool plConfigInfo::AddValues(const plString & section, const plString & key, const std::vector & values, KAddValueMode mode) { - return fSections[section.c_str()].AddValues(key,values); + return fSections[section].AddValues(key,values); } -plKeysAndValues plConfigInfo::GetSection(const std::string & section, bool & found) +plKeysAndValues plConfigInfo::GetSection(const plString & section, bool & found) { found = HasSection(section); if (found) - return fSections[section.c_str()]; + return fSections[section]; else return plKeysAndValues(); // empty } -std::vector plConfigInfo::GetSectionNames() +std::vector plConfigInfo::GetSectionNames() { - std::vector results; + std::vector results; for (Sections::const_iterator ii=fSections.begin(); ii!=fSections.end(); ++ii) - results.push_back(ii->first.c_str()); + results.push_back(ii->first); return results; } -std::string plConfigInfo::GetValue(const std::string & section, const std::string & key, const std::string & defval, bool * outFound) const +plString plConfigInfo::GetValue(const plString & section, const plString & key, const plString & defval, bool * outFound) const { - return fSections[section.c_str()].GetValue(key,defval,outFound); + return fSections[section].GetValue(key,defval,outFound); } -int plConfigInfo::GetValue(const std::string & section, const std::string & key, int defval, bool * outFound) const +int plConfigInfo::GetValue(const plString & section, const plString & key, int defval, bool * outFound) const { - return fSections[section.c_str()].GetValue(key,defval,outFound); + return fSections[section].GetValue(key,defval,outFound); } -double plConfigInfo::GetValue(const std::string & section, const std::string & key, double defval, bool * outFound) const +double plConfigInfo::GetValue(const plString & section, const plString & key, double defval, bool * outFound) const { - return fSections[section.c_str()].GetValue(key,defval,outFound); + return fSections[section].GetValue(key,defval,outFound); } -std::vector plConfigInfo::GetAllValues(const std::string & section, const std::string & key) const +std::vector plConfigInfo::GetAllValues(const plString & section, const plString & key) const { - Sections::iterator si = fSections.find(section.c_str()); + Sections::iterator si = fSections.find(section); if (si != fSections.end()) return si->second.GetAllValues(key); - std::vector empty; - return empty; + return std::vector(); } -std::string plConfigInfo::GetValueAny(const std::string & key, const std::string & defval, bool * outFound) const +plString plConfigInfo::GetValueAny(const plString & key, const plString & defval, bool * outFound) const { if (outFound) *outFound=false; for (Sections::iterator si=fSections.begin(); si!=fSections.end(); ++si) @@ -240,7 +231,7 @@ std::string plConfigInfo::GetValueAny(const std::string & key, const std::string return defval; } -int plConfigInfo::GetValueAny(const std::string & key, int defval, bool * outFound) const +int plConfigInfo::GetValueAny(const plString & key, int defval, bool * outFound) const { if (outFound) *outFound=false; for (Sections::iterator si=fSections.begin(); si!=fSections.end(); ++si) @@ -249,7 +240,7 @@ int plConfigInfo::GetValueAny(const std::string & key, int defval, bool * outFou return defval; } -double plConfigInfo::GetValueAny(const std::string & key, double defval, bool * outFound) const +double plConfigInfo::GetValueAny(const plString & key, double defval, bool * outFound) const { if (outFound) *outFound=false; for (Sections::iterator si=fSections.begin(); si!=fSections.end(); ++si) @@ -258,17 +249,16 @@ double plConfigInfo::GetValueAny(const std::string & key, double defval, bool * return defval; } -std::vector plConfigInfo::GetAllValuesAny(const std::string & key) const +std::vector plConfigInfo::GetAllValuesAny(const plString & key) const { for (Sections::iterator si=fSections.begin(); si!=fSections.end(); ++si) if (si->second.HasKey(key)) return si->second.GetAllValues(key); - std::vector empty; - return empty; + return std::vector(); } -std::string plConfigInfo::GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const char * section1, ...) const +plString plConfigInfo::GetValueIn(const plString & key, const plString & defval, bool * outFound, const char * section1, ...) const { if (outFound) *outFound=false; const char * section = section1; @@ -288,14 +278,14 @@ std::string plConfigInfo::GetValueIn(const std::string & key, const std::string return defval; } -std::string plConfigInfo::GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const std::vector & sections ) const +plString plConfigInfo::GetValueIn(const plString & key, const plString & defval, bool * outFound, const std::vector & sections ) const { if (outFound) *outFound=false; for ( int i=0; i & sections ) const +int plConfigInfo::GetValueIn(const plString & key, int defval, bool * outFound, const std::vector & sections ) const { if (outFound) *outFound=false; for ( int i=0; i & sections ) const +double plConfigInfo::GetValueIn(const plString & key, double defval, bool * outFound, const std::vector & sections ) const { if (outFound) *outFound=false; for ( int i=0; i plConfigInfo::GetAllValuesIn(const std::string & key, const char * section1, ...) +std::vector plConfigInfo::GetAllValuesIn(const plString & key, const char * section1, ...) { const char * section = section1; va_list sections; va_start(sections,section1); - std::vector result; + std::vector result; while (section) { if (HasSection(section)) @@ -386,7 +376,7 @@ std::vector plConfigInfo::GetAllValuesIn(const std::string & key, c plKeysAndValues & kv = fSections[section]; if (kv.HasKey(key)) { - std::vector values = kv.GetAllValues(key); + std::vector values = kv.GetAllValues(key); result.insert(result.end(),values.begin(),values.end()); } } @@ -403,7 +393,7 @@ bool plConfigInfo::GetSectionIterators(Sections::const_iterator & iter, Sections return true; } -bool plConfigInfo::GetKeyIterators(const xtl::istring & section, Keys::const_iterator & iter, Keys::const_iterator & end) const +bool plConfigInfo::GetKeyIterators(const plString & section, Keys::const_iterator & iter, Keys::const_iterator & end) const { Sections::const_iterator si = fSections.find(section); if (si==fSections.end()) @@ -411,7 +401,7 @@ bool plConfigInfo::GetKeyIterators(const xtl::istring & section, Keys::const_ite return fSections[section].GetKeyIterators(iter, end); } -bool plConfigInfo::GetValueIterators(const xtl::istring & section, const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const +bool plConfigInfo::GetValueIterators(const plString & section, const plString & key, Values::const_iterator & iter, Values::const_iterator & end) const { Sections::const_iterator si = fSections.find(section); if (si==fSections.end()) @@ -432,63 +422,62 @@ bool plConfigInfo::WriteTo(plConfigSource * src) //////////////////////////////////////////////// -void plConfigSource::SplitAt(std::string & key, std::string & value, char splitter, std::string & in) +void plConfigSource::SplitAt(plString & key, plString & value, char splitter, plString & in) { - if(in.length() == 0) + if (in.IsEmpty()) return; - int t = in.find(splitter); - if(t == std::string::npos) + int t = in.Find(splitter); + if (t < 0) { key = in; return; } - key.assign(in.substr(0,t)); - value.assign(in.substr(t+1,in.size()-t-1)); + key = in.Left(t); + value = in.Substr(t+1,in.GetSize()-t-1); } -bool plConfigSource::ReadString(const std::string & in) +bool plConfigSource::ReadString(const plString & in) { - std::string work = in; - xtl::trim(work); + plString work = in.Trim(); // comment - if (work[0] == '#') + if (work.CharAt(0) == '#') return true; // comment - if (work[0] == ';') + if (work.CharAt(0) == ';') return true; // section - if (work[0] == '[') + if (work.CharAt(0) == '[') { - int close = work.find_first_of("]"); - if(close == std::string::npos) + int close = work.Find("]"); + if (close < 0) return false; - fCurrSection = work.substr(1,close-1); + fCurrSection = work.Substr(1, close-1); fEffectiveSection = fCurrSection; return true; } // key=value - std::string key, value; + plString key, value; SplitAt(key, value, '=', work); // dot notation makes section change for this key=value only. - int t = key.find('.'); - if (t>0 && t0 && tAddValue(fEffectiveSection, key, value, fAddMode); @@ -542,7 +530,7 @@ bool plConfigSource::WriteOutOf(plConfigInfo & configInfo) plCmdLineConfigSource::plCmdLineConfigSource(int argc, char ** argv, const char * mySection) : fArgc(argc) , fArgv(argv) -, fMySection(mySection?mySection:"") +, fMySection(mySection) {} @@ -560,7 +548,7 @@ bool plCmdLineConfigSource::ReadInto(plConfigInfo & configInfo, KAddValueMode mo if(argc < 1) return true; - fConfigInfo->AddValue(fEffectiveSection.c_str(), "ARGV0", *argv, fAddMode); + fConfigInfo->AddValue(fEffectiveSection, "ARGV0", *argv, fAddMode); argc--; argv++; @@ -582,7 +570,7 @@ bool plCmdLineConfigSource::ReadInto(plConfigInfo & configInfo, KAddValueMode mo plEnvConfigSource::plEnvConfigSource(char ** envp, const char * mySection) : fEnvp(envp) -, fMySection(mySection?mySection:"") +, fMySection(mySection) {} @@ -617,7 +605,7 @@ bool plIniConfigSource::ReadInto(plConfigInfo & configInfo, KAddValueMode mode) fCurrSection = plConfigInfo::GlobalSection(); fEffectiveSection = fCurrSection; - if(fFileName.size() < 2) + if(fFileName.GetSize() < 2) return false; @@ -760,33 +748,34 @@ bool plIniStreamConfigSource::WriteOutOf(plConfigInfo & configInfo) ///////////////////////////////////////////////// -plIniSectionConfigSource::plIniSectionConfigSource(const char * iniFileName, std::vector & sections) +plIniSectionConfigSource::plIniSectionConfigSource(const char * iniFileName, std::vector & sections) : plIniConfigSource(iniFileName) { for (int i=0; i::iterator ii = std::find(fSections.begin(), fSections.end(), fCurrSection.c_str()); + Sections::iterator ii = std::find_if(fSections.begin(), fSections.end(), + [this](const plString &v) { return v.CompareI(fCurrSection) == 0; } + ); if (ii==fSections.end()) return true; - xtl::trim(key); - xtl::trim(value); - xtl::trim(value,"\"'"); + key = key.Trim(); + value = value.Trim().Trim("\"'"); - if (key.size() == 0) + if (key.IsEmpty()) return true; - if (key == "section") - fSections.push_back(value.c_str()); + if (key.CompareI("section") == 0) + fSections.push_back(value); return fConfigInfo->AddValue(fEffectiveSection, key, value, fAddMode); } @@ -794,10 +783,7 @@ bool plIniSectionConfigSource::ReadPair(std::string & key, std::string & value) bool plIniSectionConfigSource::ReadSubSource( const char * name ) { - std::vector sections; - for ( int i=0; iReadFrom(&src); } @@ -809,21 +795,20 @@ plIniNoSectionsConfigSource::plIniNoSectionsConfigSource(const char * filename) fEffectiveSection = fCurrSection = ""; } -bool plIniNoSectionsConfigSource::ReadString(const std::string & in) +bool plIniNoSectionsConfigSource::ReadString(const plString & in) { - std::string work = in; - xtl::trim(work); + plString work = in.Trim(); // ignore comments - if (work[0]=='#' || work[0]==';') + if (work.CharAt(0)=='#' || work.CharAt(0)==';') return true; // ignore sections - if (work[0] == '[') + if (work.CharAt(0) == '[') return true; // parse key value - std::string key, value; + plString key, value; SplitAt(key, value, '=', work); return ReadPair(key, value); @@ -834,7 +819,7 @@ bool plIniNoSectionsConfigSource::ReadInto(plConfigInfo & configInfo, KAddValueM if (!plConfigSource::ReadInto(configInfo, mode)) return false; - if(fFileName.size() < 2) + if (fFileName.GetSize() < 2) return false; std::ifstream file; @@ -944,11 +929,11 @@ void plConfigValueBase::ConfigRead(plConfigInfo * opts) { if (fReadEvaluate()) { - std::string value; + plString value; bool found; value = opts->GetValue(GetConfigGroup(),GetConfigName(),"",&found); if (found) - SetValue(fReadModify(value).c_str()); + SetValue(fReadModify(value)); } } @@ -960,12 +945,12 @@ void plConfigValueBase::ConfigWrite(plConfigInfo * opts) } } -void plConfigValueBase::SetValue(const char * value) +void plConfigValueBase::SetValue(const plString & value) { - ISetValue(fSetModify(value).c_str()); + ISetValue(fSetModify(value)); } -std::string plConfigValueBase::GetValue() const +plString plConfigValueBase::GetValue() const { return fGetModify(IGetValue()); } @@ -1030,7 +1015,7 @@ bool plConfigGroup::Write(plConfigSource * src) void plConfigGroup::AddItem(plConfigValueBase * item, const char * name) { - item->SetConfigGroup(fGroupName.c_str()); + item->SetConfigGroup(fGroupName); if (name) item->SetConfigName(name); fItems.push_back(item); @@ -1071,29 +1056,28 @@ void plConfigAggregateValue::AddItems( if (item7) AddItem(item7); } -void plConfigAggregateValue::ISetValue(const char * value) +void plConfigAggregateValue::ISetValue(const plString & value) { - std::string work = value; + plString work = value.Trim(); int p=0,i=0; do { - xtl::trim(work); - p = work.find(" "); - fItems[i]->SetValue(work.substr(0,p).c_str()); - work.erase(0,p); + p = work.Find(" "); + fItems[i]->SetValue(work.Left(p)); + work = work.Substr(p).TrimLeft(); i++; - } while (i=0); } -std::string plConfigAggregateValue::IGetValue() const +plString plConfigAggregateValue::IGetValue() const { - std::string value; + plStringStream value; for (int i=0; iGetValue()); - value.append(" "); + value << fItems[i]->GetValue(); + value << ' '; } - return xtl::trim(value); + return value.GetString().Trim(); } void plConfigAggregateValue::AddItem(plConfigValueBase * item) @@ -1103,7 +1087,7 @@ void plConfigAggregateValue::AddItem(plConfigValueBase * item) //////////////////////////////////////////////////////////////////// -plWWWAuthenticateConfigSource::plWWWAuthenticateConfigSource(const std::string& auth) +plWWWAuthenticateConfigSource::plWWWAuthenticateConfigSource(const plString& auth) : fAuth(auth) { fEffectiveSection = fCurrSection = ""; @@ -1119,21 +1103,20 @@ bool plWWWAuthenticateConfigSource::ReadInto(plConfigInfo & configInfo, KAddValu unsigned int i = 0; - while (i < fAuth.size()) + while (i < fAuth.GetSize()) { bool inQuote = false; unsigned int begin = i,end; - while (i < fAuth.size() - && ((fAuth[i] != ',' && !inQuote) || inQuote)) + while (i < fAuth.GetSize() + && ((fAuth.CharAt(i) != ',' && !inQuote) || inQuote)) { - if (fAuth[i] == '"') + if (fAuth.CharAt(i) == '"') inQuote = ! inQuote; i++; } end = i; - std::string buf; - buf.assign(fAuth,begin,end-begin); + plString buf = fAuth.Substr(begin, end-begin); if(!ReadString(buf.c_str())) { // TODO log warning here diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h index 2c13339d..0df3c0ce 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h @@ -48,8 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ///////////////////////////////////////////////// -typedef std::vector plStringList; -typedef std::vector plWStringList; +typedef std::vector plStringList; ///////////////////////////////////////////////// @@ -61,10 +60,10 @@ public: Keys; typedef plKeysAndValues::Values Values; - typedef std::map + typedef std::map Sections; - static const std::string& GlobalSection(); + static const plString& GlobalSection(); private: mutable Sections fSections; @@ -79,54 +78,54 @@ public: // remove all sections void Clear(); // remove section - void RemoveSection(const std::string & section); + void RemoveSection(const plString & section); // remove key from section - void RemoveKey(const std::string & section, const std::string & key); + void RemoveKey(const plString & section, const plString & key); // QUERY // does this section exist? - bool HasSection(const std::string & section) const; + bool HasSection(const plString & section) const; // does the given section contain this key? - bool HasKey(const std::string & section, const std::string & key); + bool HasKey(const plString & section, const plString & key); // does any section contain this key? - bool HasKeyAny(const std::string & key); + bool HasKeyAny(const plString & key); // does any of the given sections contain this key? - bool HasKeyIn(const std::string & key, const char * section1, ... /*, nil*/); - bool HasKeyIn(const std::string & key, const std::vector & sections ); + bool HasKeyIn(const plString & key, const char * section1, ... /*, nil*/); + bool HasKeyIn(const plString & key, const std::vector & sections ); // does key in section have this value? - bool KeyHasValue(const std::string & section, const std::string & key, const std::string & value); - bool KeyHasValue(const std::string & section, const std::string & key, int value); - bool KeyHasValue(const std::string & section, const std::string & key, double value); + bool KeyHasValue(const plString & section, const plString & key, const plString & value); + bool KeyHasValue(const plString & section, const plString & key, int value); + bool KeyHasValue(const plString & section, const plString & key, double value); // ADD // add key=value to the section - bool AddValue(const std::string & section, const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd); - bool AddValue(const std::string & section, const std::string & key, int value, KAddValueMode mode=kAlwaysAdd); - bool AddValue(const std::string & section, const std::string & key, double value, KAddValueMode mode=kAlwaysAdd); - bool AddValues(const std::string & section, const std::string & key, const std::vector & values, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & section, const plString & key, const plString & value, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & section, const plString & key, int value, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & section, const plString & key, double value, KAddValueMode mode=kAlwaysAdd); + bool AddValues(const plString & section, const plString & key, const std::vector & values, KAddValueMode mode=kAlwaysAdd); // GET - plKeysAndValues GetSection(const std::string & section, bool & found); - std::vector GetSectionNames(); + plKeysAndValues GetSection(const plString & section, bool & found); + std::vector GetSectionNames(); // get value for key from given section - std::string GetValue(const std::string & section, const std::string & key, const std::string & defval="", bool * outFound=nil) const; - int GetValue(const std::string & section, const std::string & key, int defval, bool * outFound=nil) const; - double GetValue(const std::string & section, const std::string & key, double defval, bool * outFound=nil) const; - std::vector GetAllValues(const std::string & section, const std::string & key) const; + plString GetValue(const plString & section, const plString & key, const plString & defval="", bool * outFound=nil) const; + int GetValue(const plString & section, const plString & key, int defval, bool * outFound=nil) const; + double GetValue(const plString & section, const plString & key, double defval, bool * outFound=nil) const; + std::vector GetAllValues(const plString & section, const plString & key) const; // get value for key from any section - std::string GetValueAny(const std::string & key, const std::string & defval="", bool * outFound=nil) const; - int GetValueAny(const std::string & key, int defval, bool * outFound=nil) const; - double GetValueAny(const std::string & key, double defval, bool * outFound=nil) const; - std::vector GetAllValuesAny(const std::string & key) const; + plString GetValueAny(const plString & key, const plString & defval="", bool * outFound=nil) const; + int GetValueAny(const plString & key, int defval, bool * outFound=nil) const; + double GetValueAny(const plString & key, double defval, bool * outFound=nil) const; + std::vector GetAllValuesAny(const plString & key) const; // get value for key from one of the given sections - std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const char * section1, ... /*, nil*/) const; - std::string GetValueIn(const std::string & key, const std::string & defval, bool * outFound, const std::vector & sections ) const; - int GetValueIn(const std::string & key, int defval, bool * outFound, const char * section1, ... /*, nil*/) const; - int GetValueIn(const std::string & key, int defval, bool * outFound, const std::vector & sections ) const; - double GetValueIn(const std::string & key, double defval, bool * outFound, const char * section1, ... /*, nil*/) const; - double GetValueIn(const std::string & key, double defval, bool * outFound, const std::vector & sections ) const; - std::vector GetAllValuesIn(const std::string & key, const char * section1, ... /*, nil*/); + plString GetValueIn(const plString & key, const plString & defval, bool * outFound, const char * section1, ... /*, nil*/) const; + plString GetValueIn(const plString & key, const plString & defval, bool * outFound, const std::vector & sections ) const; + int GetValueIn(const plString & key, int defval, bool * outFound, const char * section1, ... /*, nil*/) const; + int GetValueIn(const plString & key, int defval, bool * outFound, const std::vector & sections ) const; + double GetValueIn(const plString & key, double defval, bool * outFound, const char * section1, ... /*, nil*/) const; + double GetValueIn(const plString & key, double defval, bool * outFound, const std::vector & sections ) const; + std::vector GetAllValuesIn(const plString & key, const char * section1, ... /*, nil*/); // ITERATORS bool GetSectionIterators(Sections::const_iterator & iter, Sections::const_iterator & end) const; - bool GetKeyIterators(const xtl::istring & section, Keys::const_iterator & iter, Keys::const_iterator & end) const; - bool GetValueIterators(const xtl::istring & section, const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const; + bool GetKeyIterators(const plString & section, Keys::const_iterator & iter, Keys::const_iterator & end) const; + bool GetValueIterators(const plString & section, const plString & key, Values::const_iterator & iter, Values::const_iterator & end) const; // CONFIG SOURCE virtual bool ReadFrom(plConfigSource * src, KAddValueMode mode=kAlwaysAdd); virtual bool WriteTo(plConfigSource * src); @@ -145,33 +144,33 @@ public: plConfigInfo* GetConfigInfo() { return &fConfigInfo; } plConfigInfo* GetConfigInfoLog() { return &fLog; } - bool GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval = ""); - bool GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval); - bool GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval); - bool GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval); - bool GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval); - bool GetAllValues(std::vector& values, const std::string & section, const std::string & key, const std::string & desc); + bool GetValue(plString& retval, const plString & section, const plString & key, const plString & desc, const plString& defval = ""); + bool GetValue(int& retval, const plString & section, const plString & key, const plString & desc, int defval); + bool GetValue(bool& retval, const plString & section, const plString & key, const plString & desc, bool defval); + bool GetValue(float& retval, const plString & section, const plString & key, const plString & desc, float defval); + bool GetValue(double& retval, const plString & section, const plString & key, const plString & desc, double defval); + bool GetAllValues(std::vector& values, const plString & section, const plString & key, const plString & desc); #if USE_MULT_SECTIONS // get value for key from any section - bool GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval); - bool GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval); - bool GetValueAny(bool& retval, const std::string & key, const std::string & desc, bool defval); - bool GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval); - bool GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval); - bool GetAllValuesAny(std::vector& values, const std::string & key, const std::string & desc); + bool GetValueAny(plString& retval, const plString & key, const plString & desc, const plString & defval); + bool GetValueAny(int &retval, const plString & key, const plString & desc, int defval); + bool GetValueAny(bool& retval, const plString & key, const plString & desc, bool defval); + bool GetValueAny(float& retval, const plString & key, const plString & desc, float defval); + bool GetValueAny(double& retval, const plString & key, const plString & desc, double defval); + bool GetAllValuesAny(std::vector& values, const plString & key, const plString & desc); // get value for key from one of the given sections - bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/); - bool GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector & sections ); - bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/); - bool GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector & sections ); - bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/); - bool GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector & sections ); - bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/); - bool GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector & sections ); - bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/); - bool GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector & sections ); + bool GetValueIn(plString& retval, const plString & key, const plString & desc, const plString & defval, const char * section1, ... /*, nil*/); + bool GetValueIn(plString& retval, const plString & key, const plString & desc, const plString & defval, std::vector & sections ); + bool GetValueIn(int& retval, const plString & key, const plString & desc, int defval, const char * section1, ... /*, nil*/); + bool GetValueIn(int& retval, const plString & key, const plString & desc, int defval, std::vector & sections ); + bool GetValueIn(bool& retval, const plString & key, const plString & desc, bool defval, const char * section1, ... /*, nil*/); + bool GetValueIn(bool& retval, const plString & key, const plString & desc, bool defval, std::vector & sections ); + bool GetValueIn(float& retval, const plString & key, const plString & desc, double defval, const char * section1, ... /*, nil*/); + bool GetValueIn(float& retval, const plString & key, const plString & desc, double defval, std::vector & sections ); + bool GetValueIn(double& retval, const plString & key, const plString & desc, double defval, const char * section1, ... /*, nil*/); + bool GetValueIn(double& retval, const plString & key, const plString & desc, double defval, std::vector & sections ); #endif }; @@ -180,14 +179,14 @@ public: class plConfigSource { protected: - std::string fCurrSection; // used in parsing - std::string fEffectiveSection; // used in parsing + plString fCurrSection; // used in parsing + plString fEffectiveSection; // used in parsing KAddValueMode fAddMode; // used in parsing plConfigInfo * fConfigInfo; - void SplitAt(std::string & key, std::string & value, char splitter, std::string & in); - virtual bool ReadString(const std::string & in); - virtual bool ReadPair(std::string & key, std::string & value); + void SplitAt(plString & key, plString & value, char splitter, plString & in); + virtual bool ReadString(const plString & in); + virtual bool ReadPair(plString & key, plString & value); virtual bool ReadList(char ** list); virtual bool ReadSubSource( const char * name ) { return true; } @@ -209,7 +208,7 @@ class plCmdLineConfigSource : public plConfigSource { int fArgc; char ** fArgv; - std::string fMySection; + plString fMySection; protected: bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd); public: @@ -222,7 +221,7 @@ public: class plEnvConfigSource : public plConfigSource { char ** fEnvp; - std::string fMySection; + plString fMySection; protected: bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd); public: @@ -235,7 +234,7 @@ public: class plIniConfigSource : public plConfigSource { protected: - std::string fFileName; + plString fFileName; bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd); bool WriteOutOf(plConfigInfo & configInfo); public: @@ -262,9 +261,9 @@ public: // data in an unnamed section, or more accurately, in a section named "". class plIniNoSectionsConfigSource : public plConfigSource { - std::string fFileName; + plString fFileName; protected: - bool ReadString(const std::string & in); + bool ReadString(const plString & in); bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd); bool WriteOutOf(plConfigInfo & configInfo); public: @@ -276,14 +275,14 @@ public: // an ini file reader that only reads specified sections class plIniSectionConfigSource : public plIniConfigSource { - typedef std::vector + typedef std::vector Sections; protected: Sections fSections; - bool ReadPair(std::string & key, std::string & value); + bool ReadPair(plString & key, plString & value); bool ReadSubSource( const char * name ); public: - plIniSectionConfigSource(const char * iniFileName, std::vector & sections); + plIniSectionConfigSource(const char * iniFileName, std::vector & sections); }; ///////////////////////////////////////////////// @@ -304,7 +303,7 @@ public: class plDebugConfigSource : public plConfigSource { protected: - std::string fFileName; + plString fFileName; bool WriteOutOf(plConfigInfo & configInfo); public: plDebugConfigSource(){} @@ -314,11 +313,11 @@ public: class plWWWAuthenticateConfigSource : public plConfigSource { - const std::string& fAuth; + const plString& fAuth; protected: bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd); public: - plWWWAuthenticateConfigSource(const std::string& auth); + plWWWAuthenticateConfigSource(const plString& auth); }; //////////////////////////////////////////////////////////////////// @@ -363,18 +362,18 @@ struct plEvaluate //////////////////////////////////////////////////////////////////// -typedef std::string (plClass::*TModify)(const std::string & value); +typedef plString (plClass::*TModify)(const plString & value); struct plModify { plClass * fTarget; - std::string (plClass::*fModify)(const std::string & value); + plString (plClass::*fModify)(const plString & value); plModify( plClass * target=nil, TModify modify=nil ) : fTarget(target) , fModify(modify) {} - std::string operator()(const std::string & value) { return (fTarget)?(fTarget->*fModify)(value):value;} - std::string operator()(const std::string & value) const { return (fTarget)?(fTarget->*fModify)(value):value;} + plString operator()(const plString & value) { return (fTarget)?(fTarget->*fModify)(value):value;} + plString operator()(const plString & value) const { return (fTarget)?(fTarget->*fModify)(value):value;} }; //////////////////////////////////////////////////////////////////// @@ -382,8 +381,8 @@ struct plModify class plConfigValueBase { public: - std::string fConfigName; - std::string fConfigGroup; + plString fConfigName; + plString fConfigGroup; plEvaluate fReadEvaluate; // returns true if we want to read this value from options plEvaluate fWriteEvaluate; // returns true if we want to write this value to options plModify fReadModify; // may modify the value being read from options @@ -394,18 +393,18 @@ public: : fConfigName(configName) , fConfigGroup(configGroup) {} - void SetConfigName(const char * name) { fConfigName=(name)?name:"";} - std::string GetConfigName() const { return fConfigName;} - void SetConfigGroup(const char * group) { fConfigGroup=group;} - std::string GetConfigGroup() const { return fConfigGroup;} - bool HasConfigName() { return fConfigName.length()>0;} - bool HasConfigGroup() { return fConfigGroup.length()>0;} + void SetConfigName(const plString & name) { fConfigName=name;} + plString GetConfigName() const { return fConfigName;} + void SetConfigGroup(const plString & group) { fConfigGroup=group;} + plString GetConfigGroup() const { return fConfigGroup;} + bool HasConfigName() { return !fConfigName.IsEmpty();} + bool HasConfigGroup() { return !fConfigGroup.IsEmpty();} virtual void ConfigRead(plConfigInfo * opts); virtual void ConfigWrite(plConfigInfo * opts); - void SetValue(const char * value); - std::string GetValue() const; - virtual void ISetValue(const char * value) = 0; - virtual std::string IGetValue() const = 0; + void SetValue(const plString & value); + plString GetValue() const; + virtual void ISetValue(const plString & value) = 0; + virtual plString IGetValue() const = 0; void SetReadEvaluate(plClass * targetObj, TEvaluate evalFunc); void SetWriteEvaluate(plClass * targetObj, TEvaluate evalFunc); @@ -424,9 +423,9 @@ public: plConfigValue( const char * configName="", const char * configGroup="" ) : plConfigValueBase(configName, configGroup) {} - std::string fConfigValue; - void ISetValue(const char * value) { fConfigValue=value;} - std::string IGetValue() const { return fConfigValue;} + plString fConfigValue; + void ISetValue(const plString & value) { fConfigValue=value;} + plString IGetValue() const { return fConfigValue;} }; //////////////////////////////////////////////////////////////////// @@ -451,8 +450,8 @@ public: plConfigValueBase * item5=nil, plConfigValueBase * item6=nil, plConfigValueBase * item7=nil); - void ISetValue(const char * value); - std::string IGetValue() const; + void ISetValue(const plString & value); + plString IGetValue() const; void AddItem(plConfigValueBase * item); void AddItems( plConfigValueBase * item1=nil, @@ -474,8 +473,8 @@ public: : fConfigurable(item) {} void Set(plConfigValueBase * item) { fConfigurable=item;} - void ISetValue(const char * value) { fConfigurable->ISetValue(value);} - std::string IGetValue() const { return fConfigurable->IGetValue();} + void ISetValue(const plString & value) { fConfigurable->ISetValue(value);} + plString IGetValue() const { return fConfigurable->IGetValue();} }; //////////////////////////////////////////////////////////////////// @@ -484,7 +483,7 @@ class plConfigGroup { public: plConfigInfo fOpts; - std::string fGroupName; + plString fGroupName; std::vector fItems; plConfigGroup(const char * groupName=""); bool Read(plConfigSource * src); diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp index 282a06c6..6ec622d4 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp @@ -49,10 +49,9 @@ plConfigInfoLogging::~plConfigInfoLogging() { } -bool plConfigInfoLogging::GetValue(std::string& retval, const std::string & section, const std::string & key, const std::string & desc, const std::string& defval) +bool plConfigInfoLogging::GetValue(plString& retval, const plString & section, const plString & key, const plString & desc, const plString& defval) { - std::string descwdef; - xtl::format(descwdef,"%s # %s",defval.c_str(),desc.c_str()); + plString descwdef = plString::Format("%s # %s",defval.c_str(),desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); bool found; @@ -60,10 +59,9 @@ bool plConfigInfoLogging::GetValue(std::string& retval, const std::string & sect return found; } -bool plConfigInfoLogging::GetValue(int& retval, const std::string & section, const std::string & key, const std::string & desc, int defval) +bool plConfigInfoLogging::GetValue(int& retval, const plString & section, const plString & key, const plString & desc, int defval) { - std::string descwdef; - xtl::format(descwdef,"%d # %s",defval,desc.c_str()); + plString descwdef = plString::Format("%d # %s",defval,desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); bool found; @@ -71,10 +69,9 @@ bool plConfigInfoLogging::GetValue(int& retval, const std::string & section, con return found; } -bool plConfigInfoLogging::GetValue(bool& retval, const std::string & section, const std::string & key, const std::string & desc, bool defval) +bool plConfigInfoLogging::GetValue(bool& retval, const plString & section, const plString & key, const plString & desc, bool defval) { - std::string descwdef; - xtl::format(descwdef,"%d # %s",defval,desc.c_str()); + plString descwdef = plString::Format("%d # %s",defval,desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); bool found; @@ -82,10 +79,9 @@ bool plConfigInfoLogging::GetValue(bool& retval, const std::string & section, co return found; } -bool plConfigInfoLogging::GetValue(float& retval, const std::string & section, const std::string & key, const std::string & desc, float defval) +bool plConfigInfoLogging::GetValue(float& retval, const plString & section, const plString & key, const plString & desc, float defval) { - std::string descwdef; - xtl::format(descwdef,"%f # %s",defval,desc.c_str()); + plString descwdef = plString::Format("%f # %s",defval,desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); bool found; @@ -94,10 +90,9 @@ bool plConfigInfoLogging::GetValue(float& retval, const std::string & section, c return found; } -bool plConfigInfoLogging::GetValue(double& retval, const std::string & section, const std::string & key, const std::string & desc, double defval) +bool plConfigInfoLogging::GetValue(double& retval, const plString & section, const plString & key, const plString & desc, double defval) { - std::string descwdef; - xtl::format(descwdef,"%f # %s",defval,desc.c_str()); + plString descwdef = plString::Format("%f # %s",defval,desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); bool found; @@ -105,10 +100,9 @@ bool plConfigInfoLogging::GetValue(double& retval, const std::string & section, return found; } -bool plConfigInfoLogging::GetAllValues(std::vector& values, const std::string & section, const std::string & key, const std::string & desc) +bool plConfigInfoLogging::GetAllValues(std::vector& values, const plString & section, const plString & key, const plString & desc) { - std::string descwdef; - xtl::format(descwdef,"%s # %s","\"Multiple Entries\"",desc.c_str()); + plString descwdef = plString::Format("%s # %s","\"Multiple Entries\"",desc.c_str()); fLog.AddValue(section,key,descwdef,kReplaceIfExists); values = fConfigInfo.GetAllValues(section,key); @@ -117,7 +111,7 @@ bool plConfigInfoLogging::GetAllValues(std::vector& values, const s #if USE_MULT_SECTIONS -bool plConfigInfoLogging::GetValueAny(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval) +bool plConfigInfoLogging::GetValueAny(plString& retval, const plString & key, const plString & desc, const plString & defval) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -126,7 +120,7 @@ bool plConfigInfoLogging::GetValueAny(std::string& retval, const std::string & k return found; } -bool plConfigInfoLogging::GetValueAny(int &retval, const std::string & key, const std::string & desc, int defval) +bool plConfigInfoLogging::GetValueAny(int &retval, const plString & key, const plString & desc, int defval) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -135,7 +129,7 @@ bool plConfigInfoLogging::GetValueAny(int &retval, const std::string & key, cons return found; } -bool plConfigInfoLogging::GetValueAny(bool &retval, const std::string & key, const std::string & desc, bool defval) +bool plConfigInfoLogging::GetValueAny(bool &retval, const plString & key, const plString & desc, bool defval) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -144,7 +138,7 @@ bool plConfigInfoLogging::GetValueAny(bool &retval, const std::string & key, con return found; } -bool plConfigInfoLogging::GetValueAny(float& retval, const std::string & key, const std::string & desc, float defval) +bool plConfigInfoLogging::GetValueAny(float& retval, const plString & key, const plString & desc, float defval) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -153,7 +147,7 @@ bool plConfigInfoLogging::GetValueAny(float& retval, const std::string & key, co return found; } -bool plConfigInfoLogging::GetValueAny(double& retval, const std::string & key, const std::string & desc, double defval) +bool plConfigInfoLogging::GetValueAny(double& retval, const plString & key, const plString & desc, double defval) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -162,7 +156,7 @@ bool plConfigInfoLogging::GetValueAny(double& retval, const std::string & key, c return found; } -bool plConfigInfoLogging::GetAllValuesAny(std::vector& values, const std::string & key, const std::string & desc) +bool plConfigInfoLogging::GetAllValuesAny(std::vector& values, const plString & key, const plString & desc) { fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists); @@ -170,12 +164,12 @@ bool plConfigInfoLogging::GetAllValuesAny(std::vector& values, cons return values.size() != 0; } -bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, const char * section1, ... /*, nil*/) +bool plConfigInfoLogging::GetValueIn(plString& retval, const plString & key, const plString & desc, const plString & defval, const char * section1, ... /*, nil*/) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -186,9 +180,9 @@ bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & ke return GetValueIn(retval,key,desc,defval,sections); } -bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & key, const std::string & desc, const std::string & defval, std::vector & sections ) +bool plConfigInfoLogging::GetValueIn(plString& retval, const plString & key, const plString & desc, const plString & defval, std::vector & sections ) { - std::vector::iterator si = sections.begin(); + std::vector::iterator si = sections.begin(); while (si != sections.end()) { fLog.AddValue(*si,key,desc,kReplaceIfExists); @@ -200,12 +194,12 @@ bool plConfigInfoLogging::GetValueIn(std::string& retval, const std::string & ke return found; } -bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, const char * section1, ... /*, nil*/) +bool plConfigInfoLogging::GetValueIn(int& retval, const plString & key, const plString & desc, int defval, const char * section1, ... /*, nil*/) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -216,9 +210,9 @@ bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, cons return GetValueIn(retval,key,desc,defval,sections); } -bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, const std::string & desc, int defval, std::vector & sections ) +bool plConfigInfoLogging::GetValueIn(int& retval, const plString & key, const plString & desc, int defval, std::vector & sections ) { - std::vector::iterator si = sections.begin(); + std::vector::iterator si = sections.begin(); while (si != sections.end()) { fLog.AddValue(*si,key,desc,kReplaceIfExists); @@ -230,12 +224,12 @@ bool plConfigInfoLogging::GetValueIn(int& retval, const std::string & key, cons return found; } -bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, const char * section1, ... /*, nil*/) +bool plConfigInfoLogging::GetValueIn(bool& retval, const plString & key, const plString & desc, bool defval, const char * section1, ... /*, nil*/) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -246,9 +240,9 @@ bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, con return GetValueIn(retval,key,desc,defval,sections); } -bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, const std::string & desc, bool defval, std::vector & sections ) +bool plConfigInfoLogging::GetValueIn(bool& retval, const plString & key, const plString & desc, bool defval, std::vector & sections ) { - std::vector::iterator si = sections.begin(); + std::vector::iterator si = sections.begin(); while (si != sections.end()) { fLog.AddValue(*si,key,desc,kReplaceIfExists); @@ -260,12 +254,12 @@ bool plConfigInfoLogging::GetValueIn(bool& retval, const std::string & key, con return found; } -bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/) +bool plConfigInfoLogging::GetValueIn(float& retval, const plString & key, const plString & desc, double defval, const char * section1, ... /*, nil*/) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -276,9 +270,9 @@ bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, co return GetValueIn(retval,key,desc,defval,sections); } -bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, const std::string & desc, double defval, std::vector & sections ) +bool plConfigInfoLogging::GetValueIn(float& retval, const plString & key, const plString & desc, double defval, std::vector & sections ) { - std::vector::iterator si = sections.begin(); + std::vector::iterator si = sections.begin(); while (si != sections.end()) { fLog.AddValue(*si,key,desc,kReplaceIfExists); @@ -290,12 +284,12 @@ bool plConfigInfoLogging::GetValueIn(float& retval, const std::string & key, co return found; } -bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, const char * section1, ... /*, nil*/) +bool plConfigInfoLogging::GetValueIn(double& retval, const plString & key, const plString & desc, double defval, const char * section1, ... /*, nil*/) { const char * section = section1; va_list va; va_start(va,section1); - std::vector sections; + std::vector sections; while (section) { sections.push_back( section ); @@ -306,9 +300,9 @@ bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, c return GetValueIn(retval,key,desc,defval,sections); } -bool plConfigInfoLogging::GetValueIn(double& retval, const std::string & key, const std::string & desc, double defval, std::vector & sections ) +bool plConfigInfoLogging::GetValueIn(double& retval, const plString & key, const plString & desc, double defval, std::vector & sections ) { - std::vector::iterator si = sections.begin(); + std::vector::iterator si = sections.begin(); while (si != sections.end()) { fLog.AddValue(*si,key,desc,kReplaceIfExists); diff --git a/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.cpp b/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.cpp index 4335acca..913141e5 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.cpp @@ -65,41 +65,37 @@ void plKeysAndValues::Clear() fKeys.clear(); } -void plKeysAndValues::RemoveKey(const std::string & key) +void plKeysAndValues::RemoveKey(const plString & key) { - fKeys.erase(key.c_str()); + fKeys.erase(key); } -bool plKeysAndValues::HasKey(const std::string & key) const +bool plKeysAndValues::HasKey(const plString & key) const { - return (fKeys.find(key.c_str()) != fKeys.end()); + return (fKeys.find(key) != fKeys.end()); } -bool plKeysAndValues::KeyHasValue(const std::string & key, const std::string & value) +bool plKeysAndValues::KeyHasValue(const plString & key, const plString & value) { - Keys::const_iterator ki = fKeys.find(key.c_str()); + Keys::const_iterator ki = fKeys.find(key); if (ki==fKeys.end()) return false; - return std::find(ki->second.begin(),ki->second.end(), value.c_str()) != ki->second.end(); + return std::find_if(ki->second.begin(), ki->second.end(), + [&value](const plString &v) { return v.CompareI(value) == 0; } + ) != ki->second.end(); } -bool plKeysAndValues::KeyHasValue(const std::string & key, int value) +bool plKeysAndValues::KeyHasValue(const plString & key, int value) { - char buf[20]; - sprintf(buf, "%d", value); - std::string v(buf); - return KeyHasValue(key, v); + return KeyHasValue(key, plString::Format("%d", value)); } -bool plKeysAndValues::KeyHasValue(const std::string & key, double value) +bool plKeysAndValues::KeyHasValue(const plString & key, double value) { - char buf[30]; - sprintf(buf, "%f", value); - std::string v(buf); - return KeyHasValue(key, v); + return KeyHasValue(key, plString::Format("%f", value)); } -bool plKeysAndValues::AddValue(const std::string & key, const std::string & value, KAddValueMode mode) +bool plKeysAndValues::AddValue(const plString & key, const plString & value, KAddValueMode mode) { switch (mode) { @@ -114,97 +110,75 @@ bool plKeysAndValues::AddValue(const std::string & key, const std::string & valu default: break; } - fKeys[key.c_str()].push_front(value.c_str()); + fKeys[key].push_front(value); return true; } -bool plKeysAndValues::AddValue(const std::string & key, int value, KAddValueMode mode) +bool plKeysAndValues::AddValue(const plString & key, int value, KAddValueMode mode) { - char buf[20]; - sprintf(buf, "%d", value); - std::string v(buf); - return AddValue(key,v,mode); + return AddValue(key, plString::Format("%d", value), mode); } -bool plKeysAndValues::AddValue(const std::string & key, double value, KAddValueMode mode) +bool plKeysAndValues::AddValue(const plString & key, double value, KAddValueMode mode) { - char buf[30]; - sprintf(buf, "%f", value); - std::string v(buf); - return AddValue(key,v,mode); + return AddValue(key, plString::Format("%f", value), mode); } -bool plKeysAndValues::AddValues(const std::string & key, const std::vector & values, KAddValueMode mode) +bool plKeysAndValues::AddValues(const plString & key, const std::vector & values, KAddValueMode mode) { for (int i=0; isecond.front().c_str(); -// fKeys[key.c_str()].push_front(defval.c_str()); + return ki->second.front(); +// fKeys[key].push_front(defval); return defval; } -uint32_t plKeysAndValues::GetValue(const std::string & key, uint32_t defval, bool * outFound) const +uint32_t plKeysAndValues::GetValue(const plString & key, uint32_t defval, bool * outFound) const { - char buf[20]; - sprintf(buf, "%ul", defval); - std::string v(buf); - return strtoul(GetValue(key,v,outFound).c_str(), nil, 0); + return strtoul(GetValue(key, plString::Format("%ul", defval), outFound).c_str(), nil, 0); } -int plKeysAndValues::GetValue(const std::string & key, int defval, bool * outFound) const +int plKeysAndValues::GetValue(const plString & key, int defval, bool * outFound) const { - char buf[20]; - sprintf(buf, "%d", defval); - std::string v(buf); - return atol(GetValue(key,v,outFound).c_str()); + return atol(GetValue(key, plString::Format("%d", defval), outFound).c_str()); } -double plKeysAndValues::GetValue(const std::string & key, double defval, bool * outFound) const +double plKeysAndValues::GetValue(const plString & key, double defval, bool * outFound) const { - char buf[30]; - sprintf(buf, "%f", defval); - std::string v(buf); - return atof(GetValue(key,v,outFound).c_str()); + return atof(GetValue(key, plString::Format("%f", defval), outFound).c_str()); } -std::vector plKeysAndValues::GetAllValues(const std::string & key) +std::vector plKeysAndValues::GetAllValues(const plString & key) { - std::vector result; - xtl::istring xkey = key.c_str(); + std::vector result; if (HasKey(key)) - for (Values::const_iterator vi=fKeys[xkey].begin(); vi!=fKeys[xkey].end(); ++vi) - result.push_back(vi->c_str()); + for (Values::const_iterator vi=fKeys[key].begin(); vi!=fKeys[key].end(); ++vi) + result.push_back(*vi); return result; } @@ -215,7 +189,7 @@ bool plKeysAndValues::GetKeyIterators(Keys::const_iterator & iter, Keys::const_i return true; } -bool plKeysAndValues::GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const +bool plKeysAndValues::GetValueIterators(const plString & key, Values::const_iterator & iter, Values::const_iterator & end) const { Keys::const_iterator ki = fKeys.find(key); if(ki != fKeys.end()) @@ -235,19 +209,19 @@ void plKeysAndValues::Read(hsStream * s) { uint16_t strlen; s->ReadLE(&strlen); - std::string key; - key.assign(strlen+1,'\0'); - s->Read(strlen,(void*)key.data()); - key.resize(strlen); + plStringBuffer key; + char* kdata = key.CreateWritableBuffer(strlen); + s->Read(strlen,(void*)kdata); + kdata[strlen] = 0; uint16_t nvalues; s->ReadLE(&nvalues); for (int vi=0; viReadLE(&strlen); - std::string value; - value.assign(strlen+1,'\0'); - s->Read(strlen,(void*)value.data()); - value.resize(strlen); + plStringBuffer value; + char* vdata = value.CreateWritableBuffer(strlen); + s->Read(strlen,(void*)vdata); + vdata[strlen] = 0; // for now, only single value for key on stream is allowed. SetValue(key,value); } @@ -264,8 +238,8 @@ void plKeysAndValues::Write(hsStream * s) for (;ki!=ke;++ki) { // write key string - s->WriteLE((uint16_t)ki->first.size()); - s->Write(ki->first.size(),ki->first.c_str()); + s->WriteLE((uint16_t)ki->first.GetSize()); + s->Write(ki->first.GetSize(),ki->first.c_str()); // write nvalues for this key s->WriteLE((uint16_t)ki->second.size()); // iterate through values for this key @@ -274,8 +248,8 @@ void plKeysAndValues::Write(hsStream * s) for (;vi!=ve;++vi) { // write value string - s->WriteLE((uint16_t)vi->size()); - s->Write(vi->size(),vi->c_str()); + s->WriteLE((uint16_t)vi->GetSize()); + s->Write(vi->GetSize(),vi->c_str()); } } } diff --git a/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h b/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h index c35546f2..3d0082f5 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h +++ b/Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h @@ -62,9 +62,9 @@ enum KAddValueMode class plKeysAndValues : public hsStreamable { public: - typedef std::list + typedef std::list Values; - typedef std::map + typedef std::map Keys; private: @@ -79,31 +79,31 @@ public: plKeysAndValues & operator =(const plKeysAndValues & src); // clear void Clear(); - void RemoveKey(const std::string & key); + void RemoveKey(const plString & key); // query - bool HasKey(const std::string & key) const; - bool KeyHasValue(const std::string & key, const std::string & value); - bool KeyHasValue(const std::string & key, int value); - bool KeyHasValue(const std::string & key, double value); + bool HasKey(const plString & key) const; + bool KeyHasValue(const plString & key, const plString & value); + bool KeyHasValue(const plString & key, int value); + bool KeyHasValue(const plString & key, double value); // add - bool AddValue(const std::string & key, const std::string & value, KAddValueMode mode=kAlwaysAdd); - bool AddValue(const std::string & key, int value, KAddValueMode mode=kAlwaysAdd); - bool AddValue(const std::string & key, double value, KAddValueMode mode=kAlwaysAdd); - bool AddValues(const std::string & key, const std::vector & values, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & key, const plString & value, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & key, int value, KAddValueMode mode=kAlwaysAdd); + bool AddValue(const plString & key, double value, KAddValueMode mode=kAlwaysAdd); + bool AddValues(const plString & key, const std::vector & values, KAddValueMode mode=kAlwaysAdd); // set (clear and add) - bool SetValue(const std::string & key, const std::string & value); - bool SetValue(const std::string & key, int value); - bool SetValue(const std::string & key, double value); + bool SetValue(const plString & key, const plString & value); + bool SetValue(const plString & key, int value); + bool SetValue(const plString & key, double value); // get single value - std::string GetValue(const std::string & key, const std::string & defval="", bool * outFound=nil) const; - uint32_t GetValue(const std::string & key, uint32_t defval, bool * outFound=nil) const; - int GetValue(const std::string & key, int defval, bool * outFound=nil) const; - double GetValue(const std::string & key, double defval, bool * outFound=nil) const; - std::vector GetAllValues(const std::string & key); + plString GetValue(const plString & key, const plString & defval="", bool * outFound=nil) const; + uint32_t GetValue(const plString & key, uint32_t defval, bool * outFound=nil) const; + int GetValue(const plString & key, int defval, bool * outFound=nil) const; + double GetValue(const plString & key, double defval, bool * outFound=nil) const; + std::vector GetAllValues(const plString & key); // key iterator bool GetKeyIterators(Keys::const_iterator & iter, Keys::const_iterator & end) const; // value iterator (use for getting all values for key) - bool GetValueIterators(const xtl::istring & key, Values::const_iterator & iter, Values::const_iterator & end) const; + bool GetValueIterators(const plString & key, Values::const_iterator & iter, Values::const_iterator & end) const; // streamable void Read(hsStream * s); void Write(hsStream * s); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp index 30813010..8b593964 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp @@ -159,7 +159,7 @@ void plNetClientMgr::ISendCCRPetition(plCCRPetitionMsg* petMsg) char buffy[20]; sprintf( buffy, "%lu", GetPlayerID() ); info.AddValue( "Petition", "PlayerID", buffy ); - info.AddValue( "Petition", "PlayerName", GetPlayerName().c_str() ); + info.AddValue( "Petition", "PlayerName", GetPlayerName() ); // write config info formatted like an ini file to a buffer hsRAMStream ram;