Esempio n. 1
0
int IniFile::getValues(const string &section,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);

}
Esempio n. 2
0
void IniFile::DeleteKey(const string &section, 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;
            }
        }
    }
}
Esempio n. 3
0
bool IniFile::HasKey(const string &section, 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;
}
Esempio n. 4
0
int IniFile::getValue(const string &section, 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;
}
Esempio n. 5
0
int IniFile::setValue(const string &section, 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;
}
Esempio n. 6
0
int IniFile::setValue(const string &section,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;

}