split property & values into separate classes and files
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
f38ebeab14
commit
e377340781
28 changed files with 700 additions and 269 deletions
25
include/ikarus/objects/properties/number_property.h
Normal file
25
include/ikarus/objects/properties/number_property.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
/// \file number_property.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup properties Properties
|
||||
/// \brief Number properties store a numeric value. (e.g. "Weight" or "Age")
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusNumberProperty;
|
||||
|
||||
IKA_API IkarusNumberProperty * ikarus_number_property_create(
|
||||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
struct IkarusPropertySource * property_source,
|
||||
struct IkarusNumberSettings * settings
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
125
include/ikarus/objects/properties/property.h
Normal file
125
include/ikarus/objects/properties/property.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#pragma once
|
||||
|
||||
/// \file property.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/objects/properties/property_type.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \defgroup properties Properties
|
||||
/// \brief Properties define the structure and types of data.
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief Properties are the placeholders of values for entities.
|
||||
/// \details Each entity can have any number of properties.
|
||||
/// Every property has a type that identifies the kind of data that can be put in.
|
||||
///
|
||||
/// The following types currently exist:
|
||||
/// - Toggle: A true/false boolean-like value
|
||||
/// - Number: An arbitrary numeric value
|
||||
/// - Text: An arbitrary textual value
|
||||
///
|
||||
/// Property Examples:
|
||||
/// - Is Dead (Toggle)
|
||||
/// - Age (Number)
|
||||
/// - ISBN (Text)
|
||||
///
|
||||
/// Every property has settings which can be used to customise the property further.
|
||||
/// Two settings that are shared among all properties are the following:
|
||||
/// - Multiple
|
||||
/// - Allow undefined
|
||||
///
|
||||
/// The former transforms a property into a list. Instead of one number, you could then specify a series of numbers.
|
||||
/// The latter allows you to specify an "unknown" value for a property.
|
||||
/// It might not be known if a character is dead or not for example.
|
||||
///
|
||||
/// Each entity associated with the property has a value for it.
|
||||
///
|
||||
/// Properties can also be added to blueprints in which case they are available for all entities associated with the
|
||||
/// blueprint.
|
||||
///
|
||||
/// We call properties within entities "Entity Properties" and properties within blueprints "Blueprint Properties".
|
||||
///
|
||||
/// \remark Properties are scoped to the blueprint or entity they are associated with.
|
||||
/// \remark Values for properties are lazily created as space saving measure.
|
||||
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
|
||||
/// This default value is specified when the property is created and can be updated later.
|
||||
/// \remark Properties' tree structures are scoped to the entity or blueprint they are associated with.
|
||||
struct IkarusProperty;
|
||||
|
||||
/// \brief Deletes a property.
|
||||
/// \param property The property to delete.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \remark The property must not be accessed after deletion.
|
||||
IKA_API void ikarus_property_delete(IkarusProperty * property);
|
||||
|
||||
/// \brief Gets the type info of a property.
|
||||
/// \param property The property to get the type info of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The type info of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property);
|
||||
|
||||
/// \brief Gets the settings of a property.
|
||||
/// \param property The property to get the settings of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The settings of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusPropertySettings * ikarus_property_get_settings(IkarusProperty * property);
|
||||
|
||||
/// \see ikarus_property_get_settings
|
||||
IKA_API struct IkarusPropertySettings const * ikarus_property_get_settings_const(IkarusProperty const * property);
|
||||
|
||||
/// \brief Gets the source of a property.
|
||||
/// \param property The property to get the source of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The source of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusPropertySource const * ikarus_property_get_source(IkarusProperty const * property);
|
||||
|
||||
/// \brief Visits a property. Calling the appropriate function for the property's type.
|
||||
/// \param property The property to visit.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param toggle_property The function to call if the property is a toggle property. Skipped if null.
|
||||
/// \param number_property The function to call if the property is a number property. Skipped if null.
|
||||
/// \param text_property The function to call if the property is a text property. Skipped if null.
|
||||
/// \param data The data to pass to the functions.
|
||||
IKA_API void ikarus_property_visit(
|
||||
IkarusProperty * property,
|
||||
void (*toggle_property)(struct IkarusToggleProperty *, void *),
|
||||
void (*number_property)(struct IkarusNumberProperty *, void *),
|
||||
void (*text_property)(struct IkarusTextProperty *, void *),
|
||||
void * data
|
||||
);
|
||||
|
||||
/// \see ikarus_property_visit
|
||||
IKA_API void ikarus_property_visit_const(
|
||||
IkarusProperty const * property,
|
||||
void (*toggle_property)(struct IkarusToggleProperty const *, void *),
|
||||
void (*number_property)(struct IkarusNumberProperty const *, void *),
|
||||
void (*text_property)(struct IkarusTextProperty const *, void *),
|
||||
void * data
|
||||
);
|
||||
|
||||
/// \brief Casts a property to an object.
|
||||
/// \param property The property to cast.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The property represented as an object or null if an error occurs.
|
||||
/// \remark This operation is guaranteed to be very fast and is intended to be used frequently.
|
||||
IKA_API struct IkarusObject * ikarus_property_to_object(IkarusProperty * property);
|
||||
|
||||
/// \see ikarus_property_to_object
|
||||
IKA_API struct IkarusObject const * ikarus_property_to_object_const(IkarusProperty const * property);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
// @}
|
||||
55
include/ikarus/objects/properties/property_source.h
Normal file
55
include/ikarus/objects/properties/property_source.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
/// \file property_source.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup properties Properties
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusPropertySource;
|
||||
|
||||
/// \brief Creates an blueprint property source.
|
||||
/// \param blueprint The blueprint to create the property source for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The created property source or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusPropertySource * ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint);
|
||||
|
||||
/// \brief Creates an entity property source.
|
||||
/// \param entity The entity to create the property source for.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The created property source or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusPropertySource * ikarus_property_source_create_entity(struct IkarusEntity * entity);
|
||||
|
||||
/// \brief Visits a property source, calling the appropriate callback.
|
||||
/// \param property_source The property source to visit.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \param blueprint_visitor The callback to call if the source is a blueprint, skipped if null.
|
||||
/// \param entity_visitor The callback to call if the source is an entity, skipped if null.
|
||||
/// \param user_data User data to pass to the callbacks.
|
||||
IKA_API void ikarus_property_source_visit(
|
||||
struct IkarusPropertySource * property_source,
|
||||
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
|
||||
void (*entity_visitor)(struct IkarusEntity *, void *),
|
||||
void * user_data
|
||||
);
|
||||
|
||||
/// \see ikarus_property_source_visit
|
||||
IKA_API void ikarus_property_source_visit_const(
|
||||
struct IkarusPropertySource const * property_source,
|
||||
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
|
||||
void (*entity_visitor)(struct IkarusEntity const *, void *),
|
||||
void * user_data
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
33
include/ikarus/objects/properties/property_type.h
Normal file
33
include/ikarus/objects/properties/property_type.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
/// \file property_type.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup properties Properties
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
/// \brief The type of a property.
|
||||
/// \details Designates the type of data stored by the property as well as which settings are
|
||||
/// available.
|
||||
enum IkarusPropertyType {
|
||||
/// \brief A true/false boolean-esque value.
|
||||
IkarusPropertyType_Toggle,
|
||||
/// \brief A numeric value, limited to IEEE 80 bit floating point numbers.
|
||||
IkarusPropertyType_Number,
|
||||
/// \brief An arbitrary UTF-8 textual value.
|
||||
IkarusPropertyType_Text,
|
||||
};
|
||||
|
||||
/// \brief Fetches the default value for a property type.
|
||||
/// \remark Not to be confused with the default value of a property. See ikarus_property_get_default_value
|
||||
/// \param type The property type.
|
||||
/// \return The default value for the property type or null if an error occurs.
|
||||
IKA_API struct IkarusValue * ikarus_property_type_get_default_default_value(IkarusPropertyType type);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
/// \file number_property_settings.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup property_settings PropertySettings
|
||||
/// \brief Number property settings add additional constraints to number properties.
|
||||
/// \details The following settings are available:
|
||||
///
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusNumberPropertySettings;
|
||||
|
||||
/// \brief Sets the default value for a number property.
|
||||
/// \param settings The number property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param default_value The default value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must be a valid value for the property.
|
||||
/// \remark The settings take ownership of the value, the caller must not free it.
|
||||
IKA_API void ikarus_number_property_settings_set_default_value(
|
||||
struct IkarusNumberPropertySettings * settings, struct IkarusNumberValue * default_value
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
#pragma once
|
||||
|
||||
/// \file property_settings.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \defgroup property_settings PropertySettings
|
||||
/// \brief Property settings add additional constraints to properties.
|
||||
/// \details Each property has a certain set of settings. The options available depend on the type of the property.
|
||||
/// Settings can be changed after the property has been created. Examples of settings are:
|
||||
/// Note that the default value must be set using the concrete subtypes to ascertain type correctness.
|
||||
/// - Minimum: The minimum value for a number property.
|
||||
/// - Matches: A regular expression that the value of a text property must match.
|
||||
/// There are also some common settings, shared among all properties:
|
||||
/// - Default Value (default: PropertyType's default default (sic) value): The value that is returned if no value is specified
|
||||
/// for some entity.
|
||||
/// - List (default: false): If set to true, the property becomes a list. Instead of one number, you could then specify a series
|
||||
/// of numbers. Note that each element in the list is subject to changes in values. E.g. when we say that all values are changed
|
||||
/// in some way (e.g. reset to the default value), this applies to all elements in the list.
|
||||
/// - Allow undefined (default: false): If set to true, you can specify an "unknown" value for a property.
|
||||
/// It might not be known if a character is dead or not for example.
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusPropertySettings;
|
||||
|
||||
/// \brief Gets the default value of a property.
|
||||
/// \param settings The settings to get the default value of.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must exist.
|
||||
/// \return The default value of the property or null if an error occurs.
|
||||
/// \remark Must be freed using #ikarus_free.
|
||||
IKA_API struct IkarusValue const * ikarus_property_settings_get_default_value(IkarusPropertySettings const * settings);
|
||||
|
||||
/// \brief Fetches whether a property is a list.
|
||||
/// \param settings The property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \return True if the property is a list, false otherwise.
|
||||
IKA_API bool ikarus_property_settings_is_list(IkarusPropertySettings const * settings);
|
||||
|
||||
/// \brief Sets whether a property is a list.
|
||||
/// \details Noop if unchanged. A change from list -> single truncates to just the first element. A change from single -> list
|
||||
/// sets the first element to the current value.
|
||||
/// \param settings The property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param list Whether the property should be
|
||||
/// a list.
|
||||
IKA_API void ikarus_property_settings_set_is_list(IkarusPropertySettings * settings, bool list);
|
||||
|
||||
/// \brief Fetches whether a property may be undefined.
|
||||
/// \param settings The property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \return True if the property may be undefined, false otherwise.
|
||||
IKA_API bool ikarus_property_settings_may_be_undefined(IkarusPropertySettings const * settings);
|
||||
|
||||
/// \brief Sets whether a property may be undefined.
|
||||
/// \details Noop if unchanged. If the transition is from undefined -> defined, all undefined values will be reset to the
|
||||
/// default value.
|
||||
/// \param settings The property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param allow_undefined Whether the property should be allowed to be undefined.
|
||||
/// \param allow_undefined Whether the property should be allowed to be undefined.
|
||||
IKA_API void ikarus_property_settings_set_may_be_undefined(IkarusPropertySettings * settings, bool allow_undefined);
|
||||
|
||||
/// \brief Visits a property settings. Calling the appropriate function for the property's type.
|
||||
/// \param settings The property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param toggle_property_visitor The function to call if the property is a toggle property. Skipped if null.
|
||||
/// \param number_property_visitor The function to call if the property is a number property. Skipped if null.
|
||||
/// \param text_property_visitor The function to call if the property is a text property. Skipped if null.
|
||||
/// \param data Data passed to the visitors.
|
||||
IKA_API void ikarus_property_settings_visit(
|
||||
struct IkarusPropertySettings * settings,
|
||||
void (*toggle_property_visitor)(struct IkarusTogglePropertySettings * settings, void * data),
|
||||
void (*number_property_visitor)(struct IkarusNumberPropertySettings * settings, void * data),
|
||||
void (*text_property_visitor)(struct IkarusTextPropertySettings * settings, void * data),
|
||||
void * data
|
||||
);
|
||||
|
||||
IKA_API void ikarus_property_settings_visit_const(
|
||||
struct IkarusPropertySettings const * settings,
|
||||
void (*toggle_property_visitor)(struct IkarusTogglePropertySettings const * settings, void * data),
|
||||
void (*number_property_visitor)(struct IkarusNumberPropertySettings const * settings, void * data),
|
||||
void (*text_property_visitor)(struct IkarusTextPropertySettings const * settings, void * data),
|
||||
void * data
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
/// \file text_property_settings.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup property_settings PropertySettings
|
||||
/// \brief Text property settings add additional constraints to text properties.
|
||||
/// \details The following settings are available:
|
||||
///
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusTextPropertySettings;
|
||||
|
||||
/// \brief Sets the default value for a text property.
|
||||
/// \param settings The text property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param default_value The default value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must be a valid value for the property.
|
||||
/// \remark The settings take ownership of the value, the caller must not free it.
|
||||
IKA_API void ikarus_text_property_settings_set_default_value(
|
||||
struct IkarusTextPropertySettings * settings, struct IkarusTextValue * default_value
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
/// \file toggle_property_settings.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup property_settings PropertySettings
|
||||
/// \brief Toggle property settings add additional constraints to toggle properties.
|
||||
/// \details The following settings are available:
|
||||
///
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusTogglePropertySettings;
|
||||
|
||||
/// \brief Sets the default value for a toggle property.
|
||||
/// \param settings The toggle property settings.
|
||||
/// \pre \li Must not be null.
|
||||
/// \param default_value The default value.
|
||||
/// \pre \li Must not be null.
|
||||
/// \pre \li Must be a valid value for the property.
|
||||
/// \remark The settings take ownership of the value, the caller must not free it.
|
||||
IKA_API void ikarus_toggle_property_settings_set_default_value(
|
||||
struct IkarusTogglePropertySettings * settings, struct IkarusToggleValue * default_value
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
25
include/ikarus/objects/properties/text_property.h
Normal file
25
include/ikarus/objects/properties/text_property.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
/// \file text_property.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup properties Properties
|
||||
/// \brief Text properties store an arbitrary piece of text. (e.g. "Firstname" or "Description")
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusTextProperty;
|
||||
|
||||
IKA_API IkarusTextProperty * ikarus_text_property_create(
|
||||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
struct IkarusPropertySource * property_source,
|
||||
struct IkarusTextSettings * settings
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
25
include/ikarus/objects/properties/toggle_property.h
Normal file
25
include/ikarus/objects/properties/toggle_property.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
/// \file toggle_property.h
|
||||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
|
||||
/// \addtogroup properties Properties
|
||||
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
|
||||
/// @{
|
||||
|
||||
IKARUS_BEGIN_HEADER
|
||||
|
||||
struct IkarusToggleProperty;
|
||||
|
||||
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
|
||||
struct IkarusProject * project,
|
||||
char const * name,
|
||||
struct IkarusPropertySource * property_source,
|
||||
struct IkarusToggleSettings * settings
|
||||
);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
/// @}
|
||||
Loading…
Add table
Add a link
Reference in a new issue