Changeset 99bb030 in nscp for trunk/include/Settings.h
- Timestamp:
- 03/20/06 16:50:33 (7 years ago)
- Children:
- 8b89aba
- Parents:
- c3579b8
- File:
-
- 1 edited
-
trunk/include/Settings.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Settings.h
r9bc31a8 r99bb030 5 5 #include <map> 6 6 #include <windows.h> 7 #include <INISettings.h> 7 8 #define BUFF_LEN 4096 8 9 class Section {10 };11 9 12 10 class SettingsT 13 11 { 14 12 private: 15 typedef std::map<std::string,std::string> saveKeyList; 13 typedef struct { 14 typedef enum { sType, iType} typeEnum; 15 typeEnum type; 16 std::string sVal; 17 int iVal; 18 } valueStruct; 19 typedef std::map<std::string,valueStruct> saveKeyList; 16 20 typedef std::map<std::string,saveKeyList> saveSectionList; 17 std::string file_;18 21 saveSectionList data_; 19 22 bool bHasInternalData; 23 INISettings iniManager; 20 24 public: 21 25 typedef std::list<std::string> sectionList; … … 33 37 */ 34 38 void setFile(std::string file) { 35 file_ = file;39 iniManager.setFile(file); 36 40 } 37 41 38 sectionList getSections() { 39 sectionList ret; 40 char* buffer = new char[BUFF_LEN+1]; 41 unsigned int count = ::GetPrivateProfileSectionNames(buffer, BUFF_LEN, file_.c_str()); 42 if (count == BUFF_LEN-2) 43 throw "Fuck..."; 44 unsigned int last = 0; 45 for (unsigned int i=0;i<count;i++) { 46 if (buffer[i] == '\0') { 47 std::string s = &buffer[last]; 48 ret.push_back(s); 49 last = i+1; 42 #define UNLIKELY_VALUE -1234 43 void read() { 44 sectionList sections = getSections(); 45 for (sectionList::const_iterator it=sections.begin();it!=sections.end();++it) { 46 sectionList section = getSection(*it); 47 for (sectionList::const_iterator it2=section.begin();it2!=section.end();++it2) { 48 int i = getInt((*it), (*it2), UNLIKELY_VALUE); 49 if (i == UNLIKELY_VALUE) { 50 getString((*it), (*it2)); 51 } 50 52 } 51 53 } 52 delete [] buffer; 54 } 55 56 sectionList getSections(unsigned int bufferLength = BUFF_LEN) { 57 sectionList ret; 58 ret = iniManager.getSections(); 53 59 if (bHasInternalData) { 54 for (saveSectionList::const_iterator it = data_.begin(); it != data_.end(); ++it) { 60 for (saveSectionList::const_iterator kit = data_.begin(); kit != data_.end(); ++kit) { 61 ret.push_back(kit->first); 55 62 } 56 63 } … … 65 72 * @return A list with all keys from the section 66 73 */ 67 sectionList getSection(std::string section ) {74 sectionList getSection(std::string section, unsigned int bufferLength = BUFF_LEN) { 68 75 sectionList ret; 69 char* buffer = new char[BUFF_LEN+1]; 70 unsigned int count = GetPrivateProfileSection(section.c_str(), buffer, BUFF_LEN, file_.c_str()); 71 if (count == BUFF_LEN-2) 72 throw "Fuck..."; 73 unsigned int last = 0; 74 for (unsigned int i=0;i<count;i++) { 75 if (buffer[i] == '\0') { 76 std::string s = &buffer[last]; 77 ret.push_back(s); 78 last = i+1; 79 } 80 } 81 delete [] buffer; 76 ret = iniManager.getSection(section); 82 77 if (bHasInternalData) { 83 78 saveSectionList::const_iterator it = data_.find(section); … … 105 100 saveKeyList::const_iterator kit = it->second.find(key); 106 101 if (kit != it->second.end()) { 107 return kit->second; 102 if (kit->second.type == valueStruct::sType) 103 return kit->second.sVal; 104 else 105 throw "whoops"; 108 106 } 109 107 } 110 108 } 111 char* buffer = new char[1024]; 112 GetPrivateProfileString(section.c_str(), key.c_str(), defaultValue.c_str(), buffer, 1023, file_.c_str()); 113 std::string ret = buffer; 114 delete [] buffer; 109 std::string ret = iniManager.getString(section, key, defaultValue); 115 110 return ret; 116 111 } … … 118 113 void setString(std::string section, std::string key, std::string value) { 119 114 bHasInternalData = true; 120 (data_[section])[key] = value; 115 (data_[section])[key].sVal = value; 116 (data_[section])[key].type = valueStruct::sType; 121 117 } 122 118 … … 129 125 */ 130 126 int getInt(std::string section, std::string key, int defaultValue = 0) { 131 return GetPrivateProfileInt(section.c_str(), key.c_str(), defaultValue, file_.c_str()); 127 return iniManager.getInt(section, key, defaultValue); 128 } 129 void setInt(std::string section, std::string key, int value) { 130 bHasInternalData = true; 131 (data_[section])[key].iVal = value; 132 (data_[section])[key].type = valueStruct::iType; 132 133 } 133 134 };
Note: See TracChangeset
for help on using the changeset viewer.








