Add versioning to lib tables

Sets lib table version to allow easier migration between versions
This commit is contained in:
Seth Hillbrand 2023-01-23 09:42:27 -08:00
parent 70a57505de
commit 442ee52905
5 changed files with 45 additions and 4 deletions

View File

@ -99,8 +99,19 @@ void FP_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
// in case there is a "row integrity" error, tell where later. // in case there is a "row integrity" error, tell where later.
int lineNum = in->CurLineNumber(); int lineNum = in->CurLineNumber();
tok = in->NextTok();
if( ( tok = in->NextTok() ) != T_lib ) // Optionally parse the current version number
if( tok == T_version )
{
in->NeedNUMBER( "version" );
m_version = std::stoi( in->CurText() );
in->NeedRIGHT();
in->NeedLEFT();
tok = in->NextTok();
}
if( tok != T_lib )
in->Expecting( T_lib ); in->Expecting( T_lib );
// (name NICKNAME) // (name NICKNAME)
@ -236,6 +247,7 @@ bool FP_LIB_TABLE::operator==( const FP_LIB_TABLE& aFpTable ) const
void FP_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const void FP_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
{ {
aOutput->Print( aIndentLevel, "(fp_lib_table\n" ); aOutput->Print( aIndentLevel, "(fp_lib_table\n" );
aOutput->Print( aIndentLevel + 1, "(version %d)\n", m_version );
for( LIB_TABLE_ROWS_CITER it = m_rows.begin(); it != m_rows.end(); ++it ) for( LIB_TABLE_ROWS_CITER it = m_rows.begin(); it != m_rows.end(); ++it )
it->Format( aOutput, aIndentLevel+1 ); it->Format( aOutput, aIndentLevel+1 );

View File

@ -1,5 +1,6 @@
fp_lib_table fp_lib_table
sym_lib_table sym_lib_table
version
lib lib
name name
type type

View File

@ -114,7 +114,7 @@ void LIB_TABLE_ROW::SetOptions( const wxString& aOptions )
LIB_TABLE::LIB_TABLE( LIB_TABLE* aFallBackTable ) : LIB_TABLE::LIB_TABLE( LIB_TABLE* aFallBackTable ) :
m_fallBack( aFallBackTable ) m_fallBack( aFallBackTable ), m_version( 0 )
{ {
// not copying fall back, simply search aFallBackTable separately // not copying fall back, simply search aFallBackTable separately
// if "nickName not found". // if "nickName not found".
@ -361,7 +361,7 @@ void LIB_TABLE::Load( const wxString& aFileName )
Parse( &lexer ); Parse( &lexer );
if( migrate() && wxFileName::IsFileWritable( aFileName ) ) if( m_version != 7 && migrate() && wxFileName::IsFileWritable( aFileName ) )
Save( aFileName ); Save( aFileName );
} }
} }
@ -370,6 +370,9 @@ void LIB_TABLE::Load( const wxString& aFileName )
void LIB_TABLE::Save( const wxString& aFileName ) const void LIB_TABLE::Save( const wxString& aFileName ) const
{ {
FILE_OUTPUTFORMATTER sf( aFileName ); FILE_OUTPUTFORMATTER sf( aFileName );
// Force the lib table version to 7 before saving
m_version = 7;
Format( &sf, 0 ); Format( &sf, 0 );
} }

View File

@ -141,8 +141,19 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
// in case there is a "row integrity" error, tell where later. // in case there is a "row integrity" error, tell where later.
int lineNum = in->CurLineNumber(); int lineNum = in->CurLineNumber();
tok = in->NextTok();
if( ( tok = in->NextTok() ) != T_lib ) // Optionally parse the current version number
if( tok == T_version )
{
in->NeedNUMBER( "version" );
m_version = std::stoi( in->CurText() );
in->NeedRIGHT();
in->NeedLEFT();
tok = in->NextTok();
}
if( tok != T_lib )
in->Expecting( T_lib ); in->Expecting( T_lib );
// (name NICKNAME) // (name NICKNAME)
@ -269,6 +280,7 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
void SYMBOL_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const void SYMBOL_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
{ {
aOutput->Print( aIndentLevel, "(sym_lib_table\n" ); aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
aOutput->Print( aIndentLevel + 1, "(version %d)\n", m_version );
for( LIB_TABLE_ROWS_CITER it = m_rows.begin(); it != m_rows.end(); ++it ) for( LIB_TABLE_ROWS_CITER it = m_rows.begin(); it != m_rows.end(); ++it )
{ {

View File

@ -510,6 +510,16 @@ public:
*/ */
static UTF8 FormatOptions( const STRING_UTF8_MAP* aProperties ); static UTF8 FormatOptions( const STRING_UTF8_MAP* aProperties );
/**
* Returns the version number (0 if unset)
*
* @return integer version number read from table
*/
int GetVersion() const
{
return m_version;
}
protected: protected:
/** /**
* Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained * Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained
@ -566,6 +576,9 @@ protected:
LIB_TABLE* m_fallBack; LIB_TABLE* m_fallBack;
/// Versioning to handle importing old tables
mutable int m_version;
/// Mutex to protect access to the nickIndex variable /// Mutex to protect access to the nickIndex variable
mutable std::mutex m_nickIndexMutex; mutable std::mutex m_nickIndexMutex;
}; };