Skip to content

Properties & Rich Metadata System in uprops

Core Class Hierarchy

The core property hierarchy in uprops is defined under src/Core/uprops/:

uprops::PropertyBase (Abstract Base Interface)
  │
  ├── uprops::IProperty<T> (Typed Template Interface)
  │     ├── uprops::Property<T> (Direct Value / Pointer Storage)
  │     │     └── uprops::EnumProperty (Specialized for Enums & Labels)
  │     └── uprops::FunctionalProperty<T> (Getter / Setter Lambda Wrappers)
  │
  └── uprops::PropertyContainer (Collection Manager for Properties)

PropertyBase Interface

PropertyBase.h provides a uniform type-erased interface for inspecting any property across any subsystem:

namespace uprops {

class PropertyBase {
public:
    virtual ~PropertyBase() {}

    // Identification & Type Metadata
    virtual const std::string& GetName() const = 0;
    virtual const char* GetTypeName() const = 0;
    virtual std::type_index GetTypeIndex() const = 0;
    virtual std::string GetValueAsString() const = 0;
    virtual std::string GetQualifiedName() const; // Group + "." + Name

    // Units & Grouping
    virtual const std::string& GetUnits() const = 0;
    virtual void SetUnits(const std::string& units) = 0;
    virtual const std::string& GetGroup() const = 0;
    virtual void SetGroup(const std::string& group) = 0;

    // Constraints & State
    virtual bool HasRange() const;
    virtual double GetMin() const;
    virtual double GetMax() const;
    virtual bool HasDefault() const;
    virtual std::string GetDefaultValueAsString() const;
    virtual bool IsReadOnly() const = 0;

    // Enum Metadata
    virtual const std::vector<std::string>& GetEnumLabels() const;

    // Signal Notification Trigger
    virtual void PropertyUpdated();
};

} // namespace uprops

Property Types

1. Property<T>

Direct value property storing a pointer to a member variable or allocating internal storage:

uprops::Property<float> Mass(&container, "Mass", 10.0f, "kg", "Physics");
Mass.SetRange(0.0f, 1000.0f);
Mass.Set(15.5f); // Automatically triggers PropertyUpdated() and publishes signal

2. FunctionalProperty<T>

Lambda-backed property wrapping getters and setters without requiring direct variable storage:

uprops::FunctionalProperty<Vector3f> Position(
    &container, 
    "Position",
    [this](){ return this->GetPosition(); },
    [this](const Vector3f& v){ this->SetPosition(v); },
    "m",
    "Transform"
);

3. EnumProperty

Specialized property for enumerations with string labels:

std::vector<std::string> axes = {"X", "Y", "Z"};
uprops::EnumProperty Axis(&container, "Axis", &m_axisInt, axes, "", "Geometry");

Human Readable Properties (HRP) & Metadata Wrappers

Serializable.h defines HRP wrappers (hrp<T>, hrp_val<T>, hrp_enum<T>, hrp_enum_val<T>) that attach metadata during serialization or stream encoding.

HRP Wrapper API

// Creating an HRP wrapper for a variable
auto p = uprops::serialization::make_hrp("Radius", radiusVar, "m");
p.range(0.1, 50.0).set_default(1.0);

// Creating an HRP wrapper for an enum
auto e = uprops::serialization::make_hrp_enum("Axis", axisVar, {"X", "Y", "Z"});

HRP Macros

// General HRP Macros
#define HRP(data)                                    // Name = "data", Value = data
#define HRP2(name, data)                             // Name = name, Value = data
#define HRP3(name, data, units)                      // Name, Value, Units
#define HRP4(name, data, units, default)             // Name, Value, Units, Default
#define HRP5(name, data, units, min, max)            // Name, Value, Units, Min, Max
#define HRP6(name, data, units, default, min, max)   // Full metadata wrapper
#define HRPE(name, data, labels)                     // Enum metadata wrapper

PropertyContainer

PropertyContainer.h manages an ordered collection of properties for any object:

class PropertyContainer {
public:
    void RegisterProperty(PropertyBase* prop);
    void RegisterDisplayProperty(PropertyBase* prop);

    const std::vector<PropertyBase*>& GetProperties() const;
    const std::vector<PropertyBase*>& GetDisplayProperties() const;
    PropertyBase* GetProperty(const std::string& name) const;

    void NotifyPropertiesUpdated(); // Triggers PropertyUpdated() on all registered properties
};