int IniFile::getValues(const string §ion,const string &key, vector<string> &values,vector<string> &comments) { string value,comment; values.clear(); comments.clear(); IniSection * sect = getSection(section); if(sect != NULL){ for(IniSection::iterator it = sect->begin(); it != sect->end(); ++it){ if(it->key == key){ value = it->value; comment = it->comment; values.push_back(value); comments.push_back(comment); } } } return (values.size() ? RET_OK : RET_ERR); }
void IniFile::DeleteKey(const string §ion, const string &key) { IniSection *sect = getSection(section); if (sect != NULL) { for (IniSection::IniItem_it it = sect->begin(); it != sect->end(); ++it) { if (it->key == key) { sect->items.erase(it); break; } } } }
bool IniFile::HasKey(const string §ion, const string &key) { IniSection *sect = getSection(section); if (sect != NULL) { for (IniSection::IniItem_it it = sect->begin(); it != sect->end(); ++it) { if (it->key == key) { return true; } } } return false; }
int IniFile::getValue(const string §ion, const string &key, string *value, string *comment) { IniSection *sect = getSection(section); if (sect != NULL) { for (IniSection::IniItem_it it = sect->begin(); it != sect->end(); ++it) { if (it->key == key) { *value = it->value; *comment = it->comment; return RET_OK; } } } return RET_ERR; }
int IniFile::setValue(const string §ion, const string &key, const string &value, const string &comment /*=""*/) { IniSection *sect = getSection(section); string comt = comment; if (comt != "") { comt = commentHead + comt; } if (sect == NULL) { //如果段不存在,新建一个 sect = new IniSection(); if (sect == NULL) { fprintf(stderr, "no enough memory!\n"); exit(-1); } sect->name = section; if (sect->name == "") { // 确保空section在第一个 sections_vt.insert(sections_vt.begin(), sect); } else { sections_vt.push_back(sect); } } for (IniSection::IniItem_it it = sect->begin(); it != sect->end(); ++it) { if (it->key == key) { it->value = value; it->comment = comt; return RET_OK; } } // not found key IniItem item; item.key = key; item.value = value; item.comment = comt; sect->items.push_back(item); return RET_OK; }
int IniFile::setValue(const string §ion,const string &key, const string &value,const string &comment /*=""*/) { IniSection * sect = getSection(section); string comt = comment; if (comt != ""){ comt = flags_[0] +comt; } if(sect == NULL){ sect = new IniSection(); if(sect == NULL){ fprintf(stderr,"no enough memory!\n"); exit(-1); } sect->name = section; sections_[section] = sect; } for(IniSection::iterator it = sect->begin(); it != sect->end(); ++it){ if(it->key == key){ it->value = value; it->comment = comt; return RET_OK; } } //not found key IniItem item; item.key = key; item.value = value; item.comment = comt; sect->items.push_back(item); return RET_OK; }