KiCad PCB EDA Suite
|
#include <property_holder.h>
Public Member Functions | |
PROPERTY_HOLDER () | |
Default constructor - initializes magic value. | |
PROPERTY_HOLDER (const PROPERTY_HOLDER &other) | |
Copy constructor - maintains magic value. | |
PROPERTY_HOLDER (PROPERTY_HOLDER &&other) noexcept | |
Move constructor - maintains magic value. | |
PROPERTY_HOLDER & | operator= (const PROPERTY_HOLDER &other) |
Copy assignment operator. | |
PROPERTY_HOLDER & | operator= (PROPERTY_HOLDER &&other) noexcept |
Move assignment operator. | |
~PROPERTY_HOLDER () | |
Destructor - clears magic value to detect use-after-free. | |
bool | IsValid () const noexcept |
Check if this instance has a valid magic value. | |
template<typename T > | |
bool | SetProperty (const std::string &aKey, T &&aValue) |
Set a property with the given key and value. | |
template<typename T > | |
std::optional< T > | GetProperty (const std::string &aKey) const |
Get a property value with type checking. | |
template<typename T > | |
T | GetPropertyOr (const std::string &aKey, T &&aDefaultValue) const |
Get a property value with a default fallback. | |
bool | HasProperty (const std::string &aKey) const |
Check if a property exists. | |
bool | RemoveProperty (const std::string &aKey) |
Remove a property. | |
bool | Clear () |
Clear all properties. | |
size_t | Size () const |
Get the number of stored properties. | |
bool | Empty () const |
Check if there are no properties stored. | |
std::vector< std::string > | GetKeys () const |
Get all property keys. | |
std::optional< std::reference_wrapper< const std::type_info > > | GetPropertyType (const std::string &aKey) const |
Get the type information for a property. | |
template<typename T > | |
bool | HasPropertyOfType (const std::string &aKey) const |
Check if a property exists and has the expected type. | |
template<PropertyValueType T> | |
bool | SetTypedProperty (const std::string &aKey, T &&aValue) |
Type-safe property setter that only accepts valid property types. | |
Static Public Member Functions | |
static PROPERTY_HOLDER * | SafeCast (void *aPtr) noexcept |
Safely cast a void pointer to PROPERTY_HOLDER*. | |
static const PROPERTY_HOLDER * | SafeCast (const void *aPtr) noexcept |
Safely cast a const void pointer to const PROPERTY_HOLDER*. | |
static bool | SafeDelete (void *aPtr) noexcept |
Safely delete a PROPERTY_HOLDER from client data. | |
static bool | SafeDelete (PROPERTY_HOLDER *aHolder) noexcept |
Static Public Attributes | |
static constexpr uint64_t | MAGIC_VALUE = 0x50524F5048444C52ULL |
Magic value for memory validation (ASCII: "PROP" + "HLDR") | |
Private Attributes | |
uint64_t | m_magic |
Magic value for memory validation. | |
std::unordered_map< std::string, std::any > | m_properties |
Internal storage for properties using string keys and any values. | |
Definition at line 79 of file property_holder.h.
|
inline |
Default constructor - initializes magic value.
Definition at line 88 of file property_holder.h.
|
inline |
Copy constructor - maintains magic value.
Definition at line 96 of file property_holder.h.
|
inlinenoexcept |
Move constructor - maintains magic value.
Definition at line 105 of file property_holder.h.
|
inline |
Destructor - clears magic value to detect use-after-free.
Definition at line 136 of file property_holder.h.
References m_magic.
|
inline |
Clear all properties.
Definition at line 317 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Check if there are no properties stored.
Definition at line 341 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Get all property keys.
Definition at line 352 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Get a property value with type checking.
T | The expected type of the property |
key | The property key |
Definition at line 250 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::GetProperty().
|
inline |
Get a property value with a default fallback.
T | The expected type of the property |
key | The property key |
defaultValue | The value to return if property doesn't exist or type mismatch |
Definition at line 279 of file property_holder.h.
Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::GetPropertyOr().
|
inline |
Get the type information for a property.
key | The property key |
Definition at line 371 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Check if a property exists.
key | The property key |
Definition at line 292 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::HasProperty().
|
inline |
Check if a property exists and has the expected type.
T | The expected type |
key | The property key |
Definition at line 391 of file property_holder.h.
References IsValid(), m_properties, and T.
Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::HasPropertyOfType().
|
inlinenoexcept |
Check if this instance has a valid magic value.
Definition at line 145 of file property_holder.h.
References m_magic, and MAGIC_VALUE.
Referenced by BOOST_AUTO_TEST_CASE(), Clear(), Empty(), GetKeys(), GetProperty(), GetPropertyType(), HasProperty(), HasPropertyOfType(), RemoveProperty(), SetProperty(), and Size().
|
inline |
Copy assignment operator.
Definition at line 114 of file property_holder.h.
References m_properties.
|
inlinenoexcept |
Move assignment operator.
Definition at line 125 of file property_holder.h.
References m_properties.
|
inline |
Remove a property.
key | The property key |
Definition at line 305 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::RemoveProperty().
|
inlinestaticnoexcept |
Safely cast a const void pointer to const PROPERTY_HOLDER*.
ptr | Pointer to validate and cast |
Definition at line 177 of file property_holder.h.
References m_magic, and MAGIC_VALUE.
|
inlinestaticnoexcept |
Safely cast a void pointer to PROPERTY_HOLDER*.
ptr | Pointer to validate and cast |
Definition at line 152 of file property_holder.h.
References m_magic, and MAGIC_VALUE.
Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SHIM::LoadControlState(), SafeDelete(), and DIALOG_SHIM::SaveControlState().
|
inlinestaticnoexcept |
Definition at line 215 of file property_holder.h.
|
inlinestaticnoexcept |
Safely delete a PROPERTY_HOLDER from client data.
ptr | Pointer from client data to validate and delete |
Definition at line 202 of file property_holder.h.
References SafeCast().
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Set a property with the given key and value.
T | The type of the value to store |
key | The property key |
value | The value to store |
Definition at line 234 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SHIM::OptOut(), PROPERTY_MIXIN::SetProperty(), and SetTypedProperty().
|
inline |
Type-safe property setter that only accepts valid property types.
Definition at line 408 of file property_holder.h.
References SetProperty().
|
inline |
Get the number of stored properties.
Definition at line 330 of file property_holder.h.
References IsValid(), and m_properties.
Referenced by BOOST_AUTO_TEST_CASE().
|
private |
Magic value for memory validation.
Definition at line 414 of file property_holder.h.
Referenced by IsValid(), SafeCast(), and ~PROPERTY_HOLDER().
|
private |
Internal storage for properties using string keys and any values.
This uses std::any to allow storing any type of value, with type safety provided by the GetProperty and SetProperty methods.
Definition at line 421 of file property_holder.h.
Referenced by Clear(), Empty(), GetKeys(), GetProperty(), GetPropertyType(), HasProperty(), HasPropertyOfType(), operator=(), RemoveProperty(), SetProperty(), and Size().
|
staticconstexpr |
Magic value for memory validation (ASCII: "PROP" + "HLDR")
Definition at line 83 of file property_holder.h.
Referenced by BOOST_AUTO_TEST_CASE(), IsValid(), and SafeCast().