Commit 9cd011ab authored by Dick Hollenbeck's avatar Dick Hollenbeck

add class FILE_OUTPUTFORMATTER and use it in PCB_IO, since it is about 8-10...

add class FILE_OUTPUTFORMATTER and use it in PCB_IO, since it is about 8-10 faster than STREAM_OUTPUTFORMATTER
parent ea4b3877
......@@ -582,6 +582,37 @@ protected:
};
/**
* Class FILE_OUTPUTFORMATTER
* may be used for text file output. It is about 8 times faster than
* STREAM_OUTPUTFORMATTER for file streams.
*/
class FILE_OUTPUTFORMATTER : public OUTPUTFORMATTER
{
FILE* m_fp; ///< takes ownership
public:
FILE_OUTPUTFORMATTER( FILE* fp ) :
m_fp( fp )
{
}
~FILE_OUTPUTFORMATTER()
{
if( m_fp )
fclose( m_fp );
}
protected:
//-----<OUTPUTFORMATTER>------------------------------------------------
void write( const char* aOutBuf, int aCount ) throw( IO_ERROR )
{
fwrite( aOutBuf, aCount, 1, m_fp );
}
//-----</OUTPUTFORMATTER>-----------------------------------------------
};
/**
* Class STREAM_OUTPUTFORMATTER
* implements OUTPUTFORMATTER to a wxWidgets wxOutputStream. The stream is
......@@ -613,4 +644,5 @@ protected:
//-----</OUTPUTFORMATTER>-----------------------------------------------
};
#endif // RICHIO_H_
......@@ -181,21 +181,24 @@ void FP_CACHE::Save()
// Allow file output stream to go out of scope to close the file stream before
// renaming the file.
{
wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ),
GetChars( tempFileName ) );
wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ),
GetChars( tempFileName ) );
wxFFileOutputStream os( tempFileName );
FILE* fp = wxFopen( tempFileName, wxT( "wt" ) );
if( !os.IsOk() )
{
THROW_IO_ERROR( wxString::Format( _( "cannot save footprint library file '%s'" ),
tempFileName.GetData() ) );
}
if( !fp )
{
wxString msg = wxString::Format(
_( "cannot save footprint library file '%s'" ),
tempFileName.GetData() );
THROW_IO_ERROR( msg );
}
STREAM_OUTPUTFORMATTER formatter( os );
FILE_OUTPUTFORMATTER formatter( fp ); // gets fp ownership
m_owner->SetOutputFormatter( &formatter );
m_owner->Format( (BOARD_ITEM*) it->second->GetModule() );
m_owner->SetOutputFormatter( &formatter );
m_owner->Format( (BOARD_ITEM*) it->second->GetModule() );
}
wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
......@@ -313,15 +316,15 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper
m_board = aBoard;
wxFileOutputStream fs( aFileName );
FILE* fp = wxFopen( aFileName, wxT( "wt" ) );
if( !fs.IsOk() )
if( !fp )
{
m_error.Printf( _( "cannot open file '%s'" ), aFileName.GetData() );
THROW_IO_ERROR( m_error );
}
STREAM_OUTPUTFORMATTER formatter( fs );
FILE_OUTPUTFORMATTER formatter( fp ); // gets ownership of fp
m_out = &formatter; // no ownership
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment