From 248788f381157406c4b4d189d7cf5900f5333af0 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 4 Oct 2013 23:53:15 -0500 Subject: [PATCH] Put FP_LIB_TABLE::Footprint*() functions on stage, but comment out lazy plugin lookup trick in FindRow() until these new API functions are used. --- common/fp_lib_table.cpp | 64 ++++++++++++++++++++++++++++++----------- include/fp_lib_table.h | 50 ++++++++++++++++++-------------- pcbnew/io_mgr.h | 22 ++++++++++++-- 3 files changed, 96 insertions(+), 40 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 0666004c1f..e5a12a78ad 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -59,6 +59,46 @@ FP_LIB_TABLE::FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable ) : } +wxArrayString FP_LIB_TABLE::FootprintEnumerate( const wxString& aNickname ) +{ + const ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + return row->plugin->FootprintEnumerate( row->GetFullURI( true ), row->GetProperties() ); +} + + +MODULE* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString& aFootprintName ) +{ + const ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + return row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName, row->GetProperties() ); +} + + +void FP_LIB_TABLE::FootprintSave( const wxString& aNickname, const MODULE* aFootprint ) +{ + const ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + return row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() ); +} + + +void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& aFootprintName ) +{ + const ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName, row->GetProperties() ); +} + + +bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname ) +{ + const ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) ); +} + + void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR ) { /* @@ -335,9 +375,9 @@ std::vector FP_LIB_TABLE::GetLogicalLibs() } -const FP_LIB_TABLE::ROW* FP_LIB_TABLE::findRow( const wxString& aNickName ) +FP_LIB_TABLE::ROW* FP_LIB_TABLE::findRow( const wxString& aNickName ) const { - FP_LIB_TABLE* cur = this; + FP_LIB_TABLE* cur = (FP_LIB_TABLE*) this; do { @@ -412,7 +452,7 @@ bool FP_LIB_TABLE::InsertRow( const ROW& aRow, bool doReplace ) const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aLibraryNickName ) throw( IO_ERROR ) { - const ROW* row = findRow( aLibraryNickName ); + ROW* row = findRow( aLibraryNickName ); if( !row ) { @@ -421,23 +461,15 @@ const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aLibraryNickName THROW_IO_ERROR( msg ); } + /* enable this when FP_LIB_TABLE::Footprint*() functions are put into use. + if( !row->plugin ) + row->setPlugin( IO_MGR::PluginFind( row->type ) ); + */ + return row; } -PLUGIN* FP_LIB_TABLE::PluginFind( const wxString& aLibraryNickName ) - throw( IO_ERROR ) -{ - const ROW* row = FindRow( aLibraryNickName ); - - // row will never be NULL here. - - PLUGIN* plugin = IO_MGR::PluginFind( row->type ); - - return plugin; -} - - const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString aString ) { // We reserve the right to do this another way, by providing our own member diff --git a/include/fp_lib_table.h b/include/fp_lib_table.h index 05d0cf3764..f52e62bcfa 100644 --- a/include/fp_lib_table.h +++ b/include/fp_lib_table.h @@ -147,6 +147,8 @@ public: description = r.description; properties = r.properties ? new PROPERTIES( *r.properties ) : NULL; + setPlugin( NULL ); // do not copy the PLUGIN, it is lazily created. + return *this; } @@ -186,8 +188,16 @@ public: /** * Function GetFullURI * returns the full location specifying URI for the LIB. + * + * @param doEnvVarSubs tells this function to do the substitution, else not. */ - const wxString& GetFullURI() const { return uri; } + const wxString GetFullURI( bool doEnvVarSubs = false ) const + { + if( doEnvVarSubs ) + return FP_LIB_TABLE::ExpandSubstitutions( uri ); + else + return uri; + } /** * Function SetFullURI @@ -258,13 +268,19 @@ public: properties = aProperties; } + void setPlugin( PLUGIN* aPlugin ) + { + plugin.set( aPlugin ); + } + wxString nickName; wxString uri; LIB_T type; wxString options; wxString description; - const - PROPERTIES* properties; + + const PROPERTIES* properties; + PLUGIN::RELEASER plugin; }; /** @@ -362,11 +378,7 @@ public: */ std::vector GetLogicalLibs(); - //-------------------------------------------------------- - // the returning of a const wxString* tells if not found, but might be too - // promiscuous? - -#if 0 // PLUGIN API SUBSET, REBASED ON aNickname + //-------------------------------- /** * Function FootprintEnumerate @@ -381,7 +393,7 @@ public: * * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded. */ - wxArrayString FootprintEnumerate( const wxString& aNickname ) const; + wxArrayString FootprintEnumerate( const wxString& aNickname ); /** * Function FootprintLoad @@ -397,7 +409,7 @@ public: * @throw IO_ERROR if the library cannot be found or read. No exception * is thrown in the case where aFootprintName cannot be found. */ - MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName ) const; + MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName ); /** * Function FootprintSave @@ -436,8 +448,8 @@ public: */ bool IsFootprintLibWritable( const wxString& aNickname ); -#endif - //------------------------------------------------------- + //-------------------------------- + /** * Function InsertRow @@ -451,17 +463,13 @@ public: */ bool InsertRow( const ROW& aRow, bool doReplace = false ); - /** - * Function PluginFind - * returns a PLUGIN*. Caller should wrap that in a PLUGIN::RELEASER() - * so when it goes out of scope, IO_MGR::PluginRelease() is called. - */ - PLUGIN* PluginFind( const wxString& aLibraryNickName ) throw( IO_ERROR ); - /** * Function FindRow * returns a ROW if aNickName is found in this table or in any chained - * fallBack table fragment, else NULL. + * fallBack table fragment. The PLUGIN is loaded and attached + * to the "plugin" field of the ROW if not already loaded. + * + * @throw IO_ERROR if aNickName cannot be found. */ const ROW* FindRow( const wxString& aNickName ) throw( IO_ERROR ); @@ -564,7 +572,7 @@ protected: * returns a ROW if aNickName is found in this table or in any chained * fallBack table fragment, else NULL. */ - const ROW* findRow( const wxString& aNickName ); + ROW* findRow( const wxString& aNickName ) const; void reindex() { diff --git a/pcbnew/io_mgr.h b/pcbnew/io_mgr.h index 6e70e668da..80c89c304b 100644 --- a/pcbnew/io_mgr.h +++ b/pcbnew/io_mgr.h @@ -416,6 +416,9 @@ public: { PLUGIN* plugin; + // private assignment operator so it's illegal + RELEASER& operator=( RELEASER& aOther ) { return *this; } + public: RELEASER( PLUGIN* aPlugin = NULL ) : plugin( aPlugin ) @@ -425,15 +428,28 @@ public: ~RELEASER() { if( plugin ) - IO_MGR::PluginRelease( plugin ); + release(); } - operator PLUGIN* () + void release() + { + IO_MGR::PluginRelease( plugin ); + plugin = NULL; + } + + void set( PLUGIN* aPlugin ) + { + if( plugin ) + release(); + plugin = aPlugin; + } + + operator PLUGIN* () const { return plugin; } - PLUGIN* operator -> () + PLUGIN* operator -> () const { return plugin; }