|
KiCad PCB EDA Suite
|
Bidirectional index mapping TEXT_VAR_REF_KEY → dependent items and item → keys. More...
#include <text_var_dependency.h>
Public Member Functions | |
| TEXT_VAR_DEPENDENCY_INDEX ()=default | |
| void | Register (EDA_ITEM *aItem, const std::vector< TEXT_VAR_REF_KEY > &aKeys) |
Replace the key set for aItem with aKeys. | |
| void | Unregister (EDA_ITEM *aItem) |
Remove aItem from the index entirely. | |
| void | ForEachDependent (const TEXT_VAR_REF_KEY &aKey, const std::function< void(EDA_ITEM *)> &aFn) const |
Invoke aFn exactly once per item registered under aKey. | |
| void | Clear () |
| Drop every entry. | |
| std::size_t | DependentCount (const TEXT_VAR_REF_KEY &aKey) const |
| std::size_t | ItemCount () const |
| std::vector< TEXT_VAR_REF_KEY > | GetRegisteredKeys () const |
| Enumerate every key currently present in the forward index. | |
Private Attributes | |
| std::shared_mutex | m_mutex |
| std::unordered_map< TEXT_VAR_REF_KEY, std::unordered_set< EDA_ITEM * >, TEXT_VAR_REF_KEY_HASH > | m_dependents |
| std::unordered_map< EDA_ITEM *, std::vector< TEXT_VAR_REF_KEY > > | m_itemKeys |
Bidirectional index mapping TEXT_VAR_REF_KEY → dependent items and item → keys.
The item-keyed direction exists so Unregister is O(refs-per-item) rather than having to scan the entire forward index. All mutators are thread-safe; readers (ForEachDependent) take a shared lock.
Definition at line 127 of file text_var_dependency.h.
|
default |
References Clear(), DependentCount(), ForEachDependent(), GetRegisteredKeys(), ItemCount(), Register(), and Unregister().
| void TEXT_VAR_DEPENDENCY_INDEX::Clear | ( | ) |
Drop every entry.
Intended for teardown of the owning BOARD/SCHEMATIC.
Definition at line 245 of file text_var_dependency.cpp.
References m_dependents, m_itemKeys, and m_mutex.
Referenced by TEXT_VAR_DEPENDENCY_INDEX().
| std::size_t TEXT_VAR_DEPENDENCY_INDEX::DependentCount | ( | const TEXT_VAR_REF_KEY & | aKey | ) | const |
Definition at line 254 of file text_var_dependency.cpp.
References m_dependents, and m_mutex.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and TEXT_VAR_DEPENDENCY_INDEX().
| void TEXT_VAR_DEPENDENCY_INDEX::ForEachDependent | ( | const TEXT_VAR_REF_KEY & | aKey, |
| const std::function< void(EDA_ITEM *)> & | aFn ) const |
Invoke aFn exactly once per item registered under aKey.
The callback runs while the shared lock is held, so it must not call Register/Unregister (which would deadlock on the same mutex).
Definition at line 218 of file text_var_dependency.cpp.
References m_dependents, and m_mutex.
Referenced by TEXT_VAR_DEPENDENCY_INDEX().
| std::vector< TEXT_VAR_REF_KEY > TEXT_VAR_DEPENDENCY_INDEX::GetRegisteredKeys | ( | ) | const |
Enumerate every key currently present in the forward index.
The snapshot is taken under the shared lock and returned by value, so callers may safely mutate the index while iterating (e.g., fire an InvalidateKey on each returned key).
Definition at line 271 of file text_var_dependency.cpp.
References m_dependents, and m_mutex.
Referenced by TEXT_VAR_DEPENDENCY_INDEX().
| std::size_t TEXT_VAR_DEPENDENCY_INDEX::ItemCount | ( | ) | const |
Definition at line 264 of file text_var_dependency.cpp.
References m_itemKeys, and m_mutex.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and TEXT_VAR_DEPENDENCY_INDEX().
| void TEXT_VAR_DEPENDENCY_INDEX::Register | ( | EDA_ITEM * | aItem, |
| const std::vector< TEXT_VAR_REF_KEY > & | aKeys ) |
Replace the key set for aItem with aKeys.
Clears any prior registration for the item first.
Definition at line 157 of file text_var_dependency.cpp.
References m_dependents, m_itemKeys, and m_mutex.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and TEXT_VAR_DEPENDENCY_INDEX().
| void TEXT_VAR_DEPENDENCY_INDEX::Unregister | ( | EDA_ITEM * | aItem | ) |
Remove aItem from the index entirely.
Safe to call on an item that was never registered.
Definition at line 191 of file text_var_dependency.cpp.
References m_dependents, m_itemKeys, and m_mutex.
Referenced by TEXT_VAR_DEPENDENCY_INDEX().
|
private |
Definition at line 174 of file text_var_dependency.h.
Referenced by Clear(), DependentCount(), ForEachDependent(), GetRegisteredKeys(), Register(), and Unregister().
|
private |
Definition at line 176 of file text_var_dependency.h.
Referenced by Clear(), ItemCount(), Register(), and Unregister().
|
mutableprivate |
Definition at line 170 of file text_var_dependency.h.
Referenced by Clear(), DependentCount(), ForEachDependent(), GetRegisteredKeys(), ItemCount(), Register(), and Unregister().