Add versioning to lib tables
Sets lib table version to allow easier migration between versions
This commit is contained in:
parent
70a57505de
commit
442ee52905
|
@ -99,8 +99,19 @@ void FP_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
|
|||
|
||||
// in case there is a "row integrity" error, tell where later.
|
||||
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 );
|
||||
|
||||
// (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
|
||||
{
|
||||
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 )
|
||||
it->Format( aOutput, aIndentLevel+1 );
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
fp_lib_table
|
||||
sym_lib_table
|
||||
version
|
||||
lib
|
||||
name
|
||||
type
|
||||
|
|
|
@ -114,7 +114,7 @@ void LIB_TABLE_ROW::SetOptions( const wxString& aOptions )
|
|||
|
||||
|
||||
LIB_TABLE::LIB_TABLE( LIB_TABLE* aFallBackTable ) :
|
||||
m_fallBack( aFallBackTable )
|
||||
m_fallBack( aFallBackTable ), m_version( 0 )
|
||||
{
|
||||
// not copying fall back, simply search aFallBackTable separately
|
||||
// if "nickName not found".
|
||||
|
@ -361,7 +361,7 @@ void LIB_TABLE::Load( const wxString& aFileName )
|
|||
|
||||
Parse( &lexer );
|
||||
|
||||
if( migrate() && wxFileName::IsFileWritable( aFileName ) )
|
||||
if( m_version != 7 && migrate() && wxFileName::IsFileWritable( aFileName ) )
|
||||
Save( aFileName );
|
||||
}
|
||||
}
|
||||
|
@ -370,6 +370,9 @@ void LIB_TABLE::Load( const wxString& aFileName )
|
|||
void LIB_TABLE::Save( const wxString& aFileName ) const
|
||||
{
|
||||
FILE_OUTPUTFORMATTER sf( aFileName );
|
||||
|
||||
// Force the lib table version to 7 before saving
|
||||
m_version = 7;
|
||||
Format( &sf, 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -141,8 +141,19 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
|
|||
|
||||
// in case there is a "row integrity" error, tell where later.
|
||||
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 );
|
||||
|
||||
// (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
|
||||
{
|
||||
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 )
|
||||
{
|
||||
|
|
|
@ -510,6 +510,16 @@ public:
|
|||
*/
|
||||
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:
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/// Versioning to handle importing old tables
|
||||
mutable int m_version;
|
||||
|
||||
/// Mutex to protect access to the nickIndex variable
|
||||
mutable std::mutex m_nickIndexMutex;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue