00001 #ifndef _STLINI_H
00002 #define _STLINI_H 1
00003
00004
00005
00006
00007
00008 #ifdef _MSC_VER // these pragmas are for MS VC++ only...
00009 #pragma warning(disable : 4786)
00010 #endif
00011
00012 #include <map>
00013 #include <string>
00014
00015
00016
00017 #define MAX_INI_LINE 500
00018
00019
00020 struct StlIniCompareStringNoCase
00021 {
00022 bool operator()(const std::string& x, const std::string& y) const;
00023 };
00024
00025
00026 inline bool StlIniCompareStringNoCase::operator()(const std::string& x, const std::string& y) const
00027 {
00028 #ifdef WIN32
00029 return (stricmp(x.c_str(), y.c_str()) < 0) ? true : false;
00030 #else
00031 #ifdef strcasecmp
00032 return (strcasecmp(x.c_str(), y.c_str()) < 0) ? true : false;
00033 #else
00034 unsigned nCount = 0;
00035 int nResult = 0;
00036 const char *p1 = x.c_str();
00037 const char *p2 = y.c_str();
00038
00039 while(*p1 && *p2)
00040 {
00041 nResult = toupper(*p1) - toupper(*p2);
00042 if(nResult != 0)
00043 break;
00044 p1++;
00045 p2++;
00046 nCount++;
00047 }
00048 if(nResult == 0)
00049 {
00050 if(*p1 && !*p2)
00051 nResult = -1;
00052 if(!*p1 && *p2)
00053 nResult = 1;
00054 }
00055 if(nResult < 0)
00056 return true;
00057 return false;
00058 #endif // strcasecmp
00059 #endif
00060 }
00061
00062
00063
00064 typedef std::map<std::string, std::string, StlIniCompareStringNoCase > INISection;
00065 typedef std::map<std::string, INISection , StlIniCompareStringNoCase > INIFile;
00066
00067 std::string GetIniSetting(INIFile &theINI, const char *pszSection, const char *pszKey, const char *pszDefaultVal="");
00068 void PutIniSetting(INIFile &theINI, const char *pszSection, const char *pszKey=NULL, const char *pszValue="");
00069 void RemoveIniSetting(INIFile &theINI, const char *pszSection, const char *pszKey);
00070 void SaveIni(INIFile &theINI, const char *pszFilename);
00071 INIFile LoadIni(const char *pszFilename);
00072
00073
00074 #endif // _STLINI_H