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

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
Loading
Loading
Loading
Loading
+32 −0
Original line number Original line Diff line number Diff line
@@ -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:
    //-----</OUTPUTFORMATTER>-----------------------------------------------
    //-----</OUTPUTFORMATTER>-----------------------------------------------
};
};



#endif // RICHIO_H_
#endif // RICHIO_H_
+17 −14
Original line number Original line Diff line number Diff line
@@ -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


    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