![]() |
KiCad PCB EDA Suite
|
Provide class metadata.Helper macro to map type hashes to names. More...
#include <property_mgr.h>
Classes | |
struct | CLASS_DESC |
Returns metadata for a specific type. More... | |
struct | CLASS_INFO |
Public Types | |
typedef std::vector< CLASS_INFO > | CLASSES_INFO |
Public Member Functions | |
void | RegisterType (TYPE_ID aType, const wxString &aName) |
Associate a name with a type. More... | |
const wxString & | ResolveType (TYPE_ID aType) const |
Return name of a type. More... | |
PROPERTY_BASE * | GetProperty (TYPE_ID aType, const wxString &aProperty) const |
Return a property for a specific type. More... | |
const PROPERTY_LIST & | GetProperties (TYPE_ID aType) const |
Return all properties for a specific type. More... | |
const void * | TypeCast (const void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const |
Cast a type to another type. More... | |
void * | TypeCast (void *aSource, TYPE_ID aBase, TYPE_ID aTarget) const |
void | AddProperty (PROPERTY_BASE *aProperty) |
Register a property. More... | |
void | ReplaceProperty (size_t aBase, const wxString &aName, PROPERTY_BASE *aNew) |
Replace an existing property for a specific type. More... | |
void | AddTypeCast (TYPE_CAST_BASE *aCast) |
Register a type converter. More... | |
void | InheritsAfter (TYPE_ID aDerived, TYPE_ID aBase) |
Declare an inheritance relationship between types. More... | |
bool | IsOfType (TYPE_ID aDerived, TYPE_ID aBase) const |
Return true if aDerived is inherited from aBase. More... | |
EDA_UNITS | GetUnits () const |
void | SetUnits (EDA_UNITS aUnits) |
void | Rebuild () |
Rebuild the list of all registered properties. More... | |
CLASSES_INFO | GetAllClasses () |
std::vector< TYPE_ID > | GetMatchingClasses (PROPERTY_BASE *aProperty) |
Static Public Member Functions | |
static PROPERTY_MANAGER & | Instance () |
Private Member Functions | |
PROPERTY_MANAGER () | |
Structure holding type meta-data. More... | |
CLASS_DESC & | getClass (TYPE_ID aTypeId) |
Private Attributes | |
std::unordered_map< TYPE_ID, wxString > | m_classNames |
Map of all available types. More... | |
std::unordered_map< TYPE_ID, CLASS_DESC > | m_classes |
bool | m_dirty |
Flag indicating that the list of properties needs to be rebuild (RebuildProperties()) More... | |
EDA_UNITS | m_units |
Provide class metadata.Helper macro to map type hashes to names.
Each class handled by PROPERTY_MANAGER needs to be described using AddProperty(), AddTypeCast() and InheritsAfter() methods.
Enum types use a dedicated property type (PROPERTY_ENUM), define its possible values with ENUM_MAP class, then describe the type using macros:
Once all classes are described, the property list must be build using Rebuild() method.
Definition at line 62 of file property_mgr.h.
typedef std::vector<CLASS_INFO> PROPERTY_MANAGER::CLASSES_INFO |
Definition at line 186 of file property_mgr.h.
|
inlineprivate |
Structure holding type meta-data.
Definition at line 193 of file property_mgr.h.
void PROPERTY_MANAGER::AddProperty | ( | PROPERTY_BASE * | aProperty | ) |
Register a property.
aProperty | is the property to register. |
Definition at line 102 of file property_mgr.cpp.
References getClass(), m_dirty, PROPERTY_MANAGER::CLASS_DESC::m_ownProperties, name, PROPERTY_BASE::Name(), and PROPERTY_BASE::OwnerHash().
Referenced by BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), BOARD_ITEM_DESC::BOARD_ITEM_DESC(), CLASS_A_DESC::CLASS_A_DESC(), CLASS_B_DESC::CLASS_B_DESC(), CLASS_C_DESC::CLASS_C_DESC(), CLASS_D_DESC::CLASS_D_DESC(), EDA_ITEM_DESC::EDA_ITEM_DESC(), EDA_SHAPE_DESC::EDA_SHAPE_DESC(), EDA_TEXT_DESC::EDA_TEXT_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), FP_SHAPE_DESC::FP_SHAPE_DESC(), FP_TEXT_DESC::FP_TEXT_DESC(), PAD_DESC::PAD_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), PCB_TARGET_DESC::PCB_TARGET_DESC(), ReplaceProperty(), TRACK_VIA_DESC::TRACK_VIA_DESC(), and ZONE_DESC::ZONE_DESC().
void PROPERTY_MANAGER::AddTypeCast | ( | TYPE_CAST_BASE * | aCast | ) |
Register a type converter.
Required prior TypeCast() usage.
aCast | is the type converter to register. |
Definition at line 121 of file property_mgr.cpp.
References TYPE_CAST_BASE::BaseHash(), TYPE_CAST_BASE::DerivedHash(), getClass(), and PROPERTY_MANAGER::CLASS_DESC::m_typeCasts.
Referenced by CLASS_D_DESC::CLASS_D_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), FP_SHAPE_DESC::FP_SHAPE_DESC(), FP_TEXT_DESC::FP_TEXT_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), and TEXTE_PCB_DESC::TEXTE_PCB_DESC().
PROPERTY_MANAGER::CLASSES_INFO PROPERTY_MANAGER::GetAllClasses | ( | ) |
Definition at line 234 of file property_mgr.cpp.
References info, m_classes, and m_classNames.
Referenced by PCB_EXPR_UCODE::CreateVarRef(), and PANEL_SETUP_RULES::onScintillaCharAdded().
|
private |
Definition at line 173 of file property_mgr.cpp.
References m_classes.
Referenced by AddProperty(), AddTypeCast(), InheritsAfter(), and ReplaceProperty().
std::vector< TYPE_ID > PROPERTY_MANAGER::GetMatchingClasses | ( | PROPERTY_BASE * | aProperty | ) |
Definition at line 214 of file property_mgr.cpp.
const PROPERTY_LIST & PROPERTY_MANAGER::GetProperties | ( | TYPE_ID | aType | ) | const |
Return all properties for a specific type.
aType | is the type identifier (obtained using TYPE_HASH()). |
Definition at line 67 of file property_mgr.cpp.
References empty(), m_classes, and m_dirty.
Referenced by PANEL_SETUP_RULES::onScintillaCharAdded().
PROPERTY_BASE * PROPERTY_MANAGER::GetProperty | ( | TYPE_ID | aType, |
const wxString & | aProperty | ||
) | const |
Return a property for a specific type.
aType | is the type identifier (obtained using TYPE_HASH()). |
aProperty | is the property name used during class registration. |
Definition at line 45 of file property_mgr.cpp.
References PROPERTY_MANAGER::CLASS_DESC::m_allProperties, m_classes, m_dirty, and PROPERTY_BASE::Name().
Referenced by PCB_EXPR_UCODE::CreateVarRef(), INSPECTABLE::Get(), and INSPECTABLE::Set().
|
inline |
Declare an inheritance relationship between types.
aBase | is the base type identifier (obtained using TYPE_HASH()). |
aDerived | is the derived type identifier (obtained using TYPE_HASH()). |
Definition at line 131 of file property_mgr.cpp.
References getClass(), PROPERTY_MANAGER::CLASS_DESC::m_bases, m_dirty, and PROPERTY_MANAGER::CLASS_DESC::m_typeCasts.
Referenced by BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), BOARD_ITEM_DESC::BOARD_ITEM_DESC(), CLASS_B_DESC::CLASS_B_DESC(), CLASS_D_DESC::CLASS_D_DESC(), DIMENSION_DESC::DIMENSION_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), FP_SHAPE_DESC::FP_SHAPE_DESC(), FP_TEXT_DESC::FP_TEXT_DESC(), PAD_DESC::PAD_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), PCB_TARGET_DESC::PCB_TARGET_DESC(), TEXTE_PCB_DESC::TEXTE_PCB_DESC(), TRACK_VIA_DESC::TRACK_VIA_DESC(), and ZONE_DESC::ZONE_DESC().
|
inlinestatic |
Definition at line 65 of file property_mgr.h.
Referenced by BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), BOARD_ITEM_DESC::BOARD_ITEM_DESC(), BOOST_AUTO_TEST_CASE(), CLASS_A_DESC::CLASS_A_DESC(), CLASS_B_DESC::CLASS_B_DESC(), CLASS_C_DESC::CLASS_C_DESC(), CLASS_D_DESC::CLASS_D_DESC(), CLASS_E_DESC::CLASS_E_DESC(), PCB_EXPR_UCODE::CreateVarRef(), DIMENSION_DESC::DIMENSION_DESC(), EDA_ITEM_DESC::EDA_ITEM_DESC(), EDA_SHAPE_DESC::EDA_SHAPE_DESC(), EDA_TEXT_DESC::EDA_TEXT_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), FP_SHAPE_DESC::FP_SHAPE_DESC(), FP_TEXT_DESC::FP_TEXT_DESC(), INSPECTABLE::Get(), main(), PANEL_SETUP_RULES::onScintillaCharAdded(), PAD_DESC::PAD_DESC(), PCB_SHAPE_DESC::PCB_SHAPE_DESC(), PCB_TARGET_DESC::PCB_TARGET_DESC(), INSPECTABLE::Set(), TEXTE_PCB_DESC::TEXTE_PCB_DESC(), TRACK_VIA_DESC::TRACK_VIA_DESC(), and ZONE_DESC::ZONE_DESC().
Return true if aDerived is inherited from aBase.
Definition at line 145 of file property_mgr.cpp.
References m_classes.
Referenced by PCB_EXPR_UCODE::CreateVarRef(), and TypeCast().
void PROPERTY_MANAGER::Rebuild | ( | ) |
Rebuild the list of all registered properties.
Needs to be called once before GetProperty()/GetProperties() are used.
Definition at line 164 of file property_mgr.cpp.
References m_classes, and m_dirty.
Referenced by BOOST_AUTO_TEST_CASE(), and main().
void PROPERTY_MANAGER::RegisterType | ( | TYPE_ID | aType, |
const wxString & | aName | ||
) |
Associate a name with a type.
Build a map to provide faster type look-up.
aType | is the type identifier (obtained using TYPE_HASH()). |
aName | is the type name. |
Definition at line 31 of file property_mgr.cpp.
References m_classNames.
void PROPERTY_MANAGER::ReplaceProperty | ( | size_t | aBase, |
const wxString & | aName, | ||
PROPERTY_BASE * | aNew | ||
) |
Replace an existing property for a specific type.
It is used to modify a property that has been inherited from a base class. This method is used instead of AddProperty().
aBase | is the base class type the delivers the original property. |
aName | is the name of the replaced property. |
aNew | is the property replacing the inherited one. |
Definition at line 112 of file property_mgr.cpp.
References AddProperty(), PROPERTY_BASE::BaseHash(), getClass(), PROPERTY_MANAGER::CLASS_DESC::m_replaced, and PROPERTY_BASE::OwnerHash().
Referenced by BOARD_CONNECTED_ITEM_DESC::BOARD_CONNECTED_ITEM_DESC(), CLASS_D_DESC::CLASS_D_DESC(), CLASS_E_DESC::CLASS_E_DESC(), FOOTPRINT_DESC::FOOTPRINT_DESC(), and TRACK_VIA_DESC::TRACK_VIA_DESC().
const wxString & PROPERTY_MANAGER::ResolveType | ( | TYPE_ID | aType | ) | const |
Return name of a type.
aType | is the type identifier (obtained using TYPE_HASH()). |
Definition at line 38 of file property_mgr.cpp.
References EMPTY_STRING(), and m_classNames.
|
inline |
const void * PROPERTY_MANAGER::TypeCast | ( | const void * | aSource, |
TYPE_ID | aBase, | ||
TYPE_ID | aTarget | ||
) | const |
Cast a type to another type.
Used for correct type-casting of types with multi-inheritance. Requires registration of an appropriate converter (AddTypeCast).
aSource | is a pointer to the casted object. |
aBase | is aSource type identifier (obtained using TYPE_HASH()). |
aTarget | is the desired type identifier (obtained using TYPE_HASH()). |
Definition at line 82 of file property_mgr.cpp.
References IsOfType(), and m_classes.
Referenced by INSPECTABLE::Get(), INSPECTABLE::Set(), and TypeCast().
Definition at line 119 of file property_mgr.h.
References TypeCast().
|
private |
Definition at line 238 of file property_mgr.h.
Referenced by GetAllClasses(), getClass(), GetProperties(), GetProperty(), IsOfType(), Rebuild(), and TypeCast().
|
private |
Map of all available types.
Definition at line 235 of file property_mgr.h.
Referenced by GetAllClasses(), RegisterType(), and ResolveType().
|
private |
Flag indicating that the list of properties needs to be rebuild (RebuildProperties())
Definition at line 241 of file property_mgr.h.
Referenced by AddProperty(), GetProperties(), GetProperty(), InheritsAfter(), and Rebuild().
|
private |
Definition at line 243 of file property_mgr.h.
Referenced by GetUnits(), and SetUnits().