KiCad PCB EDA Suite
Loading...
Searching...
No Matches
TEST_LIB_TABLE Class Reference

A concrete implementation of LIB_TABLE that implements the minimum interface for testing. More...

Inheritance diagram for TEST_LIB_TABLE:
LIB_TABLE PROJECT::_ELEM

Public Member Functions

 TEST_LIB_TABLE (LIB_TABLE *aFallback=nullptr)
 
KICAD_T Type () override
 
void Clear ()
 Delete all rows.
 
bool operator== (const LIB_TABLE &r) const
 Compares this table against another.
 
bool operator!= (const LIB_TABLE &r) const
 
unsigned GetCount () const
 Get the number of rows contained in the table.
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object.
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object.
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty.
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname, bool aCheckEnabled=false) const
 Test for the existence of aNickname in the library table.
 
bool HasLibraryWithPath (const wxString &aPath) const
 Test for the existence of aPath in the library table.
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname.
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true.
 
bool RemoveRow (const LIB_TABLE_ROW *aRow)
 Removes a row from the table and frees the pointer.
 
bool ReplaceRow (size_t aIndex, LIB_TABLE_ROW *aRow)
 Replaces the Nth row with the given new row.
 
bool ChangeRowOrder (size_t aIndex, int aOffset)
 Moves a row within the table.
 
void TransferRows (LIB_TABLE_ROWS &aRowsList)
 Takes ownership of another list of rows; the original list will be freed.
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable.
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form.
 
int GetVersion () const
 Returns the version number (0 if unset)
 

Static Public Member Functions

static STRING_UTF8_MAPParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
 
static UTF8 FormatOptions (const STRING_UTF8_MAP *aProperties)
 Returns a list of options from the aProperties parameter.
 

Protected Member Functions

LIB_TABLE_ROWfindRow (const wxString &aNickname, bool aCheckIfEnabled=false) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL.
 
bool migrate ()
 Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.
 
void reindex ()
 

Protected Attributes

LIB_TABLEm_fallBack
 
int m_version
 Versioning to handle importing old tables.
 
LIB_TABLE_ROWS m_rows
 Owning set of rows.
 
std::map< wxString, LIB_TABLE_ROWS_ITERm_rowsMap
 this is a non-owning index into the LIB_TABLE_ROWS table
 
std::shared_mutex m_mutex
 Mutex to protect access to the rows vector.
 

Private Member Functions

void Parse (LIB_TABLE_LEXER *aLexer) override
 Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects.
 
void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
 Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
 

Detailed Description

A concrete implementation of LIB_TABLE that implements the minimum interface for testing.

Notably, the Parse/Format functions are not used, as there is no "real" format to read/write.

Definition at line 79 of file test_lib_table.cpp.

Constructor & Destructor Documentation

◆ TEST_LIB_TABLE()

TEST_LIB_TABLE::TEST_LIB_TABLE ( LIB_TABLE aFallback = nullptr)
inline

Definition at line 82 of file test_lib_table.cpp.

Member Function Documentation

◆ At() [1/2]

LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex)
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 377 of file lib_table_base.h.

Referenced by FP_LIB_TABLE::LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SYMBOL_GRID_TRICKS::paste_text(), FP_GRID_TRICKS::paste_text(), and PCB::IFACE::SaveFileAs().

◆ At() [2/2]

const LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex) const
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 385 of file lib_table_base.h.

◆ ChangeRowOrder()

bool LIB_TABLE::ChangeRowOrder ( size_t  aIndex,
int  aOffset 
)
inherited

Moves a row within the table.

Parameters
aIndexis the current index of the row to move
aOffsetis the number of positions to move it by in the table
Returns
true if the move resulted in a change

Definition at line 383 of file lib_table_base.cpp.

References LIB_TABLE::m_mutex, LIB_TABLE::m_rows, and LIB_TABLE::reindex().

