26#ifndef _LIB_TABLE_BASE_H_
27#define _LIB_TABLE_BASE_H_
30#include <boost/noncopyable.hpp>
31#include <boost/ptr_container/ptr_vector.hpp>
34#include <shared_mutex>
80 LIB_TABLE_ROW(
const wxString& aNick,
const wxString& aURI,
const wxString& aOptions,
81 const wxString& aDescr = wxEmptyString,
LIB_TABLE* aParent =
nullptr ) :
141 virtual void SetType(
const wxString& aType ) = 0;
149 const wxString
GetFullURI(
bool aSubstituted =
false )
const;
304 virtual void Parse( LIB_TABLE_LEXER* aLexer ) = 0;
397 bool IsEmpty(
bool aIncludeFallback =
true );
411 bool HasLibrary(
const wxString& aNickname,
bool aCheckEnabled =
false )
const;
430 wxString
GetFullURI(
const wxString& aLibNickname,
bool aExpandEnvVars =
true )
const;
453 for(
auto iter =
m_rows.begin(); iter !=
m_rows.end(); ++iter )
457 m_rows.erase( iter, iter + 1 );
479 void Load(
const wxString& aFileName );
486 void Save(
const wxString& aFileName )
const;
582 typedef std::map<wxString,int>
INDEX;
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
A logical library item identifier and consists of various portions much like a URI.
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
bool visible
Whether the LIB_TABLE_ROW is visible in choosers.
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
const wxString & GetDescr() const
Return the description of the library referenced by this row.
virtual LIB_TABLE_ROW * do_clone() const =0
std::unique_ptr< STRING_UTF8_MAP > properties
void SetVisible(bool aVisible=true)
void operator=(const LIB_TABLE_ROW &aRow)
void SetNickName(const wxString &aNickName)
Change the logical name of this library, useful for an editor.
wxString uri_user
what user entered from UI or loaded from disk
LIB_TABLE * GetParent() const
bool operator!=(const LIB_TABLE_ROW &r) const
virtual const wxString GetType() const =0
Return the type of library represented by this row.
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
void SetDescr(const wxString &aDescr)
Change the description of the library referenced by this row.
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Serialize this object as utf8 text to an OUTPUTFORMATTER, and tries to make it look good using multip...
bool enabled
Whether the LIB_TABLE_ROW is enabled.
void SetParent(LIB_TABLE *aParent)
bool m_loaded
Whether the LIB_TABLE_ROW is loaded.
void setProperties(STRING_UTF8_MAP *aProperties)
LIB_TABLE_ROW(const LIB_TABLE_ROW &aRow)
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
LIB_TABLE * m_parent
Pointer to the table this row lives in (maybe null)
virtual void SetType(const wxString &aType)=0
Change the type of library represented by this row that must be implemented in the derived object to ...
const wxString & GetNickName() const
LIB_TABLE_ROW(const wxString &aNick, const wxString &aURI, const wxString &aOptions, const wxString &aDescr=wxEmptyString, LIB_TABLE *aParent=nullptr)
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_TABLE_ROW * clone() const
bool operator==(const LIB_TABLE_ROW &r) const
bool GetIsEnabled() const
void SetOptions(const wxString &aOptions)
Change the library options strings.
const STRING_UTF8_MAP * GetProperties() const
Return the constant #PROPERTIES for this library (LIB_TABLE_ROW).
bool GetIsVisible() const
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
const wxString GetDescription(const wxString &aNickname)
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
int m_version
Versioning to handle importing old tables.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
bool operator==(const LIB_TABLE &r) const
Compares this table against another.
bool migrate()
Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
bool HasLibraryWithPath(const wxString &aPath) const
Test for the existence of aPath in the library table.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table.
void Clear()
Delete all rows.
INDEX m_nickIndex
this particular key is the nickName within each row.
INDEX::value_type INDEX_VALUE
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
LIB_TABLE(LIB_TABLE *aFallBackTable=nullptr)
Build a library table by pre-pending this table fragment in front of aFallBackTable.
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.
unsigned GetCount() const
Get the number of rows contained in the table.
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
std::map< wxString, int > INDEX
this is a non-owning index into the LIB_TABLE_ROWS table
INDEX::const_iterator INDEX_CITER
const LIB_TABLE_ROW * FindRowByURI(const wxString &aURI)
void reindex(bool aForce)
Rebuilds the m_nickIndex.
std::shared_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
bool operator!=(const LIB_TABLE &r) const
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
static STRING_UTF8_MAP * ParseOptions(const std::string &aOptionsList)
Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
const LIB_TABLE_ROW & At(unsigned aIndex) const
Get the 'n'th LIB_TABLE_ROW object.
LIB_TABLE_ROW * findRow(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,...
INDEX::iterator INDEX_ITER
int GetVersion() const
Returns the version number (0 if unset)
static UTF8 FormatOptions(const STRING_UTF8_MAP *aProperties)
Returns a list of options from the aProperties parameter.
Dialog to show and edit symbol library tables.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
A name/value tuple with unique names and optional values.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
boost::ptr_vector< LIB_TABLE_ROW > LIB_TABLE_ROWS
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
LIB_TABLE_ROW * new_clone(const LIB_TABLE_ROW &aRow)
Allows boost pointer containers to make clones of the data stored in them.
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER