KiCad PCB EDA Suite
LIB_TABLE Class Referenceabstract

Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname. More...

#include <lib_table_base.h>

Inheritance diagram for LIB_TABLE:
PROJECT::_ELEM FP_LIB_TABLE SYMBOL_LIB_TABLE FP_LIB_TABLE_GRID SYMBOL_LIB_TABLE_GRID

Public Member Functions

virtual void Parse (LIB_TABLE_LEXER *aLexer)=0
 Parse the LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects. More...
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
 Generate the table in s-expression format to aOutput with an indention level of aIndentLevel. More...
 
 LIB_TABLE (LIB_TABLE *aFallBackTable=NULL)
 Build a library table by pre-pending this table fragment in front of aFallBackTable. More...
 
virtual ~LIB_TABLE ()
 
void Clear ()
 Delete all rows. More...
 
bool operator== (const LIB_TABLE &r) const
 
bool operator!= (const LIB_TABLE &r) const
 
int GetCount ()
 
LIB_TABLE_ROWAt (int aIndex)
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty. More...
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname) const
 Test for the existence of aNickname in the library table. More...
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE. More...
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname. More...
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true. More...
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable. More...
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form. More...
 
size_t GetEnvVars (wxArrayString &aEnvVars) const
 Search the paths all of the LIB_TABLE_ROWS of the LIB_TABLE and add all of the environment variable substitutions to aEnvVars. More...
 

Static Public Member Functions

static PROPERTIESParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a PROPERTIES object which is returned. More...
 
static UTF8 FormatOptions (const PROPERTIES *aProperties)
 Returns a list of options from the aProperties parameter. More...
 
static const wxString ExpandSubstitutions (const wxString &aString)
 Replaces any environment variable references with their values and is here to fully embellish the TABLE_ROW::uri in a platform independent way. More...
 

Protected Types

typedef std::map< wxString, int > INDEX
 this is a non-owning index into the LIB_TABLE_ROWS table More...
 
typedef INDEX::iterator INDEX_ITER
 
typedef INDEX::const_iterator INDEX_CITER
 
typedef INDEX::value_type INDEX_VALUE
 

Protected Member Functions

LIB_TABLE_ROWfindRow (const wxString &aNickname) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL. More...
 
LIB_TABLE_ROWfindRow (const wxString &aNickname)
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

LIB_TABLE_ROWS rows
 
INDEX nickIndex
 this particular key is the nickName within each row. More...
 
LIB_TABLEfallBack
 

Friends

class DIALOG_FP_LIB_TABLE
 
class LIB_TABLE_GRID
 

Detailed Description

Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

This class owns the library table, which is like fstab in concept and maps logical library name to the library URI, type, and options. It is heavily based on the SWEET parser work done by Dick Hollenbeck and can be seen in new/sch_lib_table.h. A library table has the following columns:

  • Logical Library Name (Nickname)
  • Library Type, used to determine which plugin to load to access the library.
  • Library URI. The full URI to the library source, form dependent on Type.
  • Options, used for as yet to be defined information such as user names or passwords

The Library Type can be one of:

  • "file"
  • "ftp"
  • "http"

For now, the Library URI types needed to support the various types can be one of those shown below, which are typical of each type:

  • "file://C:/mylibdir"
  • "ftp://kicad.org/partlib/trunk"
  • "http://kicad.org/partlib"

The library table is built up from several additive entries (table fragments), and the final table is a (conceptual) merging of the table fragments. Two anticipated sources of the entries are a personal table saved in the KiCad configuration and a project resident table that resides in project file. The project footprint table entries are considered a higher priority in the final dynamically assembled library table. An row in the project file contribution to the library table takes precedence over the personal table if there is a collision of logical library names. Otherwise, the entries simply combine without issue to make up the applicable library table.

Author
Wayne Stambaugh

Definition at line 266 of file lib_table_base.h.

Member Typedef Documentation

typedef std::map<wxString,int> LIB_TABLE::INDEX
protected

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 488 of file lib_table_base.h.

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protected

Definition at line 490 of file lib_table_base.h.

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protected

Definition at line 489 of file lib_table_base.h.

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protected

Definition at line 491 of file lib_table_base.h.

Constructor & Destructor Documentation

