Browse Source

Merge pull request #247 from zrax/string-cleaning

Deprecate hsStlUtils and provide some misc. string-related cleanup
Adam Johnson 12 years ago
parent
commit
2c055f91f5
  1. 3
      Sources/Plasma/Apps/plClient/plClient.h
  2. 3
      Sources/Plasma/CoreLib/CMakeLists.txt
  3. 22
      Sources/Plasma/CoreLib/HeadSpin.cpp
  4. 1
      Sources/Plasma/CoreLib/hsSTLStream.h
  5. 65
      Sources/Plasma/CoreLib/hsStlSortUtils.h
  6. 447
      Sources/Plasma/CoreLib/hsStlUtils.cpp
  7. 210
      Sources/Plasma/CoreLib/hsStlUtils.h
  8. 7
      Sources/Plasma/CoreLib/hsStream.cpp
  9. 3
      Sources/Plasma/CoreLib/hsStream.h
  10. 1
      Sources/Plasma/CoreLib/plGeneric.h
  11. 115
      Sources/Plasma/CoreLib/plString.cpp
  12. 128
      Sources/Plasma/CoreLib/plString.h
  13. 1
      Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp
  14. 1
      Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp
  15. 1
      Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp
  16. 2
      Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp
  17. 3
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  18. 1
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp
  19. 3
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h
  20. 14
      Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp
  21. 1
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h
  22. 1
      Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp
  23. 1
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp
  24. 4
      Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h
  25. 2
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h
  26. 1
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h
  27. 1
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp
  28. 3
      Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h
  29. 1
      Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h
  30. 1
      Sources/Plasma/FeatureLib/pfPython/Games/Heek/pyHeekMsg.h
  31. 1
      Sources/Plasma/FeatureLib/pfPython/Games/Marker/pyMarkerMsg.h
  32. 1
      Sources/Plasma/FeatureLib/pfPython/Games/VarSync/pyVarSyncMsg.h
  33. 3
      Sources/Plasma/FeatureLib/pfPython/Pch.h
  34. 1
      Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h
  35. 2
      Sources/Plasma/FeatureLib/pfPython/cyAvatar.h
  36. 1
      Sources/Plasma/FeatureLib/pfPython/cyMisc.h
  37. 2
      Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.h
  38. 5
      Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp
  39. 2
      Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h
  40. 1
      Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp
  41. 1
      Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h
  42. 1
      Sources/Plasma/FeatureLib/pfPython/pyCCRMgr.h
  43. 1
      Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp
  44. 1
      Sources/Plasma/FeatureLib/pfPython/pyJournalBook.h
  45. 3
      Sources/Plasma/FeatureLib/pfPython/pySDL.h
  46. 1
      Sources/Plasma/NucleusLib/inc/plPipeline.h
  47. 3
      Sources/Plasma/NucleusLib/inc/plProfileManager.h
  48. 2
      Sources/Plasma/NucleusLib/pnDispatch/plDispatch.cpp
  49. 2
      Sources/Plasma/NucleusLib/pnDispatch/plDispatch.h
  50. 2
      Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.h
  51. 1
      Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h
  52. 39
      Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp
  53. 13
      Sources/Plasma/NucleusLib/pnMessage/plMessage.h
  54. 34
      Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp
  55. 3
      Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h
  56. 1
      Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h
  57. 1
      Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.cpp
  58. 3
      Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.h
  59. 2
      Sources/Plasma/NucleusLib/pnNetCommon/plNetGroup.h
  60. 3
      Sources/Plasma/NucleusLib/pnNetCommon/plNetSharedState.h
  61. 1
      Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h
  62. 1
      Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp
  63. 1
      Sources/Plasma/NucleusLib/pnProduct/Private/pnPrProductId.cpp
  64. 1
      Sources/Plasma/NucleusLib/pnUUID/pnUUID.h
  65. 3
      Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp
  66. 1
      Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.h
  67. 34
      Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp
  68. 3
      Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.h
  69. 2
      Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.h
  70. 2
      Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h
  71. 3
      Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h
  72. 5
      Sources/Plasma/PubUtilLib/plAvatar/plAGAnimInstance.h
  73. 4
      Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h
  74. 4
      Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.h
  75. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp
  76. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.h
  77. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp
  78. 1
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h
  79. 1
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.h
  80. 1
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp
  81. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp
  82. 1
      Sources/Plasma/PubUtilLib/plAvatar/plAvLadderModifier.cpp
  83. 2
      Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp
  84. 5
      Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.h
  85. 1
      Sources/Plasma/PubUtilLib/plAvatar/plAvatarSDLModifier.h
  86. 4
      Sources/Plasma/PubUtilLib/plAvatar/plCritterCommands.h
  87. 4
      Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp
  88. 1
      Sources/Plasma/PubUtilLib/plAvatar/plMultistageBehMod.h
  89. 2
      Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp
  90. 2
      Sources/Plasma/PubUtilLib/plAvatar/plSwimRegion.cpp
  91. 2
      Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h
  92. 284
      Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp
  93. 198
      Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h
  94. 82
      Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp
  95. 1
      Sources/Plasma/PubUtilLib/plContainer/plContainer.h
  96. 132
      Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.cpp
  97. 43
      Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h
  98. 2
      Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.h
  99. 2
      Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp
  100. 1
      Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp
  101. Some files were not shown because too many files have changed in this diff Show More

3
Sources/Plasma/Apps/plClient/plClient.h

@ -48,10 +48,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//#define NEW_CAMERA_CODE
#include "HeadSpin.h"
#include <list>
#include "hsBitVector.h"
#include "hsTemplates.h"
#include "hsStlUtils.h"
#include "pnKeyedObject/hsKeyedObject.h"
#include "pnKeyedObject/plUoid.h"
#include "plScene/plRenderRequest.h"

3
Sources/Plasma/CoreLib/CMakeLists.txt