Referenced by PANEL_SYM_LIB_TABLE::moveDownHandler(), and PANEL_SYM_LIB_TABLE::moveUpHandler().

◆ Clear()

◆ findRow()

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname,
bool  aCheckIfEnabled = false 
) const
protectedinherited

Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL.

Parameters
aNicknameis the name of the library table entry to find.
aCheckIfEnabledis a flag to check if the library table entry is enabled.
Returns
a pointer to the LIB_TABLE_ROW found.

Definition at line 194 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetIsEnabled(), LIB_TABLE::m_fallBack, LIB_TABLE::m_mutex, and LIB_TABLE::m_rowsMap.

Referenced by SYMBOL_LIB_TABLE::FindRow(), FP_LIB_TABLE::FindRow(), LIB_TABLE::GetDescription(), LIB_TABLE::GetFullURI(), and LIB_TABLE::HasLibrary().

◆ FindRowByURI()

const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
inherited
Returns
a LIB_TABLE_ROW pointer if aURI is found in this table or in any chained fallBack table fragments, else NULL.

Definition at line 237 of file lib_table_base.cpp.

References LIB_TABLE::m_fallBack, and LIB_TABLE::m_rows.

Referenced by PCB_EDIT_FRAME::ExportFootprintsToLibrary(), SYMBOL_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), and DIALOG_SYMBOL_REMAP::remapSymbolToLibTable().

◆ Format()

void TEST_LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
inlineoverrideprivatevirtual

Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.

Parameters
aOutputis the OUTPUTFORMATTER to format the table into.
aIndentLevelis the indentation level (2 spaces) to indent.
Exceptions
IO_ERRORif an I/O error occurs during output.
boost::interprocess::lock_exceptif separate process attempt to access the table.

Implements LIB_TABLE.

Definition at line 99 of file test_lib_table.cpp.

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const STRING_UTF8_MAP aProperties)
staticinherited

Returns a list of options from the aProperties parameter.

The name=value pairs will be separated with the '|' character. The =value portion may not be present. You might expect something like "name1=value1|name2=value2|flag_me". Notice that flag_me does not have a value. This is ok.

Parameters
aPropertiesis the PROPERTIES to format or NULL. If NULL the returned string will be empty.

Definition at line 542 of file lib_table_base.cpp.

References UTF8::begin(), UTF8::end(), name, OPT_SEP, and UTF8::size().

Referenced by DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow().

◆ GetCount()

unsigned LIB_TABLE::GetCount ( ) const
inlineinherited

◆ GetDescription()

const wxString LIB_TABLE::GetDescription ( const wxString &  aNickname)
inherited
Returns
the library description from aNickname, or an empty string if aNickname does not exist.

Definition at line 146 of file lib_table_base.cpp.

References LIB_TABLE::findRow(), and LIB_TABLE_ROW::GetDescr().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), SAVE_AS_DIALOG::SAVE_AS_DIALOG(), and PCB_BASE_FRAME::SelectLibrary().

◆ GetFullURI()

wxString LIB_TABLE::GetFullURI ( const wxString &  aLibNickname,
bool  aExpandEnvVars = true 
) const
inherited

◆ GetLogicalLibs()

◆ GetVersion()

int LIB_TABLE::GetVersion ( ) const
inlineinherited

Returns the version number (0 if unset)

Returns
integer version number read from table

Definition at line 527 of file lib_table_base.h.

◆ HasLibrary()

◆ HasLibraryWithPath()

bool LIB_TABLE::HasLibraryWithPath ( const wxString &  aPath) const
inherited

Test for the existence of aPath in the library table.

Parameters
aCheckEnabledif true will only return true for enabled libraries
Returns
true if a library aNickname exists in the table.

Definition at line 169 of file lib_table_base.cpp.

References LIB_TABLE::m_rows.

Referenced by PCM_FP_LIB_TRAVERSER::OnDir(), and PCM_SYM_LIB_TRAVERSER::OnFile().

