Tutorial

What is a property:

A property is a generic interface to manage parameter of a class whithout redeclare all the time the setter and getter (that is a little boring)

Calling a property car mermit to be notify when the value change and to control the values range of list ...

A property can use agreator interface eproperty::interface that declare a **"properties"** variablke that permit to acces at all the property declared.

Declare a class that have this interface:

class sampleClassGroup : public eproperty::Interface {

Declare property:

We have some basic properties:

Declare a Value property:

Do the correct include:

Declare your property:

Construct the property with eproperty::Interface:

propertyValue(this, "value", "default value", "optionnal Description", &sampleClassGroup::onPropertyChangeValue),

Construct the property with NO eproperty::Interface:

propertyValue("default value"),

Configure your property:

myClass.propertyValue.set("New Value");
myClass.propertyValue.setString("New Value 2");

Use your property:

TEST_INFO(" value:" << *propertyValue);

Declare a Range property:

Do the correct include:

Declare your property:

eproperty::Range<int32_t> propertyRange;

Construct the property with eproperty::Interface:

propertyRange(this, "range", 5646546, -5, 555555555) {

Construct the property with NO eproperty::Interface:

propertyRange(5646546, -5, 555555555) {

Configure your property:

myClass.propertyRange.set(15621);
myClass.propertyRange.setString("15621");

Use your property:

TEST_INFO(" range:" << *propertyRange);

Declare a List property:

Do the correct include:

Declare your property:

Construct the property with eproperty::Interface:

propertyList(this, "list", simpleEnum_enum4),

Construct the property with NO eproperty::Interface:

propertyList(simpleEnum_enum4),

Special case for the List is adding the value with their string assiciated:

propertyList.add(simpleEnum_enum1, "enum1");
propertyList.add(simpleEnum_enum2, "enum2");
propertyList.add(simpleEnum_enum3, "enum3");
propertyList.add(simpleEnum_enum4, "enum4");

Configure your property:

myClass.propertyList.set(simpleEnum_enum3);
myClass.propertyList.setString("enum3");

Use your property:

TEST_INFO(" list:" << *propertyList);

Particularity:

Define a callback:

All property can define a callback, it is used to update class property with special settings.

The callback is set in the construction instruction like:

propertyValue(this, "value", "default value", "optionnal Description", &sampleClassGroup::onPropertyChangeValue),

The fucntion define is like:

void onPropertyChangeValue() {
TEST_PRINT("Property value has change ... " << *propertyValue);
TEST_INFO("Use properties:");
TEST_INFO(" value:" << *propertyValue);
TEST_INFO(" range:" << *propertyRange);
TEST_INFO(" list:" << *propertyList);
}

It is called every time the Value change, if the value is identical the callback is not called.

Set value without calling the callback:

To set a value in a property without calling the nitifiction function, you might use:

// no check on the value set (the faster in CPU cycle)
propertyValue.setDirect("New Value to Set");
// Check the internal value (better for range)
propertyRange.setDirectCheck(-5555);

Please do not use it ouside the internal class that define the peoperty (call me if you have an api to control it at the compilation time)

Heritage and callback:

When you herit from an other class with theire property you can prefer changing the default value or set an other list of parameter.

To set value without calling the callback (that can be virtual then ==0 in the initialisation state), you need to call:

// no check on the value set (the faster in CPU cycle)
propertyValue.setDirect("New Value to Set");
// Check the internal value (better for range)
propertyRange.setDirectCheck(-5555);

For the eproperty::List, you chan rename enumeration or remove values:

// Rename an element
propertyList.rename("enum1", "new enum name");
// Remove an element
propertyList.remove("enum2");

All sample Code:

This Will generate this simple sample code:

enum simpleEnum {
simpleEnum_enum1,
simpleEnum_enum2,
simpleEnum_enum3,
simpleEnum_enum4,
};
class sampleClassGroup : public eproperty::Interface {
public:
eproperty::Range<int32_t> propertyRange;
sampleClassGroup():
propertyValue(this, "value", "default value", "optionnal Description", &sampleClassGroup::onPropertyChangeValue),
propertyList(this, "list", simpleEnum_enum4),
propertyRange(this, "range", 5646546, -5, 555555555) {
// add all enumeration values
propertyList.add(simpleEnum_enum1, "enum1");
propertyList.add(simpleEnum_enum2, "enum2");
propertyList.add(simpleEnum_enum3, "enum3");
propertyList.add(simpleEnum_enum4, "enum4");
// Rename an element
propertyList.rename("enum1", "new enum name");
// Remove an element
propertyList.remove("enum2");
// no check on the value set (the faster in CPU cycle)
propertyValue.setDirect("New Value to Set");
// Check the internal value (better for range)
propertyRange.setDirectCheck(-5555);
}
void onPropertyChangeValue() {
TEST_PRINT("Property value has change ... " << *propertyValue);
TEST_INFO("Use properties:");
TEST_INFO(" value:" << *propertyValue);
TEST_INFO(" range:" << *propertyRange);
TEST_INFO(" list:" << *propertyList);
}
};
class sampleClassSolo {
public:
sampleClassSolo():
propertyValue("default value"),
propertyList(simpleEnum_enum4),
propertyRange(5646546, -5, 555555555) {
propertyList.add(simpleEnum_enum1, "enum1");
propertyList.add(simpleEnum_enum2, "enum2");
propertyList.add(simpleEnum_enum3, "enum3");
propertyList.add(simpleEnum_enum4, "enum4");
}
};
void simpleSet() {
sampleClassGroup myClass;
myClass.propertyValue.set("New Value");
myClass.propertyValue.setString("New Value 2");
myClass.propertyList.set(simpleEnum_enum3);
myClass.propertyList.setString("enum3");
myClass.propertyRange.set(15621);
myClass.propertyRange.setString("15621");
myClass.properties.set("value", "New Value in string");
myClass.properties.set("list", "enum4");
myClass.properties.set("range", "-2");
}