|
KiCad PCB EDA Suite
|
Bi-directional index mapping a board's items keyed by identity (KIID). More...
#include <board_item_index.h>
Public Member Functions | |
| BOARD_ITEM_INDEX (BOARD &aOwner) | |
| BOARD_ITEM * | Find (const KIID &aId) |
| Return a cached item for aId if the entry is still self-consistent. | |
| void | BindItem (BOARD_ITEM &aItem) |
| Index aItem, replacing any previous entry for its UUID or address. | |
| void | Unbind (const KIID &aId) |
| Remove an item from the item-by-id cache. | |
| void | UnbindItem (const BOARD_ITEM &aItem) |
| Drop aItem itself. | |
| void | Clear () |
| Drop every entry, clearing each item's link back to the board. | |
| void | Rebind (BOARD_ITEM &aItem, const KIID &aNewId) |
| Move aItem to aNewId, keeping the index in step with the item. | |
| void | BindSubtree (BOARD_ITEM &aItem) |
| void | BindChildren (const BOARD_ITEM &aParent) |
| void | UnbindSubtree (const BOARD_ITEM &aItem) |
| void | UnbindChildren (const BOARD_ITEM &aParent) |
| bool | IsIndexed (const KIID &aId) const |
| Return true if a forward entry for aId exists. | |
| bool | IsIndexed (const BOARD_ITEM *aItem) const |
| Return true if aItem is currently indexed. | |
Private Attributes | |
| BOARD & | m_owner |
| std::unordered_map< KIID, BOARD_ITEM * > | m_itemsById |
| Forward map from KIIDs to board items. | |
| std::unordered_map< const BOARD_ITEM *, KIID > | m_idsByItem |
| Reverse map from board items to their KIIDs. | |
Bi-directional index mapping a board's items keyed by identity (KIID).
This index maintains a two-way mapping between KIIDs and board items' pointer identities. It is used to quickly look up board items by their KIIDs, in particular by functions such as BOARD::ResolveItem(), where it provides O(1) lookup for indexed items.
This index does not have any thread-safety guarantees.
Implications of being indexed:
BOARD is the client of this index, and users of BOARDs interact with it only via the BOARD API (some of which are facades for this index).
FOOTPRINT boards keep an empty index: BindItem() and Rebind() return early there.
Definition at line 51 of file board_item_index.h.
|
inlineexplicit |
Definition at line 54 of file board_item_index.h.
References m_owner.
| void BOARD_ITEM_INDEX::BindChildren | ( | const BOARD_ITEM & | aParent | ) |
Definition at line 179 of file board_item_index.cpp.
References BindSubtree(), NO_RECURSE, and BOARD_ITEM::RunOnChildren().
| void BOARD_ITEM_INDEX::BindItem | ( | BOARD_ITEM & | aItem | ) |
Index aItem, replacing any previous entry for its UUID or address.
Definition at line 47 of file board_item_index.cpp.
References m_idsByItem, m_itemsById, m_owner, BOARD_ITEM::m_owningIndex, EDA_ITEM::m_Uuid, and UnbindItem().
Referenced by BindSubtree(), and Rebind().
| void BOARD_ITEM_INDEX::BindSubtree | ( | BOARD_ITEM & | aItem | ) |
Definition at line 167 of file board_item_index.cpp.
References BindItem(), BindSubtree(), NO_RECURSE, and BOARD_ITEM::RunOnChildren().
Referenced by BindChildren(), and BindSubtree().
| void BOARD_ITEM_INDEX::Clear | ( | ) |
Drop every entry, clearing each item's link back to the board.
Definition at line 134 of file board_item_index.cpp.
References m_idsByItem, and m_itemsById.
| BOARD_ITEM * BOARD_ITEM_INDEX::Find | ( | const KIID & | aId | ) |
Return a cached item for aId if the entry is still self-consistent.
UUIDs can still be rewritten in-place in some attached-item paths. When that happens, the cache may temporarily contain a stale alias from the old UUID to the live item. Drop those aliases on read so lookups never return an item whose current UUID no longer matches the key.
Definition at line 30 of file board_item_index.cpp.
References m_itemsById, EDA_ITEM::m_Uuid, and Unbind().
Referenced by Rebind().
|
inline |
Return true if aItem is currently indexed.
This does NOT dereference the pointer, so it is safe to call even if the item has been deleted.
Definition at line 111 of file board_item_index.h.
References m_idsByItem.
|
inline |
Return true if a forward entry for aId exists.
The entry may be stale; use Find() for a verified lookup.
Definition at line 103 of file board_item_index.h.
References m_itemsById.
| void BOARD_ITEM_INDEX::Rebind | ( | BOARD_ITEM & | aItem, |
| const KIID & | aNewId ) |
Move aItem to aNewId, keeping the index in step with the item.
Definition at line 144 of file board_item_index.cpp.
References KIID::AsString(), BindItem(), Find(), m_owner, EDA_ITEM::m_Uuid, BOARD_ITEM::SetUuidDirect(), and UnbindItem().
| void BOARD_ITEM_INDEX::Unbind | ( | const KIID & | aId | ) |
Remove an item from the item-by-id cache.
Definition at line 90 of file board_item_index.cpp.
References m_idsByItem, m_itemsById, and BOARD_ITEM::m_owningIndex.
Referenced by Find().
| void BOARD_ITEM_INDEX::UnbindChildren | ( | const BOARD_ITEM & | aParent | ) |
Definition at line 205 of file board_item_index.cpp.
References NO_RECURSE, BOARD_ITEM::RunOnChildren(), and UnbindSubtree().
| void BOARD_ITEM_INDEX::UnbindItem | ( | const BOARD_ITEM & | aItem | ) |
Drop aItem itself.
Pointer-keyed, so a temporary copy sharing its UUID is left alone, and safe to call from ~BOARD_ITEM and the UUID rebind paths.
Definition at line 110 of file board_item_index.cpp.
References m_idsByItem, m_itemsById, and BOARD_ITEM::m_owningIndex.
Referenced by BindItem(), Rebind(), and UnbindSubtree().
| void BOARD_ITEM_INDEX::UnbindSubtree | ( | const BOARD_ITEM & | aItem | ) |
Definition at line 190 of file board_item_index.cpp.
References NO_RECURSE, BOARD_ITEM::RunOnChildren(), UnbindItem(), and UnbindSubtree().
Referenced by UnbindChildren(), and UnbindSubtree().
|
private |
Reverse map from board items to their KIIDs.
Definition at line 120 of file board_item_index.h.
Referenced by BindItem(), Clear(), IsIndexed(), Unbind(), and UnbindItem().
|
private |
Forward map from KIIDs to board items.
Definition at line 117 of file board_item_index.h.
Referenced by BindItem(), Clear(), Find(), IsIndexed(), Unbind(), and UnbindItem().
|
private |
Definition at line 114 of file board_item_index.h.
Referenced by BindItem(), BOARD_ITEM_INDEX(), and Rebind().