当前位置: 首页>>代码示例>>C++>>正文


C++ ConfigFile::addValue方法代码示例

本文整理汇总了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;
}
开发者ID:Klaim,项目名称:falcon,代码行数:48,代码来源:confparser_ext.cpp

示例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;
}
开发者ID:Klaim,项目名称:falcon,代码行数:95,代码来源:confparser_ext.cpp


注:本文中的ConfigFile::addValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。