◆ InsertRow()

bool LIB_TABLE::InsertRow ( LIB_TABLE_ROW aRow,
bool  doReplace = false 
)
inherited

Adds aRow if it does not already exist or if doReplace is true.

If doReplace is not true and the key for aRow already exists, the function fails and returns false.

The key for the table is the nickName, and all in this table must be unique.

Parameters
aRowis the new row to insert, or to forcibly add if doReplace is true.
doReplaceif true, means insert regardless of whether aRow's key already exists. If false, then fail if the key already exists.
Returns
bool - true if the operation succeeded.

Definition at line 307 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetNickName(), LIB_TABLE::m_mutex, LIB_TABLE::m_rows, LIB_TABLE::m_rowsMap, LIB_TABLE::reindex(), and LIB_TABLE_ROW::SetParent().

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE(), SCH_IO_ALTIUM::LoadSchematicFile(), SCH_IO_CADSTAR_ARCHIVE::LoadSchematicFile(), SCH_IO_EAGLE::LoadSchematicFile(), SCH_IO_EASYEDAPRO::LoadSchematicFile(), SCH_EDIT_FRAME::LoadSheetFromFile(), PCM_FP_LIB_TRAVERSER::OnDir(), PCM_SYM_LIB_TRAVERSER::OnFile(), PCB_EDIT_FRAME::OpenProjectFiles(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

◆ IsEmpty()

bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)
inherited

Return true if the table is empty.

Parameters
aIncludeFallbackis used to determine if the fallback table should be included in the test.
Returns
true if the footprint library table is empty.

Definition at line 137 of file lib_table_base.cpp.

References LIB_TABLE::IsEmpty(), LIB_TABLE::m_fallBack, and LIB_TABLE::m_rows.

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE::IsEmpty(), and SCH_EDIT_FRAME::LoadSheetFromFile().

◆ Load()

void LIB_TABLE::Load ( const wxString &  aFileName)
inherited

Load the library table using the path defined by aFileName aFallBackTable.

Parameters
aFileNamecontains the full path to the s-expression file.
Exceptions
IO_ERRORif an error occurs attempting to load the footprint library table.

Definition at line 451 of file lib_table_base.cpp.

References LIB_TABLE::m_version, LIB_TABLE::migrate(), LIB_TABLE::Parse(), and LIB_TABLE::Save().

Referenced by FP_LIB_TABLE::LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SCH_EDIT_FRAME::LoadSheetFromFile(), PROJECT::PcbFootprintLibs(), PROJECT_PCB::PcbFootprintLibs(), PCB::IFACE::SaveFileAs(), PROJECT_SCH::SchSymbolLibTable(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and WriteDRCReport().

◆ migrate()

bool LIB_TABLE::migrate ( )
protectedinherited

Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.

Returns
True if the tables were modified

Definition at line 426 of file lib_table_base.cpp.

References LIB_TABLE::m_rows.

Referenced by LIB_TABLE::Load().

◆ operator!=()

bool LIB_TABLE::operator!= ( const LIB_TABLE r) const
inlineinherited

Definition at line 362 of file lib_table_base.h.

◆ operator==()

bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Compares this table against another.

This compares the row contents against each other. Any fallback tables are not checked.

Definition at line 346 of file lib_table_base.h.

References LIB_TABLE::m_rows.

◆ Parse()

void TEST_LIB_TABLE::Parse ( LIB_TABLE_LEXER *  aLexer)
inlineoverrideprivatevirtual

Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects.

Parameters
aLexeris the lexer to parse.
Exceptions
IO_ERRORif an I/O error occurs during parsing.
PARSER_ERRORif the lexer format to parse is invalid.
boost::bad_pointerif an any attempt to add an invalid pointer to the boost::ptr_vector.
boost::bad_indexif an index outside the row table bounds is accessed.

Implements LIB_TABLE.

Definition at line 93 of file test_lib_table.cpp.

◆ ParseOptions()

STRING_UTF8_MAP * LIB_TABLE::ParseOptions ( const std::string &  aOptionsList)
staticinherited

Parses aOptionsList and places the result into a #PROPERTIES object which is returned.

If the options field is empty, then the returned PROPERTIES will be a NULL pointer.

Typically aOptionsList comes from the "options" field within a LIB_TABLE_ROW and the format is simply a comma separated list of name value pairs. e.g.: [name1[=value1][|name2[=value2]]] etc. When using the UI to create or edit a library table, this formatting is handled for you.

Definition at line 477 of file lib_table_base.cpp.

References name, and OPT_SEP.

Referenced by PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), PANEL_FP_LIB_TABLE::onMigrateLibraries(), LIB_TABLE_ROW::SetOptions(), and DIALOG_PLUGIN_OPTIONS::TransferDataToWindow().