LIB_TABLE::LIB_TABLE ( LIB_TABLE aFallBackTable = NULL)

Build a library table by pre-pending this table fragment in front of aFallBackTable.

Loading of this table fragment is done by using Parse().

Parameters
aFallBackTableis another LIB_TABLE which is searched only when a row is not found in this table. No ownership is taken of aFallBackTable.

Definition at line 228 of file lib_table_base.cpp.

228  :
229  fallBack( aFallBackTable )
230 {
231  // not copying fall back, simply search aFallBackTable separately
232  // if "nickName not found".
233 }
LIB_TABLE * fallBack
LIB_TABLE::~LIB_TABLE ( )
virtual

Definition at line 236 of file lib_table_base.cpp.

237 {
238  // *fallBack is not owned here.
239 }

Member Function Documentation

LIB_TABLE_ROW* LIB_TABLE::At ( int  aIndex)
inline

Definition at line 338 of file lib_table_base.h.

References rows.

Referenced by SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

338 { return &rows[aIndex]; }
LIB_TABLE_ROWS rows
void LIB_TABLE::Clear ( )
inline

Delete all rows.

Definition at line 312 of file lib_table_base.h.

References nickIndex, and rows.

Referenced by DIALOG_FP_LIB_TABLE::onOKButtonClick(), and DIALOG_SYMBOL_LIB_TABLE::TransferDataFromWindow().

313  {
314  rows.clear();
315  nickIndex.clear();
316  }
LIB_TABLE_ROWS rows
INDEX nickIndex
this particular key is the nickName within each row.
void LIB_TABLE::ensureIndex ( )
inlineprotected

Definition at line 476 of file lib_table_base.h.

References nickIndex, and reindex().

Referenced by findRow(), FindRowByURI(), and InsertRow().

477  {
478  // The dialog lib table editor may not maintain the nickIndex.
479  // Lazy indexing may be required. To handle lazy indexing, we must enforce
480  // that "nickIndex" is either empty or accurate, but never inaccurate.
481  if( !nickIndex.size() )
482  reindex();
483  }
void reindex()
INDEX nickIndex
this particular key is the nickName within each row.
const wxString LIB_TABLE::ExpandSubstitutions ( const wxString &  aString)
static

Replaces any environment variable references with their values and is here to fully embellish the TABLE_ROW::uri in a platform independent way.

This enables library tables to have platform dependent environment variables in them, allowing for a uniform table across platforms.

Definition at line 567 of file lib_table_base.cpp.

References ExpandEnvVarSubstitutions().

Referenced by GITHUB_PLUGIN::cacheLib(), LIB_TABLE_ROW::GetFullURI(), and LIB_TABLE_ROW::SetFullURI().

568 {
569  return ExpandEnvVarSubstitutions( aString );
570 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname) const
protected

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

Definition at line 284 of file lib_table_base.cpp.

References ensureIndex(), fallBack, nickIndex, and rows.

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

285 {
286  LIB_TABLE* cur = (LIB_TABLE*) this;
287 
288  do
289  {
290  cur->ensureIndex();
291 
292  INDEX_CITER it = cur->nickIndex.find( aNickName );
293 
294  if( it != cur->nickIndex.end() )
295  {
296  return &cur->rows[it->second]; // found
297  }
298 
299  // not found, search fall back table(s), if any
300  } while( ( cur = cur->fallBack ) != 0 );
301 
302  return NULL; // not found
303 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname)
protected

Definition at line 306 of file lib_table_base.cpp.

References ensureIndex(), fallBack, nickIndex, and rows.

