CHFL_PROPERTY

typedef struct CHFL_PROPERTY CHFL_PROPERTY

This class holds the data used in properties in CHFL_FRAME and CHFL_ATOM. A property can have various types: bool, double, string or chfl_vector3d.

Here is the full list of functions acting on CHFL_PROPERTY:


CHFL_PROPERTY *chfl_property_bool(bool value)

Create a new property holding a boolean value.

The caller of this function should free the allocated memory using chfl_free.

CHFL_PROPERTY* property = chfl_property_bool(true);

bool value = false;
chfl_property_get_bool(property, &value);
assert(value == true);

chfl_free(property);
Return
A pointer to the property, or NULL in case of error. You can use chfl_last_error to learn about the error.

CHFL_PROPERTY *chfl_property_double(double value)

Create a new property holding a double value.

The caller of this function should free the allocated memory using chfl_free.

CHFL_PROPERTY* property = chfl_property_double(256);

double value = 0;
chfl_property_get_double(property, &value);
assert(value == 256);

chfl_free(property);
Return
A pointer to the property, or NULL in case of error. You can use chfl_last_error to learn about the error.

CHFL_PROPERTY *chfl_property_string(const char *value)

Create a new property holding a string value.

The caller of this function should free the allocated memory using chfl_free.

CHFL_PROPERTY* property = chfl_property_string("a great property");

char value[32];
chfl_property_get_string(property, value, sizeof(value));
assert(strcmp(value, "a great property") == 0);

chfl_free(property);
Return
A pointer to the property, or NULL in case of error. You can use chfl_last_error to learn about the error.

CHFL_PROPERTY *chfl_property_vector3d(const chfl_vector3d value)

Create a new property holding a 3D vector value.

The caller of this function should free the allocated memory using chfl_free.

CHFL_PROPERTY* property = chfl_property_vector3d((chfl_vector3d){2, 3.2, -1});

chfl_vector3d value = {0};
chfl_property_get_vector3d(property, value);
assert(fabs(value[0] - 2) < 1e-12);
assert(fabs(value[1] - 3.2) < 1e-12);
assert(fabs(value[2] - -1) < 1e-12);

chfl_free(property);
Return
A pointer to the property, or NULL in case of error. You can use chfl_last_error to learn about the error.

chfl_status chfl_property_get_kind(const CHFL_PROPERTY *property, chfl_property_kind *kind)

Get the type of value holded by this property in kind.

CHFL_PROPERTY* property = chfl_property_double(256);

chfl_property_kind kind;
chfl_property_get_kind(property, &kind);
assert(kind == CHFL_PROPERTY_DOUBLE);

chfl_free(property);
Return
The operation status code. You can use chfl_last_error to learn about the error if the status code is not CHFL_SUCCESS.

chfl_status chfl_property_get_bool(const CHFL_PROPERTY *property, bool *value)

Get the boolean value holded by this property in the location pointed to by value.

This function returns CHFL_PROPERTY_ERROR if the property is not a boolean property.

CHFL_PROPERTY* property = chfl_property_bool(true);

bool value = false;
chfl_property_get_bool(property, &value);
assert(value == true);

chfl_free(property);
Return
The operation status code. You can use chfl_last_error to learn about the error if the status code is not CHFL_SUCCESS.

chfl_status chfl_property_get_double(const CHFL_PROPERTY *property, double *value)

Get the double value holded by this property in the location pointed to by value.

This function returns CHFL_PROPERTY_ERROR if the property is not a double property.

CHFL_PROPERTY* property = chfl_property_double(256);

double value = 0;
chfl_property_get_double(property, &value);
assert(value == 256);

chfl_free(property);
Return
The operation status code. You can use chfl_last_error to learn about the error if the status code is not CHFL_SUCCESS.

chfl_status chfl_property_get_string(const CHFL_PROPERTY *property, char *buffer, uint64_t buffsize)

Get the string value holded by this property in the given buffer.

This function returns CHFL_PROPERTY_ERROR if the property is not a sring property.

The buffer size must be passed in buffsize. This function will truncate the property to fit in the buffer.

CHFL_PROPERTY* property = chfl_property_string("a great property");

char value[32];
chfl_property_get_string(property, value, sizeof(value));
assert(strcmp(value, "a great property") == 0);

chfl_free(property);
Return
The operation status code. You can use chfl_last_error to learn about the error if the status code is not CHFL_SUCCESS.

chfl_status chfl_property_get_vector3d(const CHFL_PROPERTY *property, chfl_vector3d value)

Get the 3D vector value holded by this property in the location pointed to by value.

This function returns CHFL_PROPERTY_ERROR if the property is not a 3D vector property.

CHFL_PROPERTY* property = chfl_property_vector3d((chfl_vector3d){2, 3.2, -1});

chfl_vector3d value = {0};
chfl_property_get_vector3d(property, value);
assert(fabs(value[0] - 2) < 1e-12);
assert(fabs(value[1] - 3.2) < 1e-12);
assert(fabs(value[2] - -1) < 1e-12);

chfl_free(property);
Return
The operation status code. You can use chfl_last_error to learn about the error if the status code is not CHFL_SUCCESS.