KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ALLEGRO::BRD_DB Class Reference

An Allegro database that represents a .brd file (amd presumably .dra) More...

#include <allegro_db.h>

Inheritance diagram for ALLEGRO::BRD_DB:
ALLEGRO::DB ALLEGRO::DB_OBJ_RESOLVER

Classes

class  OBJ_FACTORY
 Converts blocks of "raw" binary-ish data into a DB_OBJ of the appropriate type to be stored in the DB. More...
 

Public Types

using FP_DEF_VISITOR = std::function<void( const FOOTPRINT_DEF& aFpDef )>
 

Public Member Functions

 BRD_DB ()
 
void InsertBlock (std::unique_ptr< BLOCK_BASE > aBlock) override
 
void ReserveCapacity (size_t aObjectCount, size_t aStringCount)
 Pre-allocate storage for the expected number of objects and strings.
 
void SetLeanMode (bool aLean)
 When true, InsertBlock skips DB_OBJ creation for high-volume block types (segments, graphics, arcs) that the BOARD_BUILDER accesses only through raw BLOCK_BASE.
 
bool ResolveAndValidate ()
 Iterate all the links we know about and fill in the object links.
 
void VisitFootprintDefs (FP_DEF_VISITOR aFpDef) const
 Access the footprint defs in the database.
 
void VisitFootprintInstances (VIEW_OBJS_VISITOR aVisitor) const
 Access the footprint instances in the database.
 
void visitFootprintInstances (const FOOTPRINT_DEF &aFpDef, VIEW_OBJS_VISITOR aVisitor) const
 
void VisitFunctionInstances (VIEW_OBJS_VISITOR aVisitor) const
 Access the function instances in the database.
 
void VisitComponents (VIEW_OBJS_VISITOR aVisitor) const
 
void VisitComponentPins (VIEW_OBJS_VISITOR aVisitor) const
 Visit all component pins in the database.
 
void VisitNets (VIEW_OBJS_VISITOR aVisitor) const
 
void VisitConnectedGeometry (VIEW_OBJS_VISITOR aVisitor) const
 
const BLOCK_BASEGetObjectByKey (uint32_t aKey) const
 Get a raw block by its key (for compatibility with BOARD_BUILDER).
 
const wxString & GetString (uint32_t aKey) const
 Get a string from the string table by key.
 
void AddObject (std::unique_ptr< DB_OBJ > aObject)
 
void AddString (uint32_t aKey, wxString &&aStr)
 
size_t GetObjectCount () const
 
void ResolveObjectLinks ()
 Iterate the database and resolve links.
 
DB_OBJResolve (uint32_t aRef) const override
 Implement the object resolver interface.
 
const wxString * ResolveString (uint32_t aRef) const override
 
bool IsSentinel (uint32_t aKey) const override
 In v18+ files, linked list sentinel nodes are real blocks with small keys.
 
void AddSentinelKey (uint32_t aKey)
 

Public Attributes

FMT_VER m_FmtVer
 
std::unique_ptr< FILE_HEADERm_Header
 
std::vector< std::unique_ptr< BLOCK_BASE > > m_Blocks
 
std::unordered_map< uint32_t, BLOCK_BASE * > m_ObjectKeyMap
 
std::unordered_map< uint32_t, wxString > m_StringTable
 

Protected Member Functions

void visitLinkedList (const FILE_HEADER::LINKED_LIST aLList, std::function< const DB_REF &(const DB_OBJ &aObj)> aVisitor) const
 
void reserveObjects (size_t aCount)
 
void ResolveObjectLinksBestEffort ()
 Resolve all DB_OBJ references without throwing on failure.
 

Private Attributes

OBJ_FACTORY m_ObjFactory
 
bool m_leanMode
 
std::unordered_map< uint32_t, std::unique_ptr< DB_OBJ > > m_Objects
 
std::unordered_set< uint32_t > m_SentinelKeys
 

Detailed Description

An Allegro database that represents a .brd file (amd presumably .dra)

Definition at line 849 of file allegro_db.h.

Member Typedef Documentation

◆ FP_DEF_VISITOR

using ALLEGRO::BRD_DB::FP_DEF_VISITOR = std::function<void( const FOOTPRINT_DEF& aFpDef )>

Definition at line 901 of file allegro_db.h.

Constructor & Destructor Documentation

◆ BRD_DB()

BRD_DB::BRD_DB ( )

Member Function Documentation

◆ AddObject()

void DB::AddObject ( std::unique_ptr< DB_OBJ > aObject)
inherited

Definition at line 407 of file allegro_db.cpp.

References m_Objects.

