stlini.h

00001 #ifndef _STLINI_H
00002 #define _STLINI_H 1
00003 
00004 // These pragmas are to quiet VC++ about the expanded template identifiers exceeding 255 chars.
00005 // You won't be able to see those variables in a debug session, but the code will run normally
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 // change this if you expect to have huge lines in your INI files...
00016 // note that this is the max size of a single line, NOT the max number of lines
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 // return true or false depending on whether the first string is less than the second
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 // these typedefs just make the code a bit more readable
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

Generated on Thu Jun 22 14:47:20 2006 for ncut.kdevelop by  doxygen 1.4.6