@ -27,7 +27,6 @@ set(CoreLib_SOURCES
hsRefCnt.cpp
hsSafeRefCnt.cpp
hsSTLStream.cpp
hsStlUtils.cpp
hsStream.cpp
hsStringTokenizer.cpp
hsTemplates.cpp
@ -69,9 +68,7 @@ set(CoreLib_HEADERS
hsQuat.h
hsRefCnt.h
hsSafeRefCnt.h
hsStlSortUtils.h
hsSTLStream.h
hsStlUtils.h
hsStream.h
hsStringTokenizer.h
hsTemplates.h

22
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -41,13 +41,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "hsWindows.h"
#include <wchar.h>
#ifdef _MSC_VER
# include <crtdbg.h>
#endif
#include "hsStlUtils.h"
#include "hsTemplates.h"
#include "plString.h"
///////////////////////////////////////////////////////////////////////////
@ -214,6 +215,7 @@ void hsStatusMessageF(const char * fmt, ...)
#endif
// TODO: Deprecate these in favor of plString
char * hsFormatStr(const char * fmt, ...)
{
va_list args;
@ -225,8 +227,7 @@ char * hsFormatStr(const char * fmt, ...)
char * hsFormatStrV(const char * fmt, va_list args)
{
std::string buf;
xtl::formatv(buf,fmt,args);
plString buf = plString::IFormat(fmt, args);
return hsStrcpy(buf.c_str());
}
@ -460,6 +461,8 @@ char *hsWStringToString( const wchar_t *str )
//
char** DisplaySystemVersion()
{
// TODO: I so want to std::vector<plString> this, but that requires
// including more headers in HeadSpin.h :(
#if HS_BUILD_FOR_WIN32
#ifndef VER_SUITE_PERSONAL
#define VER_SUITE_PERSONAL 0x200
@ -499,6 +502,15 @@ char** DisplaySystemVersion()
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
versionStrs.Append(hsStrcpy ("Microsoft Windows XP "));
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
versionStrs.Append(hsStrcpy ("Microsoft Windows Vista "));
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
versionStrs.Append(hsStrcpy ("Microsoft Windows 7 "));
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 )
versionStrs.Append(hsStrcpy ("Microsoft Windows 8 "));
// Test for product type.
if( bOsVersionInfoEx )
@ -545,7 +557,7 @@ char** DisplaySystemVersion()
if ( osvi.dwMajorVersion <= 4 )
{
versionStrs.Append(hsStrcpy (xtl::format("version %d.%d %s (Build %d)\n",
versionStrs.Append(hsStrcpy (plString::Format("version %d.%d %s (Build %d)\n",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
osvi.szCSDVersion,
@ -553,7 +565,7 @@ char** DisplaySystemVersion()
}
else
{
versionStrs.Append(hsStrcpy (xtl::format("%s (Build %d)\n",
versionStrs.Append(hsStrcpy (plString::Format("%s (Build %d)\n",
osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF).c_str()));
}

1
Sources/Plasma/CoreLib/hsSTLStream.h

@ -44,7 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _hsSTLStream_h_inc_
#include "hsStream.h"
#include "hsStlUtils.h"
//
// In-memory only

65
Sources/Plasma/CoreLib/hsStlSortUtils.h

@ -1,65 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsStlSortUtils_inc
#define hsStlSortUtils_inc
// These get used a lot in char * STL maps, so lets just have them in one place
class stringSorter
{
public:
bool operator() (const char *s1, const char *s2) const
{
return (strcmp(s1,s2) < 0);
}
};
class stringISorter
{
public:
bool operator() (const char *s1, const char *s2) const
{
return (stricmp(s1,s2) < 0);
}
};
#endif // hsStlSortUtils_inc

447
Sources/Plasma/CoreLib/hsStlUtils.cpp

@ -1,447 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "hsStlUtils.h"
// stl extensions
namespace xtl {
//std::string
std::string & trimleft(std::string & s, const char * charset)
{
s.erase(0, s.find_first_not_of(charset));
return s;
}
std::wstring & trimleft(std::wstring & s, const wchar_t * charset)
{
s.erase(0, s.find_first_not_of(charset));
return s;
}
std::string & trimright(std::string & s, const char * charset)
{
int idx = s.find_last_not_of(charset);
if (std::string::npos == idx)
{
s.erase();
}
else
{
char c = s.at(idx);
s.erase(idx, std::string::npos);
s.append(1, c);
}
return s;
}
std::wstring & trimright(std::wstring & s, const wchar_t * charset)
{
int idx = s.find_last_not_of(charset);
if (std::wstring::npos == idx)
{
s.erase();
}
else
{
wchar_t c = s.at(idx);
s.erase(idx, std::string::npos);
s.append(1, c);
}
return s;
}
std::string & trim(std::string & s, const char * charset)
{
trimleft(s,charset);
trimright(s,charset);
return s;
}
std::wstring & trim(std::wstring & s, const wchar_t * charset)
{
trimleft(s,charset);
trimright(s,charset);
return s;
}
//xtl::istring
xtl::istring & trimleft(xtl::istring & s, const char * charset)
{
s.erase(0, s.find_first_not_of(charset));
return s;
}
xtl::iwstring & trimleft(xtl::iwstring & s, const wchar_t * charset)
{
s.erase(0, s.find_first_not_of(charset));
return s;
}
xtl::istring & trimright(xtl::istring & s, const char * charset)
{
int idx = s.find_last_not_of(charset);
if (xtl::istring::npos == idx)
{
s.erase();
}
else
{
char c = s.at(idx);
s.erase(idx, xtl::istring::npos);
s.append(1, c);
}
return s;
}
xtl::iwstring & trimright(xtl::iwstring & s, const wchar_t * charset)
{
int idx = s.find_last_not_of(charset);
if (xtl::iwstring::npos == idx)
{
s.erase();
}
else
{
wchar_t c = s.at(idx);
s.erase(idx, xtl::iwstring::npos);
s.append(1, c);
}
return s;
}
xtl::istring & trim(xtl::istring & s, const char * charset)
{
trimleft(s,charset);
trimright(s,charset);
return s;
}
xtl::iwstring & trim(xtl::iwstring & s, const wchar_t * charset)
{
trimleft(s,charset);
trimright(s,charset);
return s;
}
// c-string
std::string trim(const char * s, const char * charset)
{
std::string result = s;
trimleft(result,charset);
trimright(result,charset);
return result;
}
std::wstring trim(const wchar_t * s, const wchar_t * charset)
{
std::wstring result = s;
trimleft(result,charset);
trimright(result,charset);
return result;
}
// format
std::string format(const char * fmt, ...)
{
std::string result;
va_list args;
va_start(args,fmt);
formatv(result,fmt,args);
va_end(args);
return result;
}
std::wstring format(const wchar_t * fmt, ...)
{
std::wstring result;
va_list args;
va_start(args,fmt);
formatv(result,fmt,args);
va_end(args);
return result;
}
std::string formatv(const char * fmt, va_list args)
{
std::string result;
formatv( result, fmt, args );
return result;
}
std::wstring formatv(const wchar_t * fmt, va_list args)
{
std::wstring result;
formatv( result, fmt, args );
return result;
}
bool format(std::string & out, const char * fmt, ...)
{
va_list args;
va_start(args,fmt);
bool r = formatv(out,fmt,args);
va_end(args);
return r;
}
bool format(std::wstring & out, const wchar_t * fmt, ...)
{
va_list args;
va_start(args,fmt);
bool r = formatv(out,fmt,args);
va_end(args);
return r;
}
bool formatv(std::string & out, const char * fmt, va_list args)
{
#define kBufSz 2048
char buf[kBufSz];
char * pbuf = buf;
int len = 0;
int attempts = 0;
bool success = false;
const int kMaxAttempts = 40;
do
{
int maxlen = kBufSz*attempts+kBufSz-1;
len = hsVsnprintf(pbuf,maxlen,fmt,args);
attempts++;
success = (len>=0 && len<maxlen);
if (!success)
{
if (pbuf!=buf)
delete [] pbuf;
pbuf = new char[kBufSz+kBufSz*attempts];
}
}
while (!success && attempts<kMaxAttempts);
if (success)
{
pbuf[len] = '\0';
out = pbuf;
}
if (success)
{
pbuf[len] = '\0';
out = pbuf;
}
else
{
out = "";
if ( attempts==kMaxAttempts )
{
hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting string. Result is likely truncated!", 0 );
}
}
if (pbuf!=buf)
delete [] pbuf;
return success;
}
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args)
{
#define kBufSz 2048
wchar_t buf[kBufSz];
wchar_t * pbuf = buf;
int len = 0;
int attempts = 0;
bool success = false;
const int kMaxAttempts = 40;
do
{
int maxlen = kBufSz*attempts+kBufSz-1;
len = hsVsnwprintf(pbuf,maxlen,fmt,args);
attempts++;
success = (len>=0 && len<maxlen);
if (!success)
{
if (pbuf!=buf)
delete [] pbuf;
pbuf = new wchar_t[kBufSz+kBufSz*attempts];
}
}
while (!success && attempts<kMaxAttempts);
if (success)
{
pbuf[len] = L'\0';
out = pbuf;
}
if (success)
{
pbuf[len] = L'\0';
out = pbuf;
}
else
{
out = L"";
if ( attempts==kMaxAttempts )
{
hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting wstring. Result is likely truncated!", 0 );
}
}
if (pbuf!=buf)
delete [] pbuf;
return success;
}
typedef std::vector<std::string> StringVector;
typedef std::vector<std::wstring> WStringVector;
typedef std::list<std::string> StringList;
typedef std::list<std::wstring> WStringList;
typedef std::set<std::string> StringSet;
typedef std::set<std::wstring> WStringSet;
template bool GetStringGroup<StringList>(const std::string& s, StringList& group, char sep);
template bool GetStringGroup<WStringList>(const std::wstring& s, WStringList& group, wchar_t sep);
template bool GetStringGroup<StringVector>(const std::string& s, StringVector& group, char sep);
template bool GetStringGroup<WStringVector>(const std::wstring& s, WStringVector& group, wchar_t sep);
template bool GetStringGroup<StringSet>(const std::string& s, StringSet& group, char sep);
template bool GetStringGroup<WStringSet>(const std::wstring& s, WStringSet& group, wchar_t sep);
template <typename T> bool GetStringGroup(const std::string& s, T& group, char sep)
{
bool ret = false;
std::string::size_type oldpos = 0, newpos = 0;
if (!(s.empty()))
{
do
{
newpos = s.find(',',oldpos);
group.insert(group.end(),s.substr(oldpos,newpos));
if (newpos != s.npos)
oldpos = newpos+1;
}
while(newpos != s.npos);
ret = true;
}
return ret;
}
template <typename T> bool GetStringGroup(const std::wstring& s, T& group, wchar_t sep)
{
bool ret = false;
std::wstring::size_type oldpos = 0, newpos = 0;
if (!(s.empty()))
{
do
{
newpos = s.find(L',',oldpos);
group.insert(group.end(),s.substr(oldpos,newpos));
if (newpos != s.npos)
oldpos = newpos+1;
} while(newpos != s.npos);
ret = true;
}
return ret;
}
template bool GetStringGroupAsString<StringList>(const StringList& group, std::string& s, char sep);
template bool GetStringGroupAsString<WStringList>(const WStringList& group, std::wstring& s, wchar_t sep);
template bool GetStringGroupAsString<StringVector>(const StringVector& group, std::string& s, char sep);
template bool GetStringGroupAsString<WStringVector>(const WStringVector& group, std::wstring& s, wchar_t sep);
template bool GetStringGroupAsString<StringSet>(const StringSet& group, std::string& s, char sep);
template bool GetStringGroupAsString<WStringSet>(const WStringSet& group, std::wstring& s, wchar_t sep);
template <typename T> bool GetStringGroupAsString(const T& group, std::string& s, char sep)
{
typename T::const_iterator it = group.begin();
bool fst = true;
while (it != group.end())
{
if (!fst)
s += ",";
else
fst = false;
s+= (*it).c_str();
it++;
}
return true;
}
template <typename T> bool GetStringGroupAsString(const T& group, std::wstring& s, wchar_t sep)
{
typename T::const_iterator it = group.begin();
bool fst = true;
while (it != group.end())
{
if (!fst)
s += L",";
else
fst = false;
s+= (*it).c_str();
it++;
}
return true;
}
} // namespace std

210
Sources/Plasma/CoreLib/hsStlUtils.h

@ -1,210 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef hsStlUtils_h_inc
#define hsStlUtils_h_inc
#include "HeadSpin.h"
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
/*****************************************************************************
*
* stl extensions
*
***/
namespace xtl
{
// Why oh why doesn't stl have copy_if?
// See Effective STL [Meyers 2001] Item 36.
template< typename InIt, typename OutIt, typename Pred >
OutIt copy_if( InIt srcBegin, InIt srcEnd, OutIt dstBegin, Pred pred )
{
while ( srcBegin!=srcEnd )
{
if ( pred( *srcBegin ) )
*dstBegin++ = *srcBegin;
++srcBegin;
}
return dstBegin;
}
// useful when clearing a vector/list/set of pointers that need to be deleted.
// use like:
// std::vector<foo*> vec;
// std::for_each(vec.begin(),vec.end(),xtl::delete_ptr());
// vec.clear();
struct delete_ptr
{
template< class T > void operator()( T * p ) const { delete p;}
};
// useful when clearing a map of pointers that need to be deleted.
// use like:
// typedef std::map<int,foo*> foomap;
// foomap m;
// std::for_each(m.begin(),m.end(),xtl::delete_map_ptr_T<foomap>());
// m.clear();
template< class A >
struct delete_map_ptr_T
{
void operator()( typename A::value_type & pair ) const { delete pair.second;}
};
// case insensitive string comparer
// useful in maps that use strings
struct stricmp_less : public std::binary_function<std::string, std::string, bool>
{
bool operator()(const std::string & _X, const std::string & _Y) const
{return ( stricmp(_X.c_str(),_Y.c_str()) < 0); }
};
struct wstricmp_less : public std::binary_function<std::wstring, std::wstring, bool>
{
bool operator()(const std::wstring & _X, const std::wstring & _Y) const
{return ( wcsicmp(_X.c_str(),_Y.c_str()) < 0); }
};
// struct stricmp_char_traits
// case insensitive char_traits. used in creating istring class below
#ifdef __SGI_STL_PORT
struct stricmp_char_traits : public __std_alias::char_traits< char >
#else
struct stricmp_char_traits : public std::char_traits< char >
#endif
{
static int compare(const char * A, const char * B, size_t N)
{
for (size_t I=0; I<N; ++I, ++A,++B)
if (tolower(*A)!=tolower(*B))
return (lt(tolower(*A),tolower(*B))?-1:+1);
return (0);
}
static const char * find(const char * S, size_t N, const char & C)
{
char c = tolower(C);
for (; 0<N; --N, ++S)
if (c==tolower(*S))
return S;
return NULL;
}
};
#ifdef __SGI_STL_PORT
struct wstricmp_char_traits : public __std_alias::char_traits< wchar_t >
#else
struct wstricmp_char_traits : public std::char_traits< wchar_t >
#endif
{
static int compare(const wchar_t * A, const wchar_t * B, size_t N)
{
for (size_t I=0; I<N; ++I, ++A,++B)
if (tolower(*A)!=tolower(*B))
return (lt(tolower(*A),tolower(*B))?-1:+1);
return (0);
}
static const wchar_t * find(const wchar_t * S, size_t N, const wchar_t & C)
{
wchar_t c = tolower(C);
for (; 0<N; --N, ++S)
if (c==tolower(*S))
return S;
return NULL;
}
};
// class istring
// A string with case insensitive char_traits.
// Calls to its find* methods are case insensitive.
typedef std::basic_string<char, stricmp_char_traits> istring;
typedef std::basic_string<wchar_t, wstricmp_char_traits> iwstring;
// std::string trim
std::string & trimleft(std::string & s, const char * charset=" \t\n\r");
std::wstring & trimleft(std::wstring & s, const wchar_t * charset=L" \t\n\r");
std::string & trimright(std::string & s, const char * charset=" \t\n\r");
std::wstring & trimright(std::wstring & s, const wchar_t * charset=L" \t\n\r");
std::string & trim(std::string & s, const char * charset=" \t\n\r");
std::wstring & trim(std::wstring & s, const wchar_t * charset=L" \t\n\r");
// xtl::istring trim
xtl::istring & trimleft(xtl::istring & s, const char * charset=" \t\n\r");
xtl::iwstring & trimleft(xtl::iwstring & s, const wchar_t * charset=L" \t\n\r");
xtl::istring & trimright(xtl::istring & s, const char * charset=" \t\n\r");
xtl::iwstring & trimright(xtl::iwstring & s, const wchar_t * charset=L" \t\n\r");
xtl::istring & trim(xtl::istring & s, const char * charset=" \t\n\r");
xtl::iwstring & trim(xtl::iwstring & s, const wchar_t * charset=L" \t\n\r");
// c-string trim
std::string trim(const char * s, const char * charset=" \t\n\r");
std::wstring trim(const wchar_t * s, const wchar_t * charset=L" \t\n\r");
// format
std::string format(const char * fmt, ...);
std::wstring format(const wchar_t * fmt, ...);
std::string formatv(const char * fmt, va_list args);
std::wstring formatv(const wchar_t * fmt, va_list args);
bool format(std::string & out, const char * fmt, ...);
bool format(std::wstring & out, const wchar_t * fmt, ...);
bool formatv(std::string & out, const char * fmt, va_list args);
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args);
template <typename T> bool GetStringGroup(const std::string& s, T& group, char sep = ',');
template <typename T> bool GetStringGroup(const std::wstring& s, T& group, wchar_t sep = L',');
template <typename T> bool GetStringGroupAsString(const T& group, std::string& s, char sep = ',');
template <typename T> bool GetStringGroupAsString(const T& group, std::wstring& s, wchar_t sep = L',');
} // namespace xtd
#endif // hsStlUtils_h_inc

7
Sources/Plasma/CoreLib/hsStream.cpp

@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTemplates.h"
#include "hsStlUtils.h"
#if HS_BUILD_FOR_UNIX
#include <unistd.h>
@ -55,7 +54,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#if HS_BUILD_FOR_WIN32
#include <io.h>
#endif
#include "hsStlUtils.h"
//////////////////////////////////////////////////////////////////////////////////
@ -123,9 +121,8 @@ uint32_t hsStream::WriteFmt(const char * fmt, ...)
uint32_t hsStream::WriteFmtV(const char * fmt, va_list av)
{
std::string buf;
xtl::formatv( buf, fmt, av );
return Write( buf.length(), buf.data() );
plString buf = plString::IFormat(fmt, av);
return Write( buf.GetSize(), buf.c_str() );
}
uint32_t hsStream::WriteSafeStringLong(const plString &string)

3
Sources/Plasma/CoreLib/hsStream.h

@ -83,6 +83,9 @@ public:
hsStream() : fBytesRead(0), fPosition(0) {}
virtual ~hsStream() { }
// Pre-filename-stringification shortcut:
bool Open_TEMP(const plString & filename, const char * mode = "rb") { return Open(filename.c_str(), mode); }
virtual bool Open(const char *, const char * = "rb")=0;
virtual bool Open(const wchar_t *, const wchar_t * = L"rb")=0;
virtual bool Close()=0;

1
Sources/Plasma/CoreLib/plGeneric.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define __PLGENERIC_H__
#include "hsStream.h"
#include "hsStlUtils.h"
class plGeneric
{

115
Sources/Plasma/CoreLib/plString.cpp

@ -163,7 +163,7 @@ void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size)
while (sp < utf16 + size) {
if (*sp >= 0xD800 && *sp <= 0xDFFF) {
// Surrogate pair
unsigned int unichar = 0x10000;
UniChar unichar = 0x10000;
if (sp + 1 >= utf16 + size) {
hsAssert(0, "Incomplete surrogate pair in UTF-16 data");
@ -204,19 +204,25 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
// We assume that if sizeof(wchar_t) == 2, the data is UTF-16 already
IConvertFromUtf16((const uint16_t *)wstr, size);
#else
IConvertFromUtf32((const UniChar *)wstr, size);
#endif
}
void plString::IConvertFromUtf32(const UniChar *ustr, size_t size)
{
fUtf8Buffer = plStringBuffer<char>();
if (wstr == nil)
if (ustr == nil)
return;
if ((int32_t)size < 0)
size = wcsnlen(wstr, -(int32_t)size);
size = ustrlen(ustr, -(int32_t)size);
// Calculate the UTF-8 size
size_t convlen = 0;
const wchar_t *sp = wstr;
while (sp < wstr + size) {
const UniChar *sp = ustr;
while (sp < ustr + size) {
if (*sp > 0x10FFFF) {
hsAssert(0, "UCS-4 character out of range");
hsAssert(0, "UTF-32 character out of range");
convlen += 3; // Use U+FFFD for release builds
}
else if (*sp > 0xFFFF)
@ -233,8 +239,8 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
// And perform the actual conversion
char *utf8 = fUtf8Buffer.CreateWritableBuffer(convlen);
char *dp = utf8;
sp = wstr;
while (sp < wstr + size) {
sp = ustr;
while (sp < ustr + size) {
if (*sp > 0x10FFFF) {
// Character out of range; Use U+FFFD instead
*dp++ = 0xE0 | ((BADCHAR_REPLACEMENT >> 12) & 0x0F);
@ -258,7 +264,6 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
++sp;
}
utf8[convlen] = 0;
#endif
}
void plString::IConvertFromIso8859_1(const char *astr, size_t size)
@ -327,7 +332,7 @@ plStringBuffer<uint16_t> plString::ToUtf16() const
uint16_t *dp = ustr;
sp = utf8;
while (sp < utf8 + srcSize) {
unsigned int unichar;
UniChar unichar;
if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12;
@ -361,11 +366,18 @@ plStringBuffer<wchar_t> plString::ToWchar() const
plStringBuffer<uint16_t> utf16 = ToUtf16();
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf16);
#else
plStringBuffer<wchar_t> result;
plUnicodeBuffer utf32 = GetUnicodeArray();
return *reinterpret_cast<plStringBuffer<wchar_t>*>(&utf32);
#endif
}
plStringBuffer<char> plString::ToIso8859_1() const
{
plStringBuffer<char> result;
if (IsEmpty())
return result;
// Calculate the UCS-4 size
// Calculate the ASCII size
size_t convlen = 0;
const char *utf8 = fUtf8Buffer.GetData();
const char *sp = utf8;
@ -383,11 +395,11 @@ plStringBuffer<wchar_t> plString::ToWchar() const
}
// And perform the actual conversion
wchar_t *wstr = result.CreateWritableBuffer(convlen);
wchar_t *dp = wstr;
char *astr = result.CreateWritableBuffer(convlen);
char *dp = astr;
sp = utf8;
while (sp < utf8 + srcSize) {
unsigned int unichar;
UniChar unichar;
if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12;
@ -403,21 +415,20 @@ plStringBuffer<wchar_t> plString::ToWchar() const
} else {
unichar = *sp++;
}
*dp++ = unichar;
*dp++ = (unichar < 0xFF) ? unichar : '?';
}
wstr[convlen] = 0;
astr[convlen] = 0;
return result;
#endif
}
plStringBuffer<char> plString::ToIso8859_1() const
plUnicodeBuffer plString::GetUnicodeArray() const
{
plStringBuffer<char> result;
plUnicodeBuffer result;
if (IsEmpty())
return result;
// Calculate the ASCII size
// Calculate the UCS-4 size
size_t convlen = 0;
const char *utf8 = fUtf8Buffer.GetData();
const char *sp = utf8;
@ -435,11 +446,11 @@ plStringBuffer<char> plString::ToIso8859_1() const
}
// And perform the actual conversion
char *astr = result.CreateWritableBuffer(convlen);
char *dp = astr;
UniChar *ustr = result.CreateWritableBuffer(convlen);
UniChar *dp = ustr;
sp = utf8;
while (sp < utf8 + srcSize) {
unsigned int unichar;
UniChar unichar;
if ((*sp & 0xF8) == 0xF0) {
unichar = (*sp++ & 0x07) << 18;
unichar |= (*sp++ & 0x3F) << 12;
@ -455,25 +466,8 @@ plStringBuffer<char> plString::ToIso8859_1() const
} else {
unichar = *sp++;
}
*dp++ = (unichar < 0xFF) ? unichar : '?';
*dp++ = unichar;
}
astr[convlen] = 0;
return result;
}
plStringBuffer<UniChar> plString::GetUnicodeArray() const
{
plStringBuffer<UniChar> result;
if (IsEmpty())
return result;
size_t convlen = GetUniCharCount();
UniChar *ustr = result.CreateWritableBuffer(convlen);
iterator iter = GetIterator();
size_t dp = 0;
while (!iter.AtEnd())
ustr[dp++] = *iter++;
ustr[convlen] = 0;
return result;
@ -518,18 +512,24 @@ plString plString::IFormat(const char *fmt, va_list vptr)
int size = 4096;
for ( ;; ) {
va_copy(vptr, vptr_save);
std::auto_ptr<char> bigbuffer(new char[size]);
chars = vsnprintf(bigbuffer.get(), size, fmt, vptr);
if (chars >= 0)
return plString::FromUtf8(bigbuffer.get(), chars);
plStringBuffer<char> bigbuffer;
char *data = bigbuffer.CreateWritableBuffer(size-1);
chars = vsnprintf(data, size, fmt, vptr);
if (chars >= 0) {
// We need to construct a new string here so the length
// parameter is accurate :(
return plString::FromUtf8(bigbuffer.GetData(), chars);
}
size *= 2;
hsAssert(size > 0, "Formatted string output is waaaaay too long");
}
} else if (chars >= 256) {
va_copy(vptr, vptr_save);
std::unique_ptr<char> bigbuffer(new char[chars+1]);
vsnprintf(bigbuffer.get(), chars+1, fmt, vptr);
return plString::FromUtf8(bigbuffer.get(), chars);
plStringBuffer<char> bigbuffer;
char *data = bigbuffer.CreateWritableBuffer(chars);
vsnprintf(data, chars+1, fmt, vptr);
return bigbuffer;
}
return plString::FromUtf8(buffer, chars);
@ -754,6 +754,15 @@ std::vector<plString> plString::Split(const char *split, size_t maxSplits) const
return result;
}
plString plString::Fill(size_t count, char c)
{
plStringBuffer<char> buf;
char *data = buf.CreateWritableBuffer(count + 1);
memset(data, c, count);
data[count] = 0;
return buf;
}
plString operator+(const plString &left, const plString &right)
{
plString cat;
@ -822,3 +831,11 @@ plStringStream &plStringStream::operator<<(unsigned int num)
snprintf(buffer, 12, "%u", num);
return operator<<(buffer);
}
size_t ustrlen(const UniChar *ustr, size_t max)
{
size_t length = 0;
for ( ; *ustr++ && max--; ++length)
;
return length;
}

128
Sources/Plasma/CoreLib/plString.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
typedef unsigned int UniChar;
#define SSO_CHARS (16)
#define WHITESPACE_CHARS " \t\n\r"
template <typename _Ch>
class plStringBuffer
@ -121,7 +122,6 @@ public:
const _Ch *GetData() const { return IHaveACow() ? fData->fStringData : fShort; }
size_t GetSize() const { return fSize; }
operator const _Ch *() const { return GetData(); }
// From Haxxia with love
@ -142,14 +142,15 @@ public:
}
};
typedef plStringBuffer<UniChar> plUnicodeBuffer;
class plString
{
public:
enum {
kSizeAuto = (size_t)(0x80000000)
};
public:
static const plString Null;
private:
@ -158,6 +159,7 @@ private:
void IConvertFromUtf8(const char *utf8, size_t size);
void IConvertFromUtf16(const uint16_t *utf16, size_t size);
void IConvertFromWchar(const wchar_t *wstr, size_t size);
void IConvertFromUtf32(const UniChar *ustr, size_t size);
void IConvertFromIso8859_1(const char *astr, size_t size);
public:
@ -166,10 +168,12 @@ public:
plString(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); }
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { }
plString(const plStringBuffer<char> &init) { operator=(init); }
plString(const plUnicodeBuffer &init) { IConvertFromUtf32(init.GetData(), init.GetSize()); }
plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); return *this; }
plString &operator=(const plString &copy) { fUtf8Buffer = copy.fUtf8Buffer; return *this; }
plString &operator=(const plStringBuffer<char> &init);
plString &operator=(const plUnicodeBuffer &init) { IConvertFromUtf32(init.GetData(), init.GetSize()); return *this; }
plString &operator+=(const char *cstr) { return operator=(*this + cstr); }
plString &operator+=(const plString &str) { return operator=(*this + str); }
@ -213,7 +217,7 @@ public:
plStringBuffer<char> ToIso8859_1() const;
// For use in displaying characters in a GUI
plStringBuffer<UniChar> GetUnicodeArray() const;
plUnicodeBuffer GetUnicodeArray() const;
size_t GetSize() const { return fUtf8Buffer.GetSize(); }
bool IsEmpty() const { return fUtf8Buffer.GetSize() == 0; }
@ -276,15 +280,15 @@ public:
int Find(const plString &str, CaseSensitivity sense = kCaseSensitive) const
{ return Find(str.c_str(), sense); }
plString TrimLeft(const char *charset = " \t\n\r") const;
plString TrimRight(const char *charset = " \t\n\r") const;
plString Trim(const char *charset = " \t\n\r") const;
plString TrimLeft(const char *charset = WHITESPACE_CHARS) const;
plString TrimRight(const char *charset = WHITESPACE_CHARS) const;
plString Trim(const char *charset = WHITESPACE_CHARS) const;
plString Substr(int start, size_t size = kSizeAuto) const;
plString Left(size_t size) const { return Substr(0, size); }
plString Right(size_t size) const { return Substr(GetSize() - size, size); }
// NOTE: Does ::Compare(blah, kCaseInsensitive) make more sense? If
// NOTE: Does Compare(blah, kCaseInsensitive) make more sense? If
// so, use that instead -- it's faster and more efficient!
plString ToUpper() const;
plString ToLower() const;
@ -294,7 +298,9 @@ public:
// all delimiters and only returns the pieces left between them), whereas
// Split will split on a full string, returning whatever is left between.
std::vector<plString> Split(const char *split, size_t maxSplits = kSizeAuto) const;
std::vector<plString> Tokenize(const char *delims = " \t\r\n\f\v") const;
std::vector<plString> Tokenize(const char *delims = WHITESPACE_CHARS) const;
static plString Fill(size_t count, char c);
public:
struct less
@ -321,108 +327,6 @@ public:
{ return _L.Compare(_R, kCaseInsensitive) == 0; }
};
public:
struct iterator
{
iterator() : m_ptr(nil), m_end(nil) { }
iterator(const iterator &copy) : m_ptr(copy.m_ptr), m_end(copy.m_end) { }
iterator &operator=(const iterator &copy)
{ m_ptr = copy.m_ptr; m_end = copy.m_end; return *this; }
iterator &operator++()
{
if ((*m_ptr & 0xF8) == 0xF0)
m_ptr += 4;
else if ((*m_ptr & 0xF0) == 0xE0)
m_ptr += 3;
else if ((*m_ptr & 0xE0) == 0xC0)
m_ptr += 2;
else
m_ptr += 1;
return *this;
}
iterator operator++(int)
{
iterator iter_save = *this;
(void) operator++();
return iter_save;
}
iterator &operator+=(size_t delta)
{
while (delta) {
operator++();
--delta;
}
return *this;
}
iterator operator+(size_t delta) const
{
iterator copy(*this);
copy += delta;
return copy;
}
int operator-(const iterator &other) const
{
return (int)(m_ptr - other.m_ptr);
}
bool operator==(const iterator &other) const { return m_ptr == other.m_ptr; }
bool operator!=(const iterator &other) const { return m_ptr != other.m_ptr; }
bool operator<(const iterator &other) const { return m_ptr < other.m_ptr; }
bool operator>(const iterator &other) const { return m_ptr > other.m_ptr; }
bool operator<=(const iterator &other) const { return m_ptr <= other.m_ptr; }
bool operator>=(const iterator &other) const { return m_ptr >= other.m_ptr; }
UniChar operator*() const
{
UniChar ch;
if ((*m_ptr & 0xF8) == 0xF0) {
ch = (m_ptr[0] & 0x07) << 18;
ch |= (m_ptr[1] & 0x3F) << 12;
ch |= (m_ptr[2] & 0x3F) << 6;
ch |= (m_ptr[3] & 0x3F);
} else if ((*m_ptr & 0xF0) == 0xE0) {
ch = (m_ptr[0] & 0x0F) << 12;
ch |= (m_ptr[1] & 0x3F) << 6;
ch |= (m_ptr[2] & 0x3F);
} else if ((*m_ptr & 0xE0) == 0xC0) {
ch = (m_ptr[0] & 0x1F) << 6;
ch |= (m_ptr[1] & 0x3F);
} else {
ch = m_ptr[0];
}
return ch;
}
bool AtEnd() const { return m_ptr >= m_end; }
bool IsValid() const { return m_ptr != 0; }
private:
friend class plString;
iterator(const char *ptr, size_t size) : m_ptr(ptr), m_end(ptr + size) { }
const char *m_ptr;
const char *m_end;
};
iterator GetIterator() const { return iterator(c_str(), GetSize()); }
size_t GetUniCharCount() const
{
iterator iter = GetIterator();
size_t count = 0;
while (!iter.AtEnd()) {
++iter;
++count;
}
return count;
}
private:
friend plString operator+(const plString &left, const plString &right);
friend plString operator+(const plString &left, const char *right);
@ -464,4 +368,6 @@ private:
size_t fLength;
};
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto);
#endif //plString_Defined

1
Sources/Plasma/FeatureLib/pfAnimation/pfObjectFlocker.cpp

@ -40,7 +40,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "hsMatrix44.h"
#include "hsGeometry3.h"
#include "plgDispatch.h"

1
Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp

@ -39,7 +39,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include "hsStlUtils.h"
#include "hsResMgr.h"
#include "hsTemplates.h"
#include "hsTimer.h"

1
Sources/Plasma/FeatureLib/pfCamera/plCameraBrain.cpp

@ -40,6 +40,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include <cmath>
#include "plCameraBrain.h"
#include "hsTimer.h"

2
Sources/Plasma/FeatureLib/pfCamera/plVirtualCamNeu.cpp

@ -41,6 +41,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include <algorithm>
#include "plVirtualCamNeu.h"
#include "plCameraModifier.h"
#include "plCameraBrain.h"

3
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -161,7 +161,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plStatusLog/plStatusLog.h"
#include "pnTimer/pnBuildDates.h"
#include "hsStlUtils.h"
#include "hsTemplates.h"
#include "plResMgr/plResManagerHelper.h"
@ -538,7 +537,7 @@ PF_CONSOLE_CMD(Stats, ListGroups, "", "Prints the names of all the stat groups t
plProfileManagerFull::GroupSet::iterator it;
for (it = groups.begin(); it != groups.end(); it++)
PrintString((char*)*it);
PrintString(it->c_str());
}
PF_CONSOLE_CMD(Stats, ListLaps, "", "Prints the names of all the stats with laps to the console")

1
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp

@ -88,7 +88,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plStatusLog/plStatusLog.h"
#include "hsStlUtils.h"
#include "hsTemplates.h"
#include "plVault/plVault.h"

3
Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.h

@ -56,7 +56,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _pfConsoleDirSrc_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <vector>
#include "pfConsoleCore/pfConsoleEngine.h"
//// pfConsoleDirSrc Class Definition ////////////////////////////////////////

14
Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp

@ -48,7 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plKey.h"
#include "plString.h"
static bool DumpSpecificMsgInfo(plMessage* msg, std::string& info);
static bool DumpSpecificMsgInfo(plMessage* msg, plString& info);
plDispatchLog::plDispatchLog() :
fLog(nil),
@ -101,7 +101,7 @@ void plDispatchLog::LogStatusBarChange(const char* name, const char* action)
void plDispatchLog::LogLongReceive(const char* keyname, const char* className, uint32_t clonePlayerID, plMessage* msg, float ms)
{
std::string info;
plString info;
if (DumpSpecificMsgInfo(msg, info))
fLog->AddLineF("%-30s[%7u](%-20s) took %6.1f ms to receive %s[%s]\n", keyname, clonePlayerID, className, ms, msg->ClassName(), info.c_str());
else
@ -195,7 +195,7 @@ void plDispatchLog::RemoveFilterExactType(uint16_t type)
#include "plResMgr/plKeyFinder.h"
#include "plResMgr/plPageInfo.h"
static bool DumpSpecificMsgInfo(plMessage* msg, std::string& info)
static bool DumpSpecificMsgInfo(plMessage* msg, plString& info)
{
#ifndef PLASMA_EXTERNAL_RELEASE // Don't bloat up the external release with all these strings
pfKIMsg* kiMsg = pfKIMsg::ConvertNoRef(msg);
@ -257,7 +257,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, std::string& info)
PrintKIType(kGZFlashUpdate); // flash an update without saving (for animation of GZFill in)
PrintKIType(kNoCommand);
info = xtl::format("Type: %s Str: %s User: %s(%d) Delay: %f Int: %d",
info = plString::Format("Type: %s Str: %s User: %s(%d) Delay: %f Int: %d",
typeName,
kiMsg->GetString() != "" ? kiMsg->GetString().c_str() : "(nil)",
kiMsg->GetUser() ? kiMsg->GetUser() : "(nil)",
@ -298,14 +298,14 @@ static bool DumpSpecificMsgInfo(plMessage* msg, std::string& info)
const plPageInfo* pageInfo = plKeyFinder::Instance().GetLocationInfo(loc);
if (pageInfo)
info += xtl::format("%s-%s ", pageInfo->GetAge(), pageInfo->GetPage());
info += plString::Format("%s-%s ", pageInfo->GetAge(), pageInfo->GetPage());
}
}
break;
case plClientMsg::kLoadAgeKeys:
case plClientMsg::kReleaseAgeKeys:
info += xtl::format(" - Age: %s", clientMsg->GetAgeName());
info += plString::Format(" - Age: %s", clientMsg->GetAgeName());
break;
}
return true;
@ -321,7 +321,7 @@ static bool DumpSpecificMsgInfo(plMessage* msg, std::string& info)
GetType(kOnRequest);
GetType(kOnRemove);
GetType(kOnReplace);
xtl::format(info, "Obj: %s RefType: %s", refMsg->GetRef()->GetKeyName().c_str(), typeName);
info = plString::Format("Obj: %s RefType: %s", refMsg->GetRef()->GetKeyName().c_str(), typeName);
return true;
}

1
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIEditBoxMod.h

@ -48,7 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef _pfGUIEditBoxMod_h
#define _pfGUIEditBoxMod_h
#include "hsStlUtils.h"
#include "pfGUIControlMod.h"
#include "pnInputCore/plKeyDef.h"

1
Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUITextBoxMod.cpp

@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//////////////////////////////////////////////////////////////////////////////
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pfGUITextBoxMod.h"
#include "pfGameGUIMgr.h"

1
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.cpp

@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pfJournalBook.h"
#include <wchar.h>
#include "hsStlUtils.h"
#include "hsResMgr.h"
#include "pcSmallRect.h"
#include "plgDispatch.h"

4
Sources/Plasma/FeatureLib/pfJournalBook/pfJournalBook.h

@ -165,7 +165,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//////////////////////////////////////////////////////////////////////////////
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <map>
#include <string>
#include "hsTemplates.h"
#include "hsColorRGBA.h"

2
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationDataMgr.h

@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _pfLocalizationDataMgr_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <map>
#include "pfLocalizedString.h"

1
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizationMgr.h

@ -50,7 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _pfLocalizationMgr_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
class pfLocalizationMgr
{

1
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.cpp

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "pfLocalizedString.h"
// MinGW sucks

3
Sources/Plasma/FeatureLib/pfLocalizationMgr/pfLocalizedString.h

@ -51,7 +51,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _pfLocalizedString_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <vector>
#include <string>
//// pfLocalizedString Class Definition //////////////////////////////

1
Sources/Plasma/FeatureLib/pfMessage/pfKIMsg.h

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _pfKIMsg_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "hsStream.h"
#include "pnMessage/plMessage.h"

1
Sources/Plasma/FeatureLib/pfPython/Games/Heek/pyHeekMsg.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// PURPOSE: Class wrapper for Heek game messages
//
#include <string>
#include "../../pyGlueHelpers.h"
#include "../pyGameCliMsg.h"

1
Sources/Plasma/FeatureLib/pfPython/Games/Marker/pyMarkerMsg.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// PURPOSE: Class wrapper for Marker game messages
//
#include <string>
#include "../../pyGlueHelpers.h"
#include "../pyGameCliMsg.h"

1
Sources/Plasma/FeatureLib/pfPython/Games/VarSync/pyVarSyncMsg.h

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// PURPOSE: Class wrapper for VarSync game messages
//
#include <string>
#include "../../pyGlueHelpers.h"
#include "../pyGameCliMsg.h"

3
Sources/Plasma/FeatureLib/pfPython/Pch.h

@ -52,6 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <algorithm>
#include <exception>
#include <locale>
#include <string>
// Platform Library Includes
#include <time.h>
@ -69,8 +70,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsGeometry3.h"
#include "hsQuat.h"
#include "hsResMgr.h"
#include "hsStlSortUtils.h"
#include "hsStlUtils.h"
#include "hsStream.h"
#include "hsTemplates.h"
#include "hsTimer.h"

1
Sources/Plasma/FeatureLib/pfPython/cyAccountManagement.h

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
#include <vector>
#include <string>
typedef struct _object PyObject;
typedef struct PyMethodDef PyMethodDef;

2
Sources/Plasma/FeatureLib/pfPython/cyAvatar.h

@ -48,7 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
// PURPOSE: Class wrapper to map animation functions to plasma2 message
//
#include "hsStlUtils.h"
#include <string>
#include "hsTemplates.h"
#include "pnKeyedObject/plKey.h"

1
Sources/Plasma/FeatureLib/pfPython/cyMisc.h

@ -59,6 +59,7 @@ class pyPoint3;
#include "HeadSpin.h"
#include <vector>
#include <string>
class pyGUIDialog;
class plPipeline;

2
Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.h

@ -47,8 +47,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// only be one instance of this interface.
//
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "plString.h"
#include <string>
#if defined(HAVE_CYPYTHONIDE) && !defined(PLASMA_EXTERNAL_RELEASE)
#include "../../Apps/CyPythonIDE/plCyDebug/plCyDebServer.h"

5
Sources/Plasma/FeatureLib/pfPython/plPythonPack.cpp

@ -45,11 +45,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "hsStream.h"
#include "hsStlSortUtils.h"
#pragma hdrstop
#include "plPythonPack.h"
@ -219,7 +218,7 @@ PyObject* plPythonPack::OpenPacked(const char* fileName)
{
char *buf = new char[size];
uint32_t readSize = fPackStream->Read(size, buf);
hsAssert(readSize <= size, xtl::format("Python PackFile %s: Incorrect amount of data, read %d instead of %d",
hsAssert(readSize <= size, plString::Format("Python PackFile %s: Incorrect amount of data, read %d instead of %d",
fileName, readSize, size).c_str());
// let the python marshal make it back into a code object

2
Sources/Plasma/FeatureLib/pfPython/plPythonSDLModifier.h

@ -46,7 +46,7 @@ class plPythonFileMod;
class plStateDataRecord;
class plSimpleStateVariable;
#include "hsStlUtils.h"
#include <map>
#include "plModifier/plSDLModifier.h"
#include "pyGlueHelpers.h"

1
Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.cpp

@ -41,6 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include <Python.h>
#include <string>
#pragma hdrstop
#include "pyAgeInfoStruct.h"

1
Sources/Plasma/FeatureLib/pfPython/pyAgeInfoStruct.h

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef pyAgeInfoStruct_h_inc
#define pyAgeInfoStruct_h_inc
#include "hsStlUtils.h"
#include "plNetCommon/plNetServerSessionInfo.h"
#include "pyGlueHelpers.h"

1
Sources/Plasma/FeatureLib/pfPython/pyCCRMgr.h

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//////////////////////////////////////////////////////////////////////
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pfCCR/plCCRMgr.h"

1
Sources/Plasma/FeatureLib/pfPython/pyEnum.cpp

@ -49,7 +49,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h>
#include <structmember.h>
#include "hsStlUtils.h"
#include "pyGlueHelpers.h"
#pragma hdrstop

1
Sources/Plasma/FeatureLib/pfPython/pyJournalBook.h

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pyGlueHelpers.h"
#include <vector>
#include <string>
class cyAnimation;
class pyImage;

3
Sources/Plasma/FeatureLib/pfPython/pySDL.h

@ -49,7 +49,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//////////////////////////////////////////////////////////////////////
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <vector>
#include "pyGlueHelpers.h"
class plStateDataRecord;

1
Sources/Plasma/NucleusLib/inc/plPipeline.h

@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnFactory/plCreatable.h"
#include "hsGMatState.h"
#include "hsTemplates.h"
#include "hsStlUtils.h"
#define MIN_WIDTH 640
#define MIN_HEIGHT 480

3
Sources/Plasma/NucleusLib/inc/plProfileManager.h

@ -43,7 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plProfileManager_h_inc
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <vector>
#include "plProfile.h"
class plProfileManager

2
Sources/Plasma/NucleusLib/pnDispatch/plDispatch.cpp

@ -331,7 +331,7 @@ void plDispatch::IMsgDispatch()
if (plNetObjectDebuggerBase::GetInstance()->IsDebugObject(ko))
{
hsLogEntry(plNetObjectDebuggerBase::GetInstance()->LogMsg(
xtl::format("<RCV> object:%s, GameMessage %s st=%.3f rt=%.3f",
plString::Format("<RCV> object:%s, GameMessage %s st=%.3f rt=%.3f",
ko->GetKeyName().c_str(), msg->ClassName(), hsTimer::GetSysSeconds(), hsTimer::GetSeconds()).c_str()));
}
}

2
Sources/Plasma/NucleusLib/pnDispatch/plDispatch.h

@ -42,8 +42,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plDispatch_inc
#define plDispatch_inc
#include <list>
#include "hsTemplates.h"
#include "hsStlUtils.h"
#include "plgDispatch.h"
#include "hsThread.h"
#include "pnKeyedObject/hsKeyedObject.h"

2
Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.h

@ -42,9 +42,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plMsgForwarder_h_inc
#define plMsgForwarder_h_inc
#include <map>
#include "hsKeyedObject.h"
#include "hsTemplates.h"
#include "hsStlUtils.h"
class plMessageWithCallbacks;

1
Sources/Plasma/NucleusLib/pnMessage/plClientMsg.h

@ -47,7 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
#include "hsResMgr.h"
#include "hsStlUtils.h"
#include "pnKeyedObject/plUoid.h"
//

39
Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp

@ -280,7 +280,7 @@ int plMsgStdStringHelper::Peek(std::string & stringref, hsStream* stream, const
stringref.resize(strlen);
if (strlen){
stream->LogRead(strlen,(void*)stringref.data(),"StdString");
stream->LogStringString(xtl::format("Value: %s", stringref.data()).c_str());
stream->LogStringString(plString::Format("Value: %s", stringref.data()).c_str());
}
}
else
@ -302,7 +302,7 @@ int plMsgStdStringHelper::PeekBig(std::string & stringref, hsStream* stream, co
stringref.resize(bufsz);
if (bufsz){
stream->LogRead(bufsz,(void*)stringref.data(),"StdString");
stream->LogStringString(xtl::format("Value: %s", stringref.data()).c_str());
stream->LogStringString(plString::Format("Value: %s", stringref.data()).c_str());
}
}
else
@ -329,39 +329,6 @@ int plMsgStdStringHelper::PeekBig(plString & stringref, hsStream* stream, const
return pos;
}
/////////////////////////////////////////////////////////////////
// STATIC
int plMsgXtlStringHelper::Poke(const xtl::istring & stringref, hsStream* stream, const uint32_t peekOptions)
{
plMessage::plStrLen strlen;
strlen = stringref.length();
stream->WriteLE(strlen);
if (strlen)
stream->Write(strlen,stringref.data());
return stream->GetPosition();
}
// STATIC
int plMsgXtlStringHelper::Peek(xtl::istring & stringref, hsStream* stream, const uint32_t peekOptions)
{
plMessage::plStrLen strlen;
stream->LogSubStreamStart("push me");
stream->LogReadLE(&strlen,"StrLen");
stringref.erase();
if (strlen <= stream->GetSizeLeft())
{
stringref.resize(strlen);
if (strlen){
stream->LogRead(strlen,(void*)stringref.data(),"XtlString");
stream->LogStringString(xtl::format("Value: %s", stringref.data()).c_str());
}
}
stream->LogSubStreamEnd();
return stream->GetPosition();
}
/////////////////////////////////////////////////////////////////
// STATIC
@ -390,7 +357,7 @@ int plMsgCStringHelper::Peek(char *& str, hsStream* stream, const uint32_t peekO
str[strlen] = '\0';
if (strlen) {
stream->LogRead(strlen,str,"CString");
stream->LogStringString(xtl::format("Value: %s",str).c_str());
stream->LogStringString(plString::Format("Value: %s",str).c_str());
}
}
}

13
Sources/Plasma/NucleusLib/pnMessage/plMessage.h

@ -43,10 +43,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plMessage_inc
#define plMessage_inc
#include <string>
#include "pnFactory/plCreatable.h"
#include "pnKeyedObject/plKey.h"
#include "hsTemplates.h"
#include "hsStlUtils.h"
class plKey;
class hsStream;
@ -157,8 +157,8 @@ public:
/////////////////////////////////////////////////////////////////
// Helpers for reading/writing these types:
// plString
// std::string
// xtl::istring
// c strings (char *)
// c arrays (type [])
@ -180,15 +180,6 @@ struct plMsgStdStringHelper
static int PeekBig(plString & stringref, hsStream* stream, const uint32_t peekOptions=0);
};
/////////////////////////////////////////////////////////////////
// reads/writes your xtl::istring field
struct plMsgXtlStringHelper
{
static int Poke(const xtl::istring & stringref, hsStream* stream, const uint32_t peekOptions=0);
static int Peek(xtl::istring & stringref, hsStream* stream, const uint32_t peekOptions=0);
};
/////////////////////////////////////////////////////////////////
// reads/writes your char * field (deprecated)

34
Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.cpp

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
#include "plGenericVar.h"
#include "hsMemory.h"
#include "hsStlUtils.h"
//////////////////////////////////////////////////////
// plGenericType
@ -317,45 +316,28 @@ void plGenericType::SetVar(Types t, unsigned int size, void* val)
}
std::string plGenericType::GetAsStdString() const
plString plGenericType::GetAsString() const
{
std::string s;
switch (fType)
{
case kInt :
{
xtl::format(s,"%d",fI);
break;
}
return plString::Format("%d", fI);
case kBool :
case kUInt :
{
xtl::format(s,"%u",fType==kBool?fB:fU);
break;
}
return plString::Format("%u", fType==kBool?fB:fU);
case kFloat :
case kDouble :
{
xtl::format(s,"%f",fType==kDouble?fD:fF);
break;
}
return plString::Format("%f", fType==kDouble?fD:fF);
case kChar :
{
xtl::format(s,"%c",fC);
break;
}
return plString::Format("%c", fC);
case kAny :
case kString :
{
s = fS;
break;
}
return fS;
case kNone :
break;
default:
hsAssert(false,"plGenericType::GetAsStdString unknown type");
}
return s;
}
return plString::Null;
}

3
Sources/Plasma/NucleusLib/pnNetCommon/plGenericVar.h

@ -44,7 +44,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pnFactory/plCreatable.h"
class hsStream;
@ -117,7 +116,7 @@ public:
void SetType(Types t) { fType=t; }
uint8_t GetType( void ) const { return fType; }
std::string GetAsStdString() const;
plString GetAsString() const;
// implicit set
void Set( int32_t i ) { fI = i; fType = kInt; }

1
Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h

@ -48,7 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsWindows.h" // FIXME
#include "plString.h"
#include "hsStlUtils.h"
#include "hsStream.h"
#if defined(HS_BUILD_FOR_WIN32)

1
Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.cpp

@ -40,7 +40,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "plNetApp.h"
#include "hsStlUtils.h"
#include "pnMessage/plMessage.h"
plNetApp* plNetApp::fInstance = nil;

3
Sources/Plasma/NucleusLib/pnNetCommon/plNetApp.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plNetApp_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "hsBitVector.h"
#include "plNetGroup.h"
@ -192,7 +191,7 @@ public:
virtual int IsLocallyOwned(const plUoid&) const { hsAssert(false, "stub"); return 0; }
virtual plNetGroupId GetEffectiveNetGroup(const plSynchedObject* obj) const { hsAssert(false, "stub"); return plNetGroup::kNetGroupUnknown; }
virtual int Update(double secs) { return hsOK;}
virtual const char* GetServerLogTimeAsString(std::string& ts) const { hsAssert(false, "stub"); return nil; }
virtual const char* GetServerLogTimeAsString(plString& ts) const { hsAssert(false, "stub"); return nil; }
virtual plUoid GetAgeSDLObjectUoid(const char* ageName) const { hsAssert(false, "stub"); return plUoid(); }
virtual void StayAlive(double secs) {}
virtual void QueueDisableNet( bool showDlg, const char msg[] ) {}

2
Sources/Plasma/NucleusLib/pnNetCommon/plNetGroup.h

@ -42,9 +42,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plNetGroup_h
#define plNetGroup_h
#include <string>
#include "pnKeyedObject/plUoid.h"
#include "hsStream.h"
#include "hsStlUtils.h"
class plNetGroupId
{

3
Sources/Plasma/NucleusLib/pnNetCommon/plNetSharedState.h

@ -43,8 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plNetSharedState_inc
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <string>
class hsStream;

1
Sources/Plasma/NucleusLib/pnNetCommon/plSynchedObject.h

@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "pnKeyedObject/hsKeyedObject.h"
#include "pnKeyedObject/plKey.h"
#include "hsStlUtils.h"
#include "plNetGroup.h"
/////////////////////////////////////

1
Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp

@ -39,6 +39,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include <string>
#include "pnNetCommon.h"
#include "hsWindows.h"

1
Sources/Plasma/NucleusLib/pnProduct/Private/pnPrProductId.cpp

@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
***/
#include "../Pch.h"
#include <wchar.h>
#pragma hdrstop

1
Sources/Plasma/NucleusLib/pnUUID/pnUUID.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define pnUUID_h_inc
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pnUtils/pnUtUuid.h"
class hsStream;

3
Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"
#include "plAgeDescription.h"
#include "hsStlUtils.h"
#include "plFile/hsFiles.h"
#include "plFile/plInitFileReader.h"
#include "plFile/plEncryptedStream.h"
@ -162,7 +161,7 @@ char *plAgePage::GetAsString( void ) const
//
// static
char plAgeDescription::kAgeDescPath[]={"dat"PATH_SEPARATOR_STR};
char plAgeDescription::kAgeDescPath[] = { "dat" PATH_SEPARATOR_STR };
const char* plAgeDescription::fCommonPages[] = { "Textures", "BuiltIn" };
// Also gotta init the separators for our helper reading function

1
Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoader.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plAgeLoader_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pnUtils/pnUtils.h"
#include "pnNetBase/pnNetBase.h"

34
Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp

@ -69,19 +69,19 @@ public:
fIsZipped = wcscmp(plFileUtils::GetFileExt(reqFile), L"gz") == 0;
}
~plResDownloadStream()
virtual ~plResDownloadStream()
{
if (fFilename)
delete[] fFilename;
}
bool Open(const char* filename, const char* mode)
virtual bool Open(const char* filename, const char* mode)
{
fFilename = hsStrcpy(filename);
return plZlibStream::Open(filename, mode);
}
uint32_t Write(uint32_t count, const void* buf)
virtual uint32_t Write(uint32_t count, const void* buf)
{
fProgress->Increment((float)count);
if (fIsZipped)
@ -231,37 +231,33 @@ void plResPatcher::IssueRequest()
Request req = fRequests.front();
fRequests.pop();
std::wstring title;
plString title;
if (req.fType == kManifest)
{
char* eapSucksString = hsWStringToString(req.fFile.c_str());
PatcherLog(kMajorStatus, " Downloading manifest... %s", eapSucksString);
xtl::format(title, L"Checking %s for updates...", req.fFile.c_str());
PatcherLog(kMajorStatus, " Downloading manifest... %S", req.fFile.c_str());
title = plString::Format("Checking %S for updates...", req.fFile.c_str());
NetCliFileManifestRequest(ManifestDownloaded, this, req.fFile.c_str());
delete[] eapSucksString;
} else if (req.fType == kFile) {
char* eapSucksString = hsWStringToString(req.fFriendlyName.c_str());
PatcherLog(kMajorStatus, " Downloading file... %s", eapSucksString);
xtl::format(title, L"Downloading... %s", plFileUtils::GetFileName(req.fFriendlyName.c_str()));
PatcherLog(kMajorStatus, " Downloading file... %S", req.fFriendlyName.c_str());
title = plString::Format("Downloading... %S", plFileUtils::GetFileName(req.fFriendlyName.c_str()));
// If this is a PRP, we need to unload it from the ResManager
if (stricmp(plFileUtils::GetFileExt(eapSucksString), "prp") == 0)
((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(eapSucksString);
plString filename = plString::FromWchar(req.fFriendlyName.c_str());
if (stricmp(plFileUtils::GetFileExt(filename.c_str()), "prp") == 0)
((plResManager*)hsgResMgr::ResMgr())->RemoveSinglePage(filename.c_str());
plFileUtils::EnsureFilePathExists(req.fFriendlyName.c_str());
plResDownloadStream* stream = new plResDownloadStream(fProgress, req.fFile.c_str());
if(stream->Open(eapSucksString, "wb"))
if (stream->Open_TEMP(filename, "wb"))
NetCliFileDownloadRequest(req.fFile.c_str(), stream, FileDownloaded, this);
else {
PatcherLog(kError, " Unable to create file %s", eapSucksString);
PatcherLog(kError, " Unable to create file %s", filename.c_str());
Finish(false);
}
delete[] eapSucksString;
}
char* hack = hsWStringToString(title.c_str());
fProgress->SetTitle(hack);
delete[] hack;
fProgress->SetTitle(title.c_str());
}
}

3
Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.h

@ -43,7 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plAudioSystem_h
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <string>
#include "hsTemplates.h"
#include "hsGeometry3.h"
#include "pnKeyedObject/hsKeyedObject.h"

2
Sources/Plasma/PubUtilLib/plAudio/plDSoundBuffer.h

@ -50,7 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef _plDSoundBuffer_h
#define _plDSoundBuffer_h
#include "hsStlUtils.h"
#include <list>
#include "hsTemplates.h"
#include "plEAXEffects.h"
#define STREAMING_BUFFERS 16

2
Sources/Plasma/PubUtilLib/plAudioCore/plWavFile.h

@ -48,7 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <vector>
#include "hsWindows.h" // FIXME
#include <mmsystem.h>
#include "plAudioFileReader.h"

3
Sources/Plasma/PubUtilLib/plAvatar/plAGAnim.h

@ -50,9 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*/
#pragma warning(disable: 4786) // don't care if mangled names are longer than 255 characters
#include <map>
#include "pnNetCommon/plSynchedObject.h"
#include "hsStlUtils.h"
#include "hsStlSortUtils.h"
class plTMController;
class hsAffineParts;

5
Sources/Plasma/PubUtilLib/plAvatar/plAGAnimInstance.h

@ -53,9 +53,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// disable warning C4786: symbol greater than 255 characters,
#pragma warning(disable: 4503 4786)
// templates
#include "hsStlUtils.h"
#include "hsStlSortUtils.h"
#include "HeadSpin.h"
#include <map>
// local
#include "plScalarChannel.h"

4
Sources/Plasma/PubUtilLib/plAvatar/plAGMasterMod.h

@ -58,10 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAvDefs.h"
#include "pnKeyedObject/plMsgForwarder.h"
// templates
#include "hsStlUtils.h"
#include "hsStlSortUtils.h"
class plAGModifier;
class plAGAnimInstance;

4
Sources/Plasma/PubUtilLib/plAvatar/plAGModifier.h

@ -53,10 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// local
#include "plAvatar/plScalarChannel.h"
// stl
#include "hsStlUtils.h"
#include "hsStlSortUtils.h"
class plSceneObject;
class plAGAnimInstance;

2
Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.cpp

@ -54,11 +54,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// global
#include "hsStlUtils.h"
#include "hsResMgr.h"
#include "hsTimer.h"
#include <cstdio>
#include <cmath>
// other
#include "pnSceneObject/plSceneObject.h"

2
Sources/Plasma/PubUtilLib/plAvatar/plAnimStage.h

@ -47,8 +47,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef PL_ANIM_STAGE_INC
#define PL_ANIM_STAGE_INC
#include <vector>
#include "hsMatrix44.h"
#include "hsStlUtils.h"
#include "pnFactory/plCreatable.h"
class plMessage;

2
Sources/Plasma/PubUtilLib/plAvatar/plAvBehaviors.cpp

@ -39,6 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include <cmath>
#include "plAvBehaviors.h"
#include "plAvBrainHuman.h"
#include "plArmatureMod.h"

1
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCoop.h

@ -42,7 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef PLAVBRAINGENERIC_H
#define PLAVBRAINGENERIC_H
#include "hsStlUtils.h"
#include "plAvBrainGeneric.h"
/** \class plAvBrainCoop

1
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainCritter.h

@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef PL_AV_BRAIN_CRITTER_H
#define PL_AV_BRAIN_CRITTER_H
#include <map>
#include "plAvBrain.h"
#include "hsTemplates.h"
#include "pnKeyedObject/plKey.h"

1
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainHuman.cpp

@ -41,6 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include <cmath>
#include "plPhysicalControllerCore.h"
#include "plAvBrainHuman.h"

2
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainSwim.cpp

@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
/////////////////////////////////////////////////////////////////////////////////////////
#include <cmath>
// singular
#include "plAvBrainSwim.h"

1
Sources/Plasma/PubUtilLib/plAvatar/plAvLadderModifier.cpp

@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plPhysicalControllerCore.h"
#include "HeadSpin.h"
#include <cmath>
// singular
#include "plAvLadderModifier.h"

2
Sources/Plasma/PubUtilLib/plAvatar/plAvTaskSeek.cpp

@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//
/////////////////////////////////////////////////////////////////////////////////////////
#include <cmath>
// singular
#include "plAvTaskSeek.h"

5
Sources/Plasma/PubUtilLib/plAvatar/plAvatarMgr.h

@ -45,8 +45,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef PLAVATARMGR_INC
#define PLAVATARMGR_INC
#include "hsStlUtils.h"
#include "hsStlSortUtils.h"
#include "HeadSpin.h"
#include <map>
#include "hsGeometry3.h"
#include "pnKeyedObject/hsKeyedObject.h"

1
Sources/Plasma/PubUtilLib/plAvatar/plAvatarSDLModifier.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plAvatarSDLModifier_inc
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "plModifier/plSDLModifier.h"

4
Sources/Plasma/PubUtilLib/plAvatar/plCritterCommands.h

@ -43,8 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef __PLCRITTERCMDS_H__
#define __PLCRITTERCMDS_H__
#include "hsStlUtils.h"
#include <vector>
#include <string>
typedef std::vector<std::string> VCharArray;

4
Sources/Plasma/PubUtilLib/plAvatar/plMatrixChannel.cpp

@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
//#include <hkmath/quaternion.h>
//#include <hkmath/quaternion.h>
#include <cmath>
// singular
#include "plMatrixChannel.h"
@ -1015,4 +1017,4 @@ void plIK2Applicator::IApply(const plAGModifier *mod, double time)
void plIK2Applicator::ISolve()
{
}
}

1
Sources/Plasma/PubUtilLib/plAvatar/plMultistageBehMod.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plMultistageBehMod_h_inc
#include "pnModifier/plSingleModifier.h"
#include "hsStlUtils.h"
class plAnimStageVec;

2
Sources/Plasma/PubUtilLib/plAvatar/plPhysicalControllerCore.cpp

@ -39,6 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include <cmath>
#include "plPhysicalControllerCore.h"
#include "plArmatureMod.h"

2
Sources/Plasma/PubUtilLib/plAvatar/plSwimRegion.cpp

@ -39,6 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include <cmath>
#include "hsGeometry3.h"
#include "hsResMgr.h"

2
Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h

@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plZlibStream_h_inc
#include "hsStream.h"
#include "hsStlUtils.h"
#include <string>
//
// This is for reading a .gz file from a buffer, and writing the uncompressed data to a file.

284
Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp

@ -42,15 +42,14 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plConfigInfo.h"
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include <fstream>
#include <algorithm>
#include <stdarg.h>
#include <sstream>
const std::string& plConfigInfo::GlobalSection()
const plString& plConfigInfo::GlobalSection()
{
static std::string section("global");
static plString section("global");
return section;
}
@ -74,32 +73,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 +108,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<std::string> sections;
std::vector<plString> sections;
while (section)
{
sections.push_back( section );
@ -124,114 +123,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<std::string> & sections )
bool plConfigInfo::HasKeyIn(const plString & key, const std::vector<plString> & sections )
{
for ( int i=0; i<sections.size(); i++ )
{
const char * section = sections[i].c_str();
if (HasSection(section))
if (HasSection(sections[i]))
{
if (fSections[section].HasKey(key))
if (fSections[sections[i]].HasKey(key))
return true;
}
}
return false;
}
bool plConfigInfo::KeyHasValue(const std::string & section, const std::string & key, const std::string & value)
bool plConfigInfo::KeyHasValue(const plString & section, const plString & key, const plString & 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, 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<std::string> & values, KAddValueMode mode)
bool plConfigInfo::AddValues(const plString & section, const plString & key, const std::vector<plString> & 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<std::string> plConfigInfo::GetSectionNames()
std::vector<plString> plConfigInfo::GetSectionNames()
{
std::vector<std::string> results;
std::vector<plString> 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<std::string> plConfigInfo::GetAllValues(const std::string & section, const std::string & key) const
std::vector<plString> 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<std::string> empty;
return empty;
return std::vector<plString>();
}
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 +230,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 +239,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 +248,16 @@ double plConfigInfo::GetValueAny(const std::string & key, double defval, bool *
return defval;
}
std::vector<std::string> plConfigInfo::GetAllValuesAny(const std::string & key) const
std::vector<plString> 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<std::string> empty;
return empty;
return std::vector<plString>();
}
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 +277,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<std::string> & sections ) const
plString plConfigInfo::GetValueIn(const plString & key, const plString & defval, bool * outFound, const std::vector<plString> & sections ) const
{
if (outFound) *outFound=false;
for ( int i=0; i<sections.size(); i++ )
{
if (HasSection(sections[i]))
{
plKeysAndValues & kv = fSections[sections[i].c_str()];
plKeysAndValues & kv = fSections[sections[i]];
if (kv.HasKey(key))
return kv.GetValue(key,defval,outFound);
}
@ -303,7 +292,7 @@ std::string plConfigInfo::GetValueIn(const std::string & key, const std::string
return defval;
}
int plConfigInfo::GetValueIn(const std::string & key, int defval, bool * outFound, const char * section1, ...) const
int plConfigInfo::GetValueIn(const plString & key, int defval, bool * outFound, const char * section1, ...) const
{
if (outFound) *outFound=false;
const char * section = section1;
@ -323,14 +312,14 @@ int plConfigInfo::GetValueIn(const std::string & key, int defval, bool * outFoun
return defval;
}
int plConfigInfo::GetValueIn(const std::string & key, int defval, bool * outFound, const std::vector<std::string> & sections ) const
int plConfigInfo::GetValueIn(const plString & key, int defval, bool * outFound, const std::vector<plString> & sections ) const
{
if (outFound) *outFound=false;
for ( int i=0; i<sections.size(); i++ )
{
if (HasSection(sections[i]))
{
plKeysAndValues & kv = fSections[sections[i].c_str()];
plKeysAndValues & kv = fSections[sections[i]];
if (kv.HasKey(key))
return kv.GetValue(key,defval,outFound);
}
@ -338,7 +327,7 @@ int plConfigInfo::GetValueIn(const std::string & key, int defval, bool * outFoun
return defval;
}
double plConfigInfo::GetValueIn(const std::string & key, double defval, bool * outFound, const char * section1, ...) const
double plConfigInfo::GetValueIn(const plString & key, double defval, bool * outFound, const char * section1, ...) const
{
if (outFound) *outFound=false;
const char * section = section1;
@ -358,14 +347,14 @@ double plConfigInfo::GetValueIn(const std::string & key, double defval, bool * o
return defval;
}
double plConfigInfo::GetValueIn(const std::string & key, double defval, bool * outFound, const std::vector<std::string> & sections ) const
double plConfigInfo::GetValueIn(const plString & key, double defval, bool * outFound, const std::vector<plString> & sections ) const
{
if (outFound) *outFound=false;
for ( int i=0; i<sections.size(); i++ )
{
if (HasSection(sections[i]))
{
plKeysAndValues & kv = fSections[sections[i].c_str()];
plKeysAndValues & kv = fSections[sections[i]];
if (kv.HasKey(key))
return kv.GetValue(key,defval,outFound);
}
@ -373,12 +362,12 @@ double plConfigInfo::GetValueIn(const std::string & key, double defval, bool * o
return defval;
}
std::vector<std::string> plConfigInfo::GetAllValuesIn(const std::string & key, const char * section1, ...)
std::vector<plString> plConfigInfo::GetAllValuesIn(const plString & key, const char * section1, ...)
{
const char * section = section1;
va_list sections;
va_start(sections,section1);
std::vector<std::string> result;
std::vector<plString> result;
while (section)
{
if (HasSection(section))
@ -386,7 +375,7 @@ std::vector<std::string> plConfigInfo::GetAllValuesIn(const std::string & key, c
plKeysAndValues & kv = fSections[section];
if (kv.HasKey(key))
{
std::vector<std::string> values = kv.GetAllValues(key);
std::vector<plString> values = kv.GetAllValues(key);
result.insert(result.end(),values.begin(),values.end());
}
}
@ -403,7 +392,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 +400,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 +421,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 && t<key.size()-1)
int t = key.Find('.');
if (t>0 && t<key.GetSize()-1)
{
fEffectiveSection.assign(key.substr(0,t));
key.assign(key.substr(t+1));
fEffectiveSection = key.Left(t);
key = key.Substr(t+1);
}
bool ret=ReadPair(key, value);
fEffectiveSection = fCurrSection;
if(ret && strcmp("LoadIni",key.c_str()) == 0)
if(ret && key.Compare("LoadIni") == 0)
{
ret = ReadSubSource( value.c_str() );
}
@ -496,15 +484,14 @@ bool plConfigSource::ReadString(const std::string & in)
return ret;
}
bool plConfigSource::ReadPair(std::string & key, std::string & value)
bool plConfigSource::ReadPair(plString & key, plString & value)
{
hsAssert(fConfigInfo, "plConfigSource::ProcessPair: fConfigInfo not set.");
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;
return fConfigInfo->AddValue(fEffectiveSection, key, value, fAddMode);
@ -542,7 +529,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 +547,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 +569,7 @@ bool plCmdLineConfigSource::ReadInto(plConfigInfo & configInfo, KAddValueMode mo
plEnvConfigSource::plEnvConfigSource(char ** envp, const char * mySection)
: fEnvp(envp)
, fMySection(mySection?mySection:"")
, fMySection(mySection)
{}
@ -617,7 +604,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 +747,34 @@ bool plIniStreamConfigSource::WriteOutOf(plConfigInfo & configInfo)
/////////////////////////////////////////////////
plIniSectionConfigSource::plIniSectionConfigSource(const char * iniFileName, std::vector<std::string> & sections)
plIniSectionConfigSource::plIniSectionConfigSource(const char * iniFileName, std::vector<plString> & sections)
: plIniConfigSource(iniFileName)
{
for (int i=0; i<sections.size(); i++)
fSections.push_back(sections[i].c_str());
fSections.push_back(sections[i]);
}
bool plIniSectionConfigSource::ReadPair(std::string & key, std::string & value)
bool plIniSectionConfigSource::ReadPair(plString & key, plString & value)
{
hsAssert(fConfigInfo, "plConfigSource::ProcessPair: fConfigInfo not set.");
// the current section must be in list of sections.
std::vector<xtl::istring>::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 +782,7 @@ bool plIniSectionConfigSource::ReadPair(std::string & key, std::string & value)
bool plIniSectionConfigSource::ReadSubSource( const char * name )
{
std::vector<std::string> sections;
for ( int i=0; i<fSections.size(); i++ )
sections.push_back( fSections[i].c_str() );
plIniSectionConfigSource src(name, sections);
plIniSectionConfigSource src(name, fSections);
return fConfigInfo->ReadFrom(&src);
}
@ -809,21 +794,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 +818,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 +928,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 +944,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 +1014,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 +1055,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<fItems.size() && p!=std::string::npos);
} while (i<fItems.size() && p>=0);
}
std::string plConfigAggregateValue::IGetValue() const
plString plConfigAggregateValue::IGetValue() const
{
std::string value;
plStringStream value;
for (int i=0; i<fItems.size(); i++)
{
value.append(fItems[i]->GetValue());
value.append(" ");
value << fItems[i]->GetValue();
value << ' ';
}
return xtl::trim(value);
return value.GetString().Trim();
}
void plConfigAggregateValue::AddItem(plConfigValueBase * item)
@ -1103,7 +1086,7 @@ void plConfigAggregateValue::AddItem(plConfigValueBase * item)
////////////////////////////////////////////////////////////////////
plWWWAuthenticateConfigSource::plWWWAuthenticateConfigSource(const std::string& auth)
plWWWAuthenticateConfigSource::plWWWAuthenticateConfigSource(const plString& auth)
: fAuth(auth)
{
fEffectiveSection = fCurrSection = "";
@ -1119,21 +1102,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

198
Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h

@ -43,13 +43,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plConfigInfo_h_inc
#include "plKeysAndValues.h"
#include "hsStlUtils.h"
#include <stdarg.h>
/////////////////////////////////////////////////
typedef std::vector<std::string> plStringList;
typedef std::vector<std::wstring> plWStringList;
typedef std::vector<plString> plStringList;
/////////////////////////////////////////////////
@ -61,10 +59,10 @@ public:
Keys;
typedef plKeysAndValues::Values
Values;
typedef std::map<xtl::istring, plKeysAndValues>
typedef std::map<plString, plKeysAndValues, plString::less_i>
Sections;
static const std::string& GlobalSection();
static const plString& GlobalSection();
private:
mutable Sections fSections;
@ -79,54 +77,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<std::string> & sections );
bool HasKeyIn(const plString & key, const char * section1, ... /*, nil*/);
bool HasKeyIn(const plString & key, const std::vector<plString> & 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<std::string> & 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<plString> & values, KAddValueMode mode=kAlwaysAdd);
// GET
plKeysAndValues GetSection(const std::string & section, bool & found);
std::vector<std::string> GetSectionNames();
plKeysAndValues GetSection(const plString & section, bool & found);
std::vector<plString> 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<std::string> 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<plString> 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<std::string> 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<plString> 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<std::string> & 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<std::string> & 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<std::string> & sections ) const;
std::vector<std::string> 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<plString> & 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<plString> & 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<plString> & sections ) const;
std::vector<plString> 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 +143,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<std::string>& 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<plString>& 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<std::string>& 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<plString>& 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<std::string> & 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<std::string> & 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<std::string> & 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<std::string> & 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<std::string> & 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<plString> & 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<plString> & 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<plString> & 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<plString> & 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<plString> & sections );
#endif
};
@ -180,14 +178,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 +207,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 +220,7 @@ public:
class plEnvConfigSource : public plConfigSource
{
char ** fEnvp;
std::string fMySection;
plString fMySection;
protected:
bool ReadInto(plConfigInfo & configInfo, KAddValueMode mode=kAlwaysAdd);
public:
@ -235,7 +233,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 +260,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 +274,14 @@ public:
// an ini file reader that only reads specified sections
class plIniSectionConfigSource : public plIniConfigSource
{
typedef std::vector<xtl::istring>
typedef std::vector<plString>
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<std::string> & sections);
plIniSectionConfigSource(const char * iniFileName, std::vector<plString> & sections);
};
/////////////////////////////////////////////////
@ -304,7 +302,7 @@ public:
class plDebugConfigSource : public plConfigSource
{
protected:
std::string fFileName;
plString fFileName;
bool WriteOutOf(plConfigInfo & configInfo);
public:
plDebugConfigSource(){}
@ -314,11 +312,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 +361,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 +380,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 +392,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 +422,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 +449,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 +472,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 +482,7 @@ class plConfigGroup
{
public:
plConfigInfo fOpts;
std::string fGroupName;
plString fGroupName;
std::vector<plConfigValueBase*> fItems;
plConfigGroup(const char * groupName="");
bool Read(plConfigSource * src);

82
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<std::string>& values, const std::string & section, const std::string & key, const std::string & desc)
bool plConfigInfoLogging::GetAllValues(std::vector<plString>& 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<std::string>& 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<std::string>& values, const std::string & key, const std::string & desc)
bool plConfigInfoLogging::GetAllValuesAny(std::vector<plString>& values, const plString & key, const plString & desc)
{
fLog.AddValue("ANY SECTION",key,desc,kReplaceIfExists);
@ -170,12 +164,12 @@ bool plConfigInfoLogging::GetAllValuesAny(std::vector<std::string>& 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<std::string> sections;
std::vector<plString> 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<std::string> & sections )
bool plConfigInfoLogging::GetValueIn(plString& retval, const plString & key, const plString & desc, const plString & defval, std::vector<plString> & sections )
{
std::vector<std::string>::iterator si = sections.begin();
std::vector<plString>::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<std::string> sections;
std::vector<plString> 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<std::string> & sections )
bool plConfigInfoLogging::GetValueIn(int& retval, const plString & key, const plString & desc, int defval, std::vector<plString> & sections )
{
std::vector<std::string>::iterator si = sections.begin();
std::vector<plString>::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<std::string> sections;
std::vector<plString> 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<std::string> & sections )
bool plConfigInfoLogging::GetValueIn(bool& retval, const plString & key, const plString & desc, bool defval, std::vector<plString> & sections )
{
std::vector<std::string>::iterator si = sections.begin();
std::vector<plString>::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<std::string> sections;
std::vector<plString> 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<std::string> & sections )
bool plConfigInfoLogging::GetValueIn(float& retval, const plString & key, const plString & desc, double defval, std::vector<plString> & sections )
{
std::vector<std::string>::iterator si = sections.begin();
std::vector<plString>::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<std::string> sections;
std::vector<plString> 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<std::string> & sections )
bool plConfigInfoLogging::GetValueIn(double& retval, const plString & key, const plString & desc, double defval, std::vector<plString> & sections )
{
std::vector<std::string>::iterator si = sections.begin();
std::vector<plString>::iterator si = sections.begin();
while (si != sections.end())
{
fLog.AddValue(*si,key,desc,kReplaceIfExists);

1
Sources/Plasma/PubUtilLib/plContainer/plContainer.h

@ -43,7 +43,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plContainer_h_inc
#include "HeadSpin.h"
#include "hsStlUtils.h"
template < class T >
class plDataContainerT

132
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<std::string> & values, KAddValueMode mode)
bool plKeysAndValues::AddValues(const plString & key, const std::vector<plString> & values, KAddValueMode mode)
{
for (int i=0; i<values.size(); i++)
AddValue(key,values[i],mode);
return true;
}
bool plKeysAndValues::SetValue(const std::string & key, const std::string & value)
bool plKeysAndValues::SetValue(const plString & key, const plString & value)
{
fKeys[key.c_str()].clear();
fKeys[key].clear();
return AddValue(key,value);
}
bool plKeysAndValues::SetValue(const std::string & key, int value)
bool plKeysAndValues::SetValue(const plString & key, int value)
{
char buf[20];
sprintf(buf, "%d", value);
std::string v(buf);
return SetValue(key, v);
return SetValue(key, plString::Format("%d", value));
}
bool plKeysAndValues::SetValue(const std::string & key, double value)
bool plKeysAndValues::SetValue(const plString & key, double value)
{
char buf[30];
sprintf(buf, "%f", value);
std::string v(buf);
return SetValue(key, v);
return SetValue(key, plString::Format("%f", value));
}
std::string plKeysAndValues::GetValue(const std::string & key, const std::string & defval, bool * outFound) const
plString plKeysAndValues::GetValue(const plString & key, const plString & defval, bool * outFound) const
{
Keys::const_iterator ki = fKeys.find(key.c_str());
Keys::const_iterator ki = fKeys.find(key);
if (outFound)
*outFound = (ki!=fKeys.end());
if(ki != fKeys.end())
return ki->second.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<std::string> plKeysAndValues::GetAllValues(const std::string & key)
std::vector<plString> plKeysAndValues::GetAllValues(const plString & key)
{
std::vector<std::string> result;
xtl::istring xkey = key.c_str();
std::vector<plString> 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<char> key;
char* kdata = key.CreateWritableBuffer(strlen);
s->Read(strlen,(void*)kdata);
kdata[strlen] = 0;
uint16_t nvalues;
s->ReadLE(&nvalues);
for (int vi=0; vi<nvalues; vi++)
{
s->ReadLE(&strlen);
std::string value;
value.assign(strlen+1,'\0');
s->Read(strlen,(void*)value.data());
value.resize(strlen);
plStringBuffer<char> 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());
}
}
}

43
Sources/Plasma/PubUtilLib/plContainer/plKeysAndValues.h

@ -43,8 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define plKeysAndValues_h_inc
#include "HeadSpin.h"
#include <map>
#include <list>
#include "hsStlUtils.h"
#include "hsStream.h"
#pragma warning(disable:4284)
@ -62,9 +63,9 @@ enum KAddValueMode
class plKeysAndValues : public hsStreamable
{
public:
typedef std::list<xtl::istring>
typedef std::list<plString>
Values;
typedef std::map<xtl::istring, Values>
typedef std::map<plString, Values, plString::less_i>
Keys;
private:
@ -79,31 +80,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<std::string> & 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<plString> & 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<std::string> 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<plString> 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);

2
Sources/Plasma/PubUtilLib/plDrawable/plDynaDecalMgr.h

@ -43,11 +43,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plDynaDecalMgr_inc
#define plDynaDecalMgr_inc
#include <map>
#include "pnNetCommon/plSynchedObject.h"
#include "hsTemplates.h"
#include "hsGeometry3.h"
#include "hsMatrix44.h"
#include "hsStlUtils.h"
class plParticleSystem;

2
Sources/Plasma/PubUtilLib/plFile/hsFiles_Unix.cpp

@ -50,9 +50,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <sys/types.h>
#include <unistd.h>
#include <glob.h>
#include <string>
#include "hsTemplates.h"
#include "plFileUtils.h"
#include "hsStlUtils.h"
struct hsFolderIterator_Data {
glob_t fGlobBuf;

1
Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp

@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsSTLStream.h"
#include <time.h>
#include <wchar.h>
static const uint32_t kDefaultKey[4] = { 0x6c0a5452, 0x3827d0f, 0x3a170b92, 0x16db7fc2 };
static const int kEncryptChunkSize = 8;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save