Referenced by ALLEGRO::BRD_DB::InsertBlock().

◆ AddSentinelKey()

void ALLEGRO::DB::AddSentinelKey ( uint32_t aKey)
inlineinherited

Definition at line 289 of file allegro_db.h.

References m_SentinelKeys.

Referenced by collectSentinelKeys().

◆ AddString()

void ALLEGRO::DB::AddString ( uint32_t aKey,
wxString && aStr )
inlineinherited

Definition at line 261 of file allegro_db.h.

References m_StringTable.

Referenced by ReadStringMap().

◆ GetObjectByKey()

const BLOCK_BASE * ALLEGRO::BRD_DB::GetObjectByKey ( uint32_t aKey) const
inline

Get a raw block by its key (for compatibility with BOARD_BUILDER).

Definition at line 942 of file allegro_db.h.

References m_ObjectKeyMap.

◆ GetObjectCount()

size_t ALLEGRO::DB::GetObjectCount ( ) const
inlineinherited

Definition at line 263 of file allegro_db.h.

References m_Objects.

Referenced by ALLEGRO::PARSER::readObjects().

◆ GetString()

const wxString & ALLEGRO::BRD_DB::GetString ( uint32_t aKey) const
inline

Get a string from the string table by key.

Definition at line 951 of file allegro_db.h.

References empty(), and ALLEGRO::DB::m_StringTable.

◆ InsertBlock()

void BRD_DB::InsertBlock ( std::unique_ptr< BLOCK_BASE > aBlock)
overridevirtual

Implements ALLEGRO::DB.

Definition at line 217 of file allegro_db.cpp.

References ALLEGRO::DB::AddObject(), m_Blocks, m_leanMode, m_ObjectKeyMap, and m_ObjFactory.

Referenced by ALLEGRO::PARSER::readObjects().

◆ IsSentinel()

bool ALLEGRO::DB::IsSentinel ( uint32_t aKey) const
inlineoverridevirtualinherited

In v18+ files, linked list sentinel nodes are real blocks with small keys.

References pointing to these sentinels are logically null (end-of-chain).

Reimplemented from ALLEGRO::DB_OBJ_RESOLVER.

Definition at line 284 of file allegro_db.h.

References m_SentinelKeys.

Referenced by visitLinkedList().

◆ ReserveCapacity()

void BRD_DB::ReserveCapacity ( size_t aObjectCount,
size_t aStringCount )

Pre-allocate storage for the expected number of objects and strings.

Avoids incremental rehashing as elements are inserted.

Definition at line 208 of file allegro_db.cpp.

References m_Blocks, m_ObjectKeyMap, ALLEGRO::DB::m_StringTable, and ALLEGRO::DB::reserveObjects().

◆ reserveObjects()

void ALLEGRO::DB::reserveObjects ( size_t aCount)
inlineprotectedinherited

Definition at line 301 of file allegro_db.h.

References m_Objects.

Referenced by ALLEGRO::BRD_DB::ReserveCapacity().

◆ Resolve()

DB_OBJ * DB::Resolve ( uint32_t aRef) const
overridevirtualinherited

Implement the object resolver interface.

Implements ALLEGRO::DB_OBJ_RESOLVER.

Definition at line 413 of file allegro_db.cpp.

References m_Objects.

Referenced by visitLinkedList().

◆ ResolveAndValidate()

bool BRD_DB::ResolveAndValidate ( )

Iterate all the links we know about and fill in the object links.

This means that when we come to use the objects, we don't have to keep looking them up in the DB and handling failures.

Definition at line 1583 of file allegro_db.cpp.

References collectSentinelKeys(), m_FmtVer, m_Header, m_leanMode, IO_ERROR::Problem(), ALLEGRO::DB::ResolveObjectLinks(), ALLEGRO::DB::ResolveObjectLinksBestEffort(), and ALLEGRO::V_180.

◆ ResolveObjectLinks()

void DB::ResolveObjectLinks ( )
inherited

Iterate the database and resolve links.

This has to be done after all the objects are read, as they are not necessarily read in order.

This is done once per DB after loading. We can just resolve everything on-demand (with or without caching), but resolving upfront means we can detect bad references earlier which is useful when the DB data is not fully known.

Definition at line 436 of file allegro_db.cpp.

References m_Objects, and THROW_IO_ERROR.

Referenced by ALLEGRO::BRD_DB::ResolveAndValidate().

◆ ResolveObjectLinksBestEffort()

void DB::ResolveObjectLinksBestEffort ( )
protectedinherited

Resolve all DB_OBJ references without throwing on failure.

