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: ...@@ -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 * Class STREAM_OUTPUTFORMATTER
* implements OUTPUTFORMATTER to a wxWidgets wxOutputStream. The stream is * implements OUTPUTFORMATTER to a wxWidgets wxOutputStream. The stream is
...@@ -613,4 +644,5 @@ protected: ...@@ -613,4 +644,5 @@ protected:
//-----</OUTPUTFORMATTER>----------------------------------------------- //-----</OUTPUTFORMATTER>-----------------------------------------------
}; };
#endif // RICHIO_H_ #endif // RICHIO_H_
...@@ -184,15 +184,18 @@ void FP_CACHE::Save() ...@@ -184,15 +184,18 @@ void FP_CACHE::Save()
wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ), wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ),
GetChars( tempFileName ) ); GetChars( tempFileName ) );
wxFFileOutputStream os( tempFileName ); FILE* fp = wxFopen( tempFileName, wxT( "wt" ) );
if( !os.IsOk() ) if( !fp )
{ {
THROW_IO_ERROR( wxString::Format( _( "cannot save footprint library file '%s'" ), wxString msg = wxString::Format(
tempFileName.GetData() ) ); _( "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->SetOutputFormatter( &formatter );
m_owner->Format( (BOARD_ITEM*) it->second->GetModule() ); m_owner->Format( (BOARD_ITEM*) it->second->GetModule() );
...@@ -313,15 +316,15 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper ...@@ -313,15 +316,15 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProper
m_board = aBoard; 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() ); m_error.Printf( _( "cannot open file '%s'" ), aFileName.GetData() );
THROW_IO_ERROR( m_error ); THROW_IO_ERROR( m_error );
} }
STREAM_OUTPUTFORMATTER formatter( fs ); FILE_OUTPUTFORMATTER formatter( fp ); // gets ownership of fp
m_out = &formatter; // no ownership 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