1.6 KiB
1.6 KiB
Skill: Core Object & Property System
This skill defines the patterns for implementing and working with the uLib core object model.
Context
- Base Class:
uLib::Object - Property System:
uLib::Property<T> - Registration: All objects must register their properties for UI visibility and serialization.
Implementation Patterns
1. Defining an Object
Inherit from uLib::Object and use the ULIB_PROPERTY macro for members.
class MyObject : public uLib::Object {
public:
ULIB_PROPERTY(double, Speed, 0.0)
ULIB_PROPERTY(std::string, Description, "None")
MyObject() {
// Required for property visibility in PropertyEditor
ULIB_ACTIVATE_PROPERTIES(*this)
}
};
2. Property Access
Properties can be treated like their underlying types or accessed via .Get()/.Set().
obj.Speed = 10.5; // Triggers Updated() signal
double s = obj.Speed; // Implicit conversion
obj.Speed.SetRange(0.0, 100.0); // Setting metadata
3. Serialization
Implement serialize overloads for different archive types. Use hrp (Human Readable Property) to name fields.
template <class ArchiveT>
void serialize(ArchiveT &ar, const unsigned int version) {
ar & boost::serialization::make_nvp("InstanceName", this->GetInstanceName());
ar & boost::serialization::make_hrp("Speed", Speed, "m/s");
}
Checklist
- Inherit from
uLib::Object. - Use
ULIB_PROPERTYfor members that should appear in the GUI. - Call
ULIB_ACTIVATE_PROPERTIESin the constructor. - Implement
serializeif persistence is required.