Objects that can't fully resolve are marked invalid but processing continues.

Definition at line 452 of file allegro_db.cpp.

References m_Objects.

Referenced by ALLEGRO::BRD_DB::ResolveAndValidate().

◆ ResolveString()

const wxString * DB::ResolveString ( uint32_t aRef) const
overridevirtualinherited

Implements ALLEGRO::DB_OBJ_RESOLVER.

Definition at line 424 of file allegro_db.cpp.

References m_StringTable.

◆ SetLeanMode()

void ALLEGRO::BRD_DB::SetLeanMode ( bool aLean)
inline

When true, InsertBlock skips DB_OBJ creation for high-volume block types (segments, graphics, arcs) that the BOARD_BUILDER accesses only through raw BLOCK_BASE.

Types needed by VisitNets (NET, FIELD, etc.) still get full DB_OBJ resolution.

Definition at line 891 of file allegro_db.h.

References m_leanMode.

◆ VisitComponentPins()

void BRD_DB::VisitComponentPins ( VIEW_OBJS_VISITOR aVisitor) const

◆ VisitComponents()

◆ VisitConnectedGeometry()

void BRD_DB::VisitConnectedGeometry ( VIEW_OBJS_VISITOR aVisitor) const

Definition at line 1816 of file allegro_db.cpp.

References ALLEGRO::VIEW_OBJS::m_Board, and VisitNets().

◆ VisitFootprintDefs()

void BRD_DB::VisitFootprintDefs ( BRD_DB::FP_DEF_VISITOR aVisitor) const

Access the footprint defs in the database.

This iterates the 0x2B linked list.

Definition at line 1617 of file allegro_db.cpp.

References ALLEGRO::DB_NULLREF, m_Header, ALLEGRO::FOOTPRINT_DEF::m_Next, and ALLEGRO::DB::visitLinkedList().

Referenced by VisitFootprintInstances().

◆ VisitFootprintInstances()

void BRD_DB::VisitFootprintInstances ( VIEW_OBJS_VISITOR aVisitor) const

Access the footprint instances in the database.

This iterates the 0x2D linked list for a given footprint def.

Definition at line 1670 of file allegro_db.cpp.

References ALLEGRO::VIEW_OBJS::m_Board, VisitFootprintDefs(), and visitFootprintInstances().

◆ visitFootprintInstances()

◆ VisitFunctionInstances()

void BRD_DB::VisitFunctionInstances ( VIEW_OBJS_VISITOR aVisitor) const

Access the function instances in the database.

This iterates the 0x06 linked list and finds the functions.

If the function is assigned to a component, the component is set. If the component is placed, the symbol is also set.

Definition at line 1686 of file allegro_db.cpp.

References VisitComponents().

◆ visitLinkedList()

◆ VisitNets()

Member Data Documentation

◆ m_Blocks

std::vector<std::unique_ptr<BLOCK_BASE> > ALLEGRO::BRD_DB::m_Blocks

Definition at line 966 of file allegro_db.h.

Referenced by InsertBlock(), and ReserveCapacity().

◆ m_FmtVer

FMT_VER ALLEGRO::BRD_DB::m_FmtVer

Definition at line 962 of file allegro_db.h.

Referenced by BRD_DB(), ALLEGRO::PARSER::readObjects(), and ResolveAndValidate().

◆ m_Header

◆ m_leanMode

bool ALLEGRO::BRD_DB::m_leanMode
private

Definition at line 973 of file allegro_db.h.

Referenced by BRD_DB(), InsertBlock(), ResolveAndValidate(), and SetLeanMode().

◆ m_ObjectKeyMap

std::unordered_map<uint32_t, BLOCK_BASE*> ALLEGRO::BRD_DB::m_ObjectKeyMap

Definition at line 967 of file allegro_db.h.

Referenced by GetObjectByKey(), InsertBlock(), and ReserveCapacity().

◆ m_Objects

std::unordered_map<uint32_t, std::unique_ptr<DB_OBJ> > ALLEGRO::DB::m_Objects
privateinherited

◆ m_ObjFactory

OBJ_FACTORY ALLEGRO::BRD_DB::m_ObjFactory
private

Definition at line 971 of file allegro_db.h.

Referenced by BRD_DB(), and InsertBlock().

◆ m_SentinelKeys

std::unordered_set<uint32_t> ALLEGRO::DB::m_SentinelKeys
privateinherited

Definition at line 314 of file allegro_db.h.

Referenced by AddSentinelKey(), and IsSentinel().

◆ m_StringTable

std::unordered_map<uint32_t, wxString> ALLEGRO::DB::m_StringTable
inherited

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