◆ reindex()

void LIB_TABLE::reindex ( )
protectedinherited

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( const LIB_TABLE_ROW aRow)
inherited

Removes a row from the table and frees the pointer.

Parameters
aRowis the row to remove
Returns
true if the row was found (and removed)

Definition at line 331 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetNickName(), LIB_TABLE::m_mutex, LIB_TABLE::m_rows, LIB_TABLE::m_rowsMap, and LIB_TABLE::reindex().

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), FP_LIB_TABLE::LoadGlobalTable(), and SYMBOL_LIB_TABLE::LoadGlobalTable().

◆ ReplaceRow()

bool LIB_TABLE::ReplaceRow ( size_t  aIndex,
LIB_TABLE_ROW aRow 
)
inherited

Replaces the Nth row with the given new row.

Returns
true if successful

Definition at line 368 of file lib_table_base.cpp.

References LIB_TABLE::m_mutex, LIB_TABLE::m_rows, LIB_TABLE::m_rowsMap, and LIB_TABLE::reindex().

Referenced by SYMBOL_GRID_TRICKS::paste_text().

◆ Save()

◆ TransferRows()

void LIB_TABLE::TransferRows ( LIB_TABLE_ROWS aRowsList)
inherited

Takes ownership of another list of rows; the original list will be freed.

Definition at line 404 of file lib_table_base.cpp.

References LIB_TABLE::m_mutex, LIB_TABLE::m_rows, and LIB_TABLE::reindex().

Referenced by PANEL_SYM_LIB_TABLE::TransferDataFromWindow(), and PANEL_FP_LIB_TABLE::TransferDataFromWindow().

◆ Type()

KICAD_T TEST_LIB_TABLE::Type ( )
inlineoverridevirtual

Implements PROJECT::_ELEM.

Definition at line 86 of file test_lib_table.cpp.

References FP_LIB_TABLE_T.

Member Data Documentation

◆ m_fallBack

LIB_TABLE* LIB_TABLE::m_fallBack
protectedinherited

◆ m_mutex

std::shared_mutex LIB_TABLE::m_mutex
mutableprotectedinherited

◆ m_rows

◆ m_rowsMap

std::map<wxString, LIB_TABLE_ROWS_ITER> LIB_TABLE::m_rowsMap
protectedinherited

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 565 of file lib_table_base.h.

Referenced by LIB_TABLE::Clear(), LIB_TABLE::findRow(), LIB_TABLE::InsertRow(), LIB_TABLE::reindex(), LIB_TABLE::RemoveRow(), and LIB_TABLE::ReplaceRow().

◆ m_version

int LIB_TABLE::m_version
mutableprotectedinherited

Versioning to handle importing old tables.

Definition at line 557 of file lib_table_base.h.

Referenced by SYMBOL_LIB_TABLE::Format(), FP_LIB_TABLE::Format(), LIB_TABLE::Load(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and LIB_TABLE::Save().


The documentation for this class was generated from the following file: