本文整理汇总了C++中ConfigSection::add_entry方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigSection::add_entry方法的具体用法?C++ ConfigSection::add_entry怎么用?C++ ConfigSection::add_entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSection
的用法示例。
在下文中一共展示了ConfigSection::add_entry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set
void Config::set(const char* section, const char* key, double value) {
ConfigSection* sc = add_section(section);
char* locale = nls_locale_to_c();
char tmp[32];
snprintf(tmp, sizeof(tmp)-1, "%g", value);
nls_locale_from_c(locale);
sc->add_entry(key, tmp);
}
示例2: load
bool Config::load(const char* fname) {
E_ASSERT(fname != NULL);
clear();
FILE *f = fopen(fname, "r");
if (!f) {
errcode = CONF_ERR_FILE;
return false;
}
// set default return values
errcode = CONF_SUCCESS;
bool status = true;
// we must have at least one section
bool sect_found = false;
// use fixed sizes for sections and keys
char section[ESECT_MAX];
char keybuf[EKEY_MAX];
// line and value can grow
int buflen = ELINE_SIZE_START;
char* buf = new char[buflen];
// use the same size as for line
int valbuflen = buflen;
char* valbuf = new char[valbuflen];
char *bufp;
ConfigSection* tsect = NULL;
while(config_getline(&buf, &buflen, f) != -1) {
++linenum;
bufp = buf;
EAT_SPACES(bufp);
// comment or empty line
if (*bufp == COMMENT || *bufp == '\0')
continue;
// we found an section
if (*bufp == SECT_OPEN) {
sect_found = true;
bufp++;
if (!scan_section(bufp, section, sizeof(section))) {
errcode = CONF_ERR_BAD;
status = false;
break;
} else {
// first check if section exists, or create if not
tsect = find_section(section);
if (!tsect) {
++sectnum;
tsect = new ConfigSection(section);
section_list.push_back(tsect);
}
}
}
// data part
else {
// file without sections
if (!sect_found) {
errcode = CONF_ERR_SECTION;
status = false;
break;
}
/*
* check if size of valbuf is less than buflen;
* in that case make it size as buflen (better would be to use
* buflen - EKEY_MAX - '=' - <spaces>, but that would complicate thing,
* also more size does not hurts :P)
*/
if(valbuflen < buflen) {
valbuflen = buflen;
delete [] valbuf;
valbuf = new char[valbuflen];
}
if (!scan_keyvalues(bufp, keybuf, valbuf, buflen, EKEY_MAX, valbuflen)) {
errcode = CONF_ERR_BAD;
status = false;
break;
}
E_ASSERT(tsect != NULL && "Entry without a section ?!");
tsect->add_entry(keybuf, valbuf);
}
}
fclose(f);
delete [] buf;
delete [] valbuf;
return status;
}