本文整理汇总了C++中ConfigFile::addValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigFile::addValue方法的具体用法?C++ ConfigFile::addValue怎么用?C++ ConfigFile::addValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigFile
的用法示例。
在下文中一共展示了ConfigFile::addValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConfParser_add
/*#
@method add ConfParser
@brief Adds a key/value pairs to the INI file.
@param key The key to which add the given value.
@param value The value, or value array, to be added.
@optparam section If provided, the section where to add the entry
This function adds a key/value pair to the main section, or if section parameter
is given and not @b nil, to the specified section.
If the key is already present, a multiple value is set.
*/
FALCON_FUNC ConfParser_add( ::Falcon::VMachine *vm )
{
CoreObject *self = vm->self().asObject();
ConfigFile *cfile = (ConfigFile *) self->getUserData();
Item *i_key = vm->param(0);
Item *i_value = vm->param(1);
Item *i_section = vm->param(2); // actually, if valorized, key and value are param 1 and 2.
if ( i_key == 0 || ! i_key->isString() || i_value == 0 ||
( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
)
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "S, S" ) );
}
String *value;
bool delValue;
if( i_value->isString() )
{
delValue = false;
value = i_value->asString();
}
else {
value = new String;
delValue = true;
vm->itemToString( *value, i_value );
}
if( i_section == 0 || i_section->isNil() )
cfile->addValue( *i_key->asString(), *value );
else
cfile->addValue( *i_section->asString(), *i_key->asString(), *value );
if ( delValue )
delete value;
}
示例2: ConfParser_set
/*#
@method set ConfParser
@brief Sets the value of a certain key key.
@param key The key to which add the given value.
@param value The value, or value array, to be added.
@optparam section If provided, the section where to add the entry
Sets a key/value pair in the main section, or if section parameter is
given and not nil, in the specified section.
*/
FALCON_FUNC ConfParser_set( ::Falcon::VMachine *vm )
{
CoreObject *self = vm->self().asObject();
ConfigFile *cfile = (ConfigFile *) self->getUserData();
Item *i_key = vm->param(0);
Item *i_value = vm->param(1);
Item *i_section = vm->param(2); // actually, if valorized, key and value are param 1 and 2.
if ( i_key == 0 || ! i_key->isString() || i_value == 0 ||
( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
)
{
throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "S, S" ) );
}
if ( i_section != 0 && i_section->isNil() )
i_section = 0;
String *value;
bool delValue;
if( i_value->isArray() )
{
CoreArray *array = i_value->asArray();
bool first = true;
for ( uint32 i = 0; i < array->length(); i ++ )
{
Item &itm = array->at( i );
if( itm.isString() )
{
delValue = false;
value = itm.asString();
}
else {
value = new String;
delValue = true;
vm->itemToString( *value, &itm );
}
if ( first )
{
// setValue will remove every previous reference...
if( i_section == 0 )
cfile->setValue( *i_key->asString(), *value );
else
cfile->setValue( *i_section->asString(), *i_key->asString(), *value );
first = false;
}
else {
// ...then we can begin to add
if( i_section == 0 )
cfile->addValue( *i_key->asString(), *value );
else
cfile->addValue( *i_section->asString(), *i_key->asString(), *value );
}
if ( delValue )
delete value;
}
// we have no more business here
return;
}
else if( i_value->isString() )
{
delValue = false;
value = i_value->asString();
}
else {
value = new String;
delValue = true;
vm->itemToString( *value, i_value );
}
if( i_section == 0 )
cfile->setValue( *i_key->asString(), *value );
else
cfile->setValue( *i_section->asString(), *i_key->asString(), *value );
if ( delValue )
delete value;
}