KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PropertyValueType Concept Reference

A C++20 property system for arbitrary key-value storage with type safety. More...

#include <property_holder.h>

Concept definition

template<typename T>
concept PropertyValueType = std::copy_constructible<T> && std::destructible<T>
A C++20 property system for arbitrary key-value storage with type safety.

Detailed Description

A C++20 property system for arbitrary key-value storage with type safety.

This class provides a flexible way to store arbitrary typed properties using string keys. It supports type-safe getters/setters with automatic type checking and optional default values.

Example usage:

// Setting properties
props.SetProperty("persist", true);
props.SetProperty("max_width", 500);
props.SetProperty("label", std::string("My Label"));
// Getting properties with type checking
if (auto persist = props.GetProperty<bool>("persist")) {
std::cout << "Persist: " << *persist << std::endl;
}
// Getting with default value
bool shouldPersist = props.GetPropertyOr("persist", false);
int width = props.GetPropertyOr("max_width", 100);
// Checking existence
if (props.HasProperty("label")) {
// Property exists
}
// Removing properties
props.RemoveProperty("label");
props.Clear();
bool SetProperty(const std::string &aKey, T &&aValue)
Set a property with the given key and value.
bool RemoveProperty(const std::string &aKey)
Remove a property.
std::optional< T > GetProperty(const std::string &aKey) const
Get a property value with type checking.
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 Clear()
Clear all properties.

Concept for types that can be used as property values

Definition at line 77 of file property_holder.h.