KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PROPERTY_HOLDER Class Reference

#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_HOLDERoperator= (const PROPERTY_HOLDER &other)
 Copy assignment operator.
 
PROPERTY_HOLDERoperator= (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< TGetProperty (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_HOLDERSafeCast (void *aPtr) noexcept
 Safely cast a void pointer to PROPERTY_HOLDER*.
 
static const PROPERTY_HOLDERSafeCast (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.
 

Detailed Description

Definition at line 79 of file property_holder.h.

Constructor & Destructor Documentation

◆ PROPERTY_HOLDER() [1/3]

PROPERTY_HOLDER::PROPERTY_HOLDER ( )
inline

Default constructor - initializes magic value.

Definition at line 88 of file property_holder.h.

◆ PROPERTY_HOLDER() [2/3]

PROPERTY_HOLDER::PROPERTY_HOLDER ( const PROPERTY_HOLDER other)
inline

Copy constructor - maintains magic value.

Definition at line 96 of file property_holder.h.

◆ PROPERTY_HOLDER() [3/3]

PROPERTY_HOLDER::PROPERTY_HOLDER ( PROPERTY_HOLDER &&  other)
inlinenoexcept

Move constructor - maintains magic value.

Definition at line 105 of file property_holder.h.

◆ ~PROPERTY_HOLDER()

PROPERTY_HOLDER::~PROPERTY_HOLDER ( )
inline

Destructor - clears magic value to detect use-after-free.

Definition at line 136 of file property_holder.h.

References m_magic.

Member Function Documentation

◆ Clear()

bool PROPERTY_HOLDER::Clear ( )
inline

Clear all properties.

Returns
true if cleared successfully, false if object is invalid

Definition at line 317 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE().

◆ Empty()

bool PROPERTY_HOLDER::Empty ( ) const
inline

Check if there are no properties stored.

Returns
true if empty or object is invalid, false otherwise

Definition at line 341 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetKeys()

std::vector< std::string > PROPERTY_HOLDER::GetKeys ( ) const
inline

Get all property keys.

Returns
A vector of all property keys (empty if object is invalid)

Definition at line 352 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetProperty()

template<typename T >
std::optional< T > PROPERTY_HOLDER::GetProperty ( const std::string &  aKey) const
inline

Get a property value with type checking.

Template Parameters
TThe expected type of the property
Parameters
keyThe property key
Returns
std::optional<T> containing the value if found and type matches, nullopt otherwise

Definition at line 250 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::GetProperty().

◆ GetPropertyOr()

template<typename T >
T PROPERTY_HOLDER::GetPropertyOr ( const std::string &  aKey,
T &&  aDefaultValue 
) const
inline

Get a property value with a default fallback.

Template Parameters
TThe expected type of the property
Parameters
keyThe property key
defaultValueThe value to return if property doesn't exist or type mismatch
Returns
The property value or the default value

Definition at line 279 of file property_holder.h.

Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::GetPropertyOr().

◆ GetPropertyType()

std::optional< std::reference_wrapper< const std::type_info > > PROPERTY_HOLDER::GetPropertyType ( const std::string &  aKey) const
inline

Get the type information for a property.

Parameters
keyThe property key
Returns
std::optional<std::type_info> containing type info if property exists and object is valid

Definition at line 371 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE().

◆ HasProperty()

bool PROPERTY_HOLDER::HasProperty ( const std::string &  aKey) const
inline

Check if a property exists.

Parameters
keyThe property key
Returns
true if the property exists and object is valid, false otherwise

Definition at line 292 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::HasProperty().

◆ HasPropertyOfType()

template<typename T >
bool PROPERTY_HOLDER::HasPropertyOfType ( const std::string &  aKey) const
inline

Check if a property exists and has the expected type.

Template Parameters
TThe expected type
Parameters
keyThe property key
Returns
true if property exists, has type T, and object is valid

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().

◆ IsValid()

bool PROPERTY_HOLDER::IsValid ( ) const
inlinenoexcept

Check if this instance has a valid magic value.

Returns
true if magic value is valid, false otherwise

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().

◆ operator=() [1/2]

PROPERTY_HOLDER & PROPERTY_HOLDER::operator= ( const PROPERTY_HOLDER other)
inline

Copy assignment operator.

Definition at line 114 of file property_holder.h.

References m_properties.

◆ operator=() [2/2]

PROPERTY_HOLDER & PROPERTY_HOLDER::operator= ( PROPERTY_HOLDER &&  other)
inlinenoexcept

Move assignment operator.

Definition at line 125 of file property_holder.h.

References m_properties.

◆ RemoveProperty()

bool PROPERTY_HOLDER::RemoveProperty ( const std::string &  aKey)
inline

Remove a property.

Parameters
keyThe property key
Returns
true if the property was removed, false if it didn't exist or object is invalid

Definition at line 305 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE(), and PROPERTY_MIXIN::RemoveProperty().

◆ SafeCast() [1/2]

static const PROPERTY_HOLDER * PROPERTY_HOLDER::SafeCast ( const void *  aPtr)
inlinestaticnoexcept

Safely cast a const void pointer to const PROPERTY_HOLDER*.

Parameters
ptrPointer to validate and cast
Returns
const PROPERTY_HOLDER* if valid, nullptr otherwise

Definition at line 177 of file property_holder.h.

References m_magic, and MAGIC_VALUE.

◆ SafeCast() [2/2]

static PROPERTY_HOLDER * PROPERTY_HOLDER::SafeCast ( void *  aPtr)
inlinestaticnoexcept

Safely cast a void pointer to PROPERTY_HOLDER*.

Parameters
ptrPointer to validate and cast
Returns
PROPERTY_HOLDER* if valid, nullptr otherwise

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().

◆ SafeDelete() [1/2]

static bool PROPERTY_HOLDER::SafeDelete ( PROPERTY_HOLDER aHolder)
inlinestaticnoexcept

Definition at line 215 of file property_holder.h.

◆ SafeDelete() [2/2]

static bool PROPERTY_HOLDER::SafeDelete ( void *  aPtr)
inlinestaticnoexcept

Safely delete a PROPERTY_HOLDER from client data.

Parameters
ptrPointer from client data to validate and delete
Returns
true if successfully deleted, false if invalid pointer

Definition at line 202 of file property_holder.h.

References SafeCast().

Referenced by BOOST_AUTO_TEST_CASE().

◆ SetProperty()

template<typename T >
bool PROPERTY_HOLDER::SetProperty ( const std::string &  aKey,
T &&  aValue 
)
inline

Set a property with the given key and value.

Template Parameters
TThe type of the value to store
Parameters
keyThe property key
valueThe value to store
Returns
true if property was set, false if object is invalid

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().

◆ SetTypedProperty()

template<PropertyValueType T>
bool PROPERTY_HOLDER::SetTypedProperty ( const std::string &  aKey,
T &&  aValue 
)
inline

Type-safe property setter that only accepts valid property types.

Definition at line 408 of file property_holder.h.

References SetProperty().

◆ Size()

size_t PROPERTY_HOLDER::Size ( ) const
inline

Get the number of stored properties.

Returns
The number of properties, or 0 if object is invalid

Definition at line 330 of file property_holder.h.

References IsValid(), and m_properties.

Referenced by BOOST_AUTO_TEST_CASE().

Member Data Documentation

◆ m_magic

uint64_t PROPERTY_HOLDER::m_magic
private

Magic value for memory validation.

Definition at line 414 of file property_holder.h.

Referenced by IsValid(), SafeCast(), and ~PROPERTY_HOLDER().

◆ m_properties

std::unordered_map<std::string, std::any> PROPERTY_HOLDER::m_properties
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().

◆ MAGIC_VALUE

constexpr uint64_t PROPERTY_HOLDER::MAGIC_VALUE = 0x50524F5048444C52ULL
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().


The documentation for this class was generated from the following file: