KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_item_index.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <unordered_map>
23
24#include <kiid.h>
25
26class BOARD;
27class BOARD_ITEM;
28
52{
53public:
54 explicit BOARD_ITEM_INDEX( BOARD& aOwner ) :
55 m_owner( aOwner )
56 {
57 }
58
66 BOARD_ITEM* Find( const KIID& aId );
67
71 void BindItem( BOARD_ITEM& aItem );
72
76 void Unbind( const KIID& aId );
77
82 void UnbindItem( const BOARD_ITEM& aItem );
83
87 void Clear();
88
92 void Rebind( BOARD_ITEM& aItem, const KIID& aNewId );
93
94 void BindSubtree( BOARD_ITEM& aItem );
95 void BindChildren( const BOARD_ITEM& aParent );
96 void UnbindSubtree( const BOARD_ITEM& aItem );
97 void UnbindChildren( const BOARD_ITEM& aParent );
98
103 bool IsIndexed( const KIID& aId ) const { return m_itemsById.contains( aId ); }
104
111 bool IsIndexed( const BOARD_ITEM* aItem ) const { return m_idsByItem.contains( aItem ); }
112
113private:
115
117 std::unordered_map<KIID, BOARD_ITEM*> m_itemsById;
118
120 std::unordered_map<const BOARD_ITEM*, KIID> m_idsByItem;
121};
BOARD_ITEM_INDEX(BOARD &aOwner)
std::unordered_map< KIID, BOARD_ITEM * > m_itemsById
Forward map from KIIDs to board items.
BOARD_ITEM * Find(const KIID &aId)
Return a cached item for aId if the entry is still self-consistent.
void UnbindSubtree(const BOARD_ITEM &aItem)
void UnbindItem(const BOARD_ITEM &aItem)
Drop aItem itself.
void Clear()
Drop every entry, clearing each item's link back to the board.
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.
void BindSubtree(BOARD_ITEM &aItem)
void Unbind(const KIID &aId)
Remove an item from the item-by-id cache.
void BindChildren(const BOARD_ITEM &aParent)
void BindItem(BOARD_ITEM &aItem)
Index aItem, replacing any previous entry for its UUID or address.
std::unordered_map< const BOARD_ITEM *, KIID > m_idsByItem
Reverse map from board items to their KIIDs.
void UnbindChildren(const BOARD_ITEM &aParent)
void Rebind(BOARD_ITEM &aItem, const KIID &aNewId)
Move aItem to aNewId, keeping the index in step with the item.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Definition kiid.h:46