307 {
308  LIB_TABLE* cur = (LIB_TABLE*) this;
309 
310  do
311  {
312  cur->ensureIndex();
313 
314  INDEX_ITER it = cur->nickIndex.find( aNickName );
315 
316  if( it != cur->nickIndex.end() )
317  {
318  return &cur->rows[it->second]; // found
319  }
320 
321  // not found, search fall back table(s), if any
322  } while( ( cur = cur->fallBack ) != 0 );
323 
324  return NULL; // not found
325 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX::iterator INDEX_ITER
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
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 328 of file lib_table_base.cpp.

References ensureIndex(), fallBack, and rows.

329 {
330  LIB_TABLE* cur = this;
331 
332  do
333  {
334  cur->ensureIndex();
335 
336  for( unsigned i = 0; i < cur->rows.size(); i++ )
337  {
338  wxString uri = cur->rows[i].GetFullURI( true );
339 
340  if( wxFileName::GetPathSeparator() == wxChar( '\\' ) && uri.Find( wxChar( '/' ) ) >= 0 )
341  uri.Replace( "/", "\\" );
342 
343  if( (wxFileName::IsCaseSensitive() && uri == aURI)
344  || (!wxFileName::IsCaseSensitive() && uri.Upper() == aURI.Upper() ) )
345  {
346  return &cur->rows[i]; // found
347  }
348  }
349 
350  // not found, search fall back table(s), if any
351  } while( ( cur = cur->fallBack ) != 0 );
352 
353  return NULL; // not found
354 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
virtual void LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
pure virtual

Generate the table in s-expression format to aOutput with an indention 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.

Implemented in SYMBOL_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Save().

UTF8 LIB_TABLE::FormatOptions ( const PROPERTIES aProperties)
static

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 529 of file lib_table_base.cpp.

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

Referenced by DIALOG_FP_PLUGIN_OPTIONS::makeResult().

530 {
531  UTF8 ret;
532 
533  if( aProperties )
534  {
535  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
536  {
537  const std::string& name = it->first;
538 
539  const UTF8& value = it->second;
540 
541  if( ret.size() )
542  ret += OPT_SEP;
543 
544  ret += name;
545 
546  // the separation between name and value is '='
547  if( value.size() )
548  {
549  ret += '=';
550 
551  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
552  {
553  // escape any separator in the value.
554  if( *si == OPT_SEP )
555  ret += '\\';
556 
557  ret += *si;
558  }
559  }
560  }
561  }
562 
563  return ret;
564 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
std::string::size_type size() const
Definition: utf8.h:115
std::string::const_iterator end() const
Definition: utf8.h:197
std::string::const_iterator begin() const
Definition: utf8.h:196
const char * name
#define OPT_SEP
options separator character
int LIB_TABLE::GetCount ( )
inline

Definition at line 336 of file lib_table_base.h.

References rows.

Referenced by SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

336 { return rows.size(); }
LIB_TABLE_ROWS rows
const wxString LIB_TABLE::GetDescription ( const wxString &  aNickname)
Returns
the library description from aNickname, or an empty string if aNickname does not exist.

Definition at line 251 of file lib_table_base.cpp.

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

Referenced by PCB_BASE_FRAME::SelectLibrary().

252 {
253  // use "no exception" form of find row:
254  const LIB_TABLE_ROW* row = findRow( aNickname );
255 
256  if( row )
257  return row->GetDescr();
258  else
259  return wxEmptyString;
260 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
const wxString & GetDescr() const
Return the description of the library referenced by this row.
size_t LIB_TABLE::GetEnvVars ( wxArrayString &  aEnvVars) const

Search the paths all of the LIB_TABLE_ROWS of the LIB_TABLE and add all of the environment variable substitutions to aEnvVars.

This will only add unique environment variables to the list. Duplicates are ignored.

Parameters
aEnvVarsis the array to load the environment variables.
Returns
the number of unique environment variables found in the table.

Definition at line 435 of file lib_table_base.cpp.

References fallBack, and rows.

436 {
437  const LIB_TABLE* cur = this;
438 
439  do
440  {
441  for( unsigned i = 0; i < cur->rows.size(); i++ )
442  {
443  wxString uri = cur->rows[i].GetFullURI( false );
444 
445  int start = uri.Find( "${" );
446 
447  if( start == wxNOT_FOUND )
448  continue;
449 
450  int end = uri.Find( '}' );
451 
452  if( end == wxNOT_FOUND || end < start+2 )
453  continue;
454 
455  wxString envVar = uri.Mid( start+2, end - (start+2) );
456 
457  if( aEnvVars.Index( envVar, false ) == wxNOT_FOUND )
458  aEnvVars.Add( envVar );
459  }
460 
461  // not found, search fall back table(s), if any
462  } while( ( cur = cur->fallBack ) != 0 );
463 
464  return aEnvVars.GetCount();
465 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
wxString LIB_TABLE::GetFullURI ( const wxString &  aLibNickname,
bool  aExpandEnvVars = true 
) const

Return the full URI of the library mapped to aLibNickname.

Definition at line 271 of file lib_table_base.cpp.

References findRow(), and LIB_TABLE_ROW::GetFullURI().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), LIB_MANAGER::IsLibraryReadOnly(), and NETLIST_EXPORTER_GENERIC::makeLibraries().

272 {
273  const LIB_TABLE_ROW* row = findRow( aNickname );
274 
275  wxString retv;
276 
277  if( row )
278  retv = row->GetFullURI( aExpandEnvVars );
279 
280  return retv;
281 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
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 * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
std::vector< wxString > LIB_TABLE::GetLogicalLibs ( )

Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

Definition at line 357 of file lib_table_base.cpp.

References fallBack, and rows.

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), LIB_MANAGER::GetLibraryNames(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), LIB_VIEW_FRAME::OnSelectSymbol(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), SCH_BASE_FRAME::SelectComponentFromLibrary(), PCB_BASE_FRAME::SelectLibrary(), and FOOTPRINT_LIST_IMPL::StartWorkers().

358 {
359  // Only return unique logical library names. Use std::set::insert() to
360  // quietly reject any duplicates, which can happen when encountering a duplicate
361  // nickname from one of the fall back table(s).
362 
363  std::set< wxString > unique;
364  std::vector< wxString > ret;
365  const LIB_TABLE* cur = this;
366 
367  do
368  {
369  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
370  {
371  if( it->GetIsEnabled() )
372  {
373  unique.insert( it->GetNickName() );
374  }
375  }
376 
377  } while( ( cur = cur->fallBack ) != 0 );
378 
379  ret.reserve( unique.size() );
380 
381  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
382  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
383  {
384  ret.push_back( *it );
385  }
386 
387  return ret;
388 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
bool LIB_TABLE::HasLibrary ( const wxString &  aNickname) const

Test for the existence of aNickname in the library table.

Returns
true if a library aNickname exists in the table.

Definition at line 263 of file lib_table_base.cpp.

References findRow().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), LIB_MANAGER::LibraryExists(), SCH_EAGLE_PLUGIN::Load(), NETLIST_EXPORTER_GENERIC::makeLibraries(), SCH_BASE_FRAME::SelectComponentFromLibrary(), and SCH_COMPONENT::SetLibId().

264 {
265  const LIB_TABLE_ROW* row = findRow( aNickname );
266 
267  return row != nullptr;
268 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
bool LIB_TABLE::InsertRow ( LIB_TABLE_ROW aRow,
bool  doReplace = false 
)

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 391 of file lib_table_base.cpp.

References ensureIndex(), LIB_TABLE_ROW::GetNickName(), nickIndex, and rows.

Referenced by LIB_MANAGER::addLibrary(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), InvokeFootprintWizard(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE::Parse().

392 {
393  ensureIndex();
394 
395  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
396 
397  if( it == nickIndex.end() )
398  {
399  rows.push_back( aRow );
400  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
401  return true;
402  }
403 
404  if( doReplace )
405  {
406  rows.replace( it->second, aRow );
407  return true;
408  }
409 
410  return false;
411 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
const wxString & GetNickName() const
INDEX nickIndex
this particular key is the nickName within each row.
bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)

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 242 of file lib_table_base.cpp.

References fallBack, IsEmpty(), and rows.

Referenced by SCH_EDIT_FRAME::AppendSchematic(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), IsEmpty(), PCB_EDIT_FRAME::LoadFootprints(), and FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib().

243 {
244  if( !aIncludeFallback || !fallBack )
245  return rows.empty();
246 
247  return rows.empty() && fallBack->IsEmpty( true );
248 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.
void LIB_TABLE::Load ( const wxString &  aFileName)

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 414 of file lib_table_base.cpp.

References Parse().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), FP_LIB_TABLE::LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), PROJECT::PcbFootprintLibs(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

416 {
417  // It's OK if footprint library tables are missing.
418  if( wxFileName::IsFileReadable( aFileName ) )
419  {
420  FILE_LINE_READER reader( aFileName );
421  LIB_TABLE_LEXER lexer( &reader );
422 
423  Parse( &lexer );
424  }
425 }
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW object...
Class LIB_TABLE_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/lib_table.keywords.
bool LIB_TABLE::operator!= ( const LIB_TABLE r) const
inline

Definition at line 334 of file lib_table_base.h.

334 { return !( *this == r ); }
bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inline

Definition at line 318 of file lib_table_base.h.

References rows.

319  {
320  if( rows.size() == r.rows.size() )
321  {
322  unsigned i;
323 
324  for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
325  ;
326 
327  if( i == rows.size() )
328  return true;
329  }
330 
331  return false;
332  }
LIB_TABLE_ROWS rows
virtual void LIB_TABLE::Parse ( LIB_TABLE_LEXER aLexer)
pure virtual

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.

Implemented in SYMBOL_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Load().

PROPERTIES * LIB_TABLE::ParseOptions ( const std::string &  aOptionsList)
static

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 468 of file lib_table_base.cpp.

References name, and OPT_SEP.

Referenced by DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), and LIB_TABLE_ROW::SetOptions().

469 {
470  if( aOptionsList.size() )
471  {
472  const char* cp = &aOptionsList[0];
473  const char* end = cp + aOptionsList.size();
474 
475  PROPERTIES props;
476  std::string pair;
477 
478  // Parse all name=value pairs
479  while( cp < end )
480  {
481  pair.clear();
482 
483  // Skip leading white space.
484  while( cp < end && isspace( *cp ) )
485  ++cp;
486 
487  // Find the end of pair/field
488  while( cp < end )
489  {
490  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
491  {
492  ++cp; // skip the escape
493  pair += *cp++; // add the separator
494  }
495  else if( *cp == OPT_SEP )
496  {
497  ++cp; // skip the separator
498  break; // process the pair
499  }
500  else
501  pair += *cp++;
502  }
503 
504  // stash the pair
505  if( pair.size() )
506  {
507  // first equals sign separates 'name' and 'value'.
508  size_t eqNdx = pair.find( '=' );
509 
510  if( eqNdx != pair.npos )
511  {
512  std::string name = pair.substr( 0, eqNdx );
513  std::string value = pair.substr( eqNdx + 1 );
514  props[name] = value;
515  }
516  else
517  props[pair] = ""; // property is present, but with no value.
518  }
519  }
520 
521  if( props.size() )
522  return new PROPERTIES( props );
523  }
524 
525  return NULL;
526 }
std::vector< PROPERTY > PROPERTIES
Definition: specctra.h:184
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const char * name
#define OPT_SEP
options separator character
void LIB_TABLE::reindex ( )
inlineprotected

Definition at line 468 of file lib_table_base.h.

References nickIndex, and rows.

Referenced by ensureIndex(), DIALOG_FP_LIB_TABLE::onOKButtonClick(), and DIALOG_SYMBOL_LIB_TABLE::TransferDataFromWindow().

469  {
470  nickIndex.clear();
471 
472  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
473  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
474  }
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
INDEX nickIndex
this particular key is the nickName within each row.
void LIB_TABLE::Save ( const wxString &  aFileName) const

Write this library table to aFileName in s-expression form.

Parameters
aFileNameis the name of the file to write to.

Definition at line 428 of file lib_table_base.cpp.

References Format().

Referenced by FP_LIB_TABLE::LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), CVPCB_MAINFRAME::OnEditFootprintLibraryTable(), PCB_EDIT_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

429 {
430  FILE_OUTPUTFORMATTER sf( aFileName );
431  Format( &sf, 0 );
432 }
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

Friends And Related Function Documentation

friend class DIALOG_FP_LIB_TABLE
friend

Definition at line 268 of file lib_table_base.h.

friend class LIB_TABLE_GRID
friend

Definition at line 269 of file lib_table_base.h.

Member Data Documentation

LIB_TABLE* LIB_TABLE::fallBack
protected

Definition at line 496 of file lib_table_base.h.

Referenced by findRow(), FindRowByURI(), GetEnvVars(), GetLogicalLibs(), and IsEmpty().

INDEX LIB_TABLE::nickIndex
protected

this particular key is the nickName within each row.

Definition at line 494 of file lib_table_base.h.

Referenced by Clear(), ensureIndex(), findRow(), InsertRow(), and reindex().


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