FALCON_FUNC ConfParser_read( ::Falcon::VMachine *vm ) { CoreObject *self = vm->self().asObject(); ConfigFile *cfile = (ConfigFile *) self->getUserData(); Item *i_stream = vm->param(0); bool bRes; if( i_stream == 0 ) { vm->idle(); bRes = cfile->load(); vm->unidle(); } else { bool bValid = false; if ( i_stream->isObject() ) { CoreObject *streamObj = i_stream->asObject(); if ( streamObj->derivedFrom( "Stream" ) ) { Stream *base = (Stream *) streamObj->getUserData(); bRes = cfile->load( base ); bValid = true; } } if ( ! bValid ) { throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "Stream" ) ); return; } } if ( ! bRes ) { // is this an I/O or a parsing error? if ( cfile->fsError() != 0 ) { throw new IoError( ErrorParam( e_loaderror, __LINE__ ). sysError( cfile->fsError() ). extra( cfile->errorMessage() ) ); } else { String msg = cfile->errorMessage() + " at "; msg.writeNumber( (int64) cfile->errorLine() ); self->setProperty( "error", cfile->errorMessage() ); self->setProperty( "errorLine", (int64) cfile->errorLine() ); throw new ParseError( ErrorParam( FALCP_ERR_INVFORMAT, __LINE__ ) .desc( FAL_STR(cp_msg_invformat) ) .extra( msg ) ); } } }
/*# @method write ConfParser @brief Write the INI file. @optparam stream An optional output stream on which to write the configuration file. @raise IoError on write error. Writes the content of a modified or entirely generated configuration file on the given stream, that must be a valid Falcon stream opened for output. If a stream is not given, then the file name provided to the ConfParser constructor is opened for writing. In case the name has not been given in the constructor, the method raises an error. */ FALCON_FUNC ConfParser_write( ::Falcon::VMachine *vm ) { CoreObject *self = vm->self().asObject(); ConfigFile *cfile = (ConfigFile *) self->getUserData(); Item *i_stream = vm->param(0); bool bRes; if( i_stream == 0 ) { bRes = cfile->save(); } else { bool bValid = false; if ( i_stream->isObject() ) { CoreObject *streamObj = i_stream->asObject(); if ( streamObj->derivedFrom( "Stream" ) ) { Stream *base = (Stream *) streamObj->getUserData(); bRes = cfile->save( base ); bValid = true; } } if ( ! bValid ) { throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "Stream" ) ); return; } } if ( ! bRes ) { // is this a file error? if ( cfile->fsError() ) { throw new IoError( ErrorParam( e_file_output, __LINE__ ). sysError( cfile->fsError() ). extra( cfile->errorMessage() ) ); } else { // no -- it's a configuration file.d self->setProperty( "error", cfile->errorMessage() ); self->setProperty( "errorLine", (int64) cfile->errorLine() ); throw new ParseError( ErrorParam( FALCP_ERR_STORE, __LINE__ ). desc( FAL_STR(cp_msg_errstore) ).extra( cfile->errorMessage() ) ); } } }