Put FP_LIB_TABLE::Footprint*() functions on stage, but comment out lazy plugin lookup trick in FindRow() until these new API functions are used.

This commit is contained in:
Dick Hollenbeck 2013-10-04 23:53:15 -05:00
parent d82c3b9ab1
commit 248788f381
3 changed files with 96 additions and 40 deletions

View File

@ -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 ) void FP_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw( IO_ERROR, PARSE_ERROR )
{ {
/* /*
@ -335,9 +375,9 @@ std::vector<wxString> 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 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 ) const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aLibraryNickName )
throw( IO_ERROR ) throw( IO_ERROR )
{ {
const ROW* row = findRow( aLibraryNickName ); ROW* row = findRow( aLibraryNickName );
if( !row ) if( !row )
{ {
@ -421,23 +461,15 @@ const FP_LIB_TABLE::ROW* FP_LIB_TABLE::FindRow( const wxString& aLibraryNickName
THROW_IO_ERROR( msg ); 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; 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 ) const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString aString )
{ {
// We reserve the right to do this another way, by providing our own member // We reserve the right to do this another way, by providing our own member

View File

@ -147,6 +147,8 @@ public:
description = r.description; description = r.description;
properties = r.properties ? new PROPERTIES( *r.properties ) : NULL; properties = r.properties ? new PROPERTIES( *r.properties ) : NULL;
setPlugin( NULL ); // do not copy the PLUGIN, it is lazily created.
return *this; return *this;
} }
@ -186,8 +188,16 @@ public:
/** /**
* Function GetFullURI * Function GetFullURI
* returns the full location specifying URI for the LIB. * 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 * Function SetFullURI
@ -258,13 +268,19 @@ public:
properties = aProperties; properties = aProperties;
} }
void setPlugin( PLUGIN* aPlugin )
{
plugin.set( aPlugin );
}
wxString nickName; wxString nickName;
wxString uri; wxString uri;
LIB_T type; LIB_T type;
wxString options; wxString options;
wxString description; wxString description;
const
PROPERTIES* properties; const PROPERTIES* properties;
PLUGIN::RELEASER plugin;
}; };
/** /**
@ -362,11 +378,7 @@ public:
*/ */
std::vector<wxString> GetLogicalLibs(); std::vector<wxString> GetLogicalLibs();
//----<read accessors>---------------------------------------------------- //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
// 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 * Function FootprintEnumerate
@ -381,7 +393,7 @@ public:
* *
* @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded. * @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 * Function FootprintLoad
@ -397,7 +409,7 @@ public:
* @throw IO_ERROR if the library cannot be found or read. No exception * @throw IO_ERROR if the library cannot be found or read. No exception
* is thrown in the case where aFootprintName cannot be found. * 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 * Function FootprintSave
@ -436,8 +448,8 @@ public:
*/ */
bool IsFootprintLibWritable( const wxString& aNickname ); bool IsFootprintLibWritable( const wxString& aNickname );
#endif //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
//----</read accessors>---------------------------------------------------
/** /**
* Function InsertRow * Function InsertRow
@ -451,17 +463,13 @@ public:
*/ */
bool InsertRow( const ROW& aRow, bool doReplace = false ); 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 * Function FindRow
* returns a ROW if aNickName is found in this table or in any chained * 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 ); 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 * returns a ROW if aNickName is found in this table or in any chained
* fallBack table fragment, else NULL. * fallBack table fragment, else NULL.
*/ */
const ROW* findRow( const wxString& aNickName ); ROW* findRow( const wxString& aNickName ) const;
void reindex() void reindex()
{ {

View File

@ -416,6 +416,9 @@ public:
{ {
PLUGIN* plugin; PLUGIN* plugin;
// private assignment operator so it's illegal
RELEASER& operator=( RELEASER& aOther ) { return *this; }
public: public:
RELEASER( PLUGIN* aPlugin = NULL ) : RELEASER( PLUGIN* aPlugin = NULL ) :
plugin( aPlugin ) plugin( aPlugin )
@ -425,15 +428,28 @@ public:
~RELEASER() ~RELEASER()
{ {
if( plugin ) 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; return plugin;
} }
PLUGIN* operator -> () PLUGIN* operator -> () const
{ {
return plugin; return plugin;
} }