Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
prop.h File Reference

Type-agnotic property system. More...

#include <any>
#include <variant>
#include "cube.h"

Go to the source code of this file.

Classes

class  prop::PropertyMeta
 Meta information about a property. More...
 
class  prop::Property< PropertyMetaT >
 A property. More...
 

Typedefs

typedef std::variant< int, float, bvec, ivec, vec, std::string > prop::PropertyValue
 Storage for a property value.
 
typedef std::function< void(std::any argument)> prop::OnChangeCallback
 Callback type for property changes.
 

Enumerations

enum class  prop::PropertyType {
  NoType = -1 , Int , Float , Color ,
  IntVec , FloatVec , String , Count
}
 Type of a property. More...
 

Functions

template<typename PropertyT, std::size_t N>
PropertyT * prop::find_prop (std::string name, std::array< PropertyT, N > &props)
 Finds a property with the given name in the given array.
 
template<typename PropertyT, std::size_t N>
const PropertyT * prop::find_prop (std::string name, const std::array< PropertyT, N > &props)
 Finds a property with the given name in the given array.
 
template<typename PropertyT, std::size_t N>
bool prop::set_prop (std::string name, PropertyValue value, std::array< PropertyT, N > &props, std::any on_change_arg=std::any())
 Sets the value of a property with the given name in the given array.
 
template<typename PropertyMetaT, std::size_t N>
const PropertyMetaT * prop::find_prop_meta (std::string name, const std::array< PropertyMetaT, N > &prop_metas)
 Finds a property definition with the given name in the given array.
 
template<typename PropertyT, std::size_t N>
void prop::pack_props (const std::array< PropertyT, N > &props, std::vector< uint8_t > &buf)
 Packs the given properties into the given buffer.
 
template<typename PropertyT, std::size_t N>
size_t prop::unpack_props (const std::vector< uint8_t > &buf, std::array< PropertyT, N > &props)
 Unpacks the given buffer into the given properties.
 
template<std::size_t N, typename PropertyT, std::size_t... Is, typename PropertyMetaT>
std::array< PropertyT, N > prop::_make_props_array_impl (std::index_sequence< Is... >, const PropertyMetaT(&prop_meta)[N])
 
template<std::size_t N, typename PropertyT, std::size_t... Is, typename PropertyMetaT>
std::array< PropertyT, N > prop::make_props_array (const PropertyMetaT(&prop_meta)[N])
 Creates an array of properties from the given property definitions.
 

Detailed Description

Type-agnotic property system.

This file provides a type-agnostic property system. It is used to provide a generic interface for convenient property access for objects, entities and entire systems.

Typedef Documentation

◆ OnChangeCallback

typedef std::function<void(std::any argument)> prop::OnChangeCallback

Callback type for property changes.

Parameters
argument- The argument passed to the callback.

◆ PropertyValue

typedef std::variant<int, float, bvec, ivec, vec, std::string> prop::PropertyValue

Storage for a property value.

This type is used to store a property value. Supported types are: int, float, bvec, ivec, vec, std::string

Enumeration Type Documentation

◆ PropertyType

enum class prop::PropertyType
strong

Type of a property.

This enum is used to determine the type of a property. Mandates what sort of type is stored inside the PropertyValue.

Function Documentation

◆ find_prop() [1/2]

template<typename PropertyT, std::size_t N>
const PropertyT * prop::find_prop ( std::string name,
const std::array< PropertyT, N > & props )

Finds a property with the given name in the given array.

Template Parameters
PropertyT- Property class type
N- Size of the array
Parameters
name- The name of the property to find.
props- The array of properties to search.
Returns
PropertyT* - The property if found, nullptr otherwise.

◆ find_prop() [2/2]

template<typename PropertyT, std::size_t N>
PropertyT * prop::find_prop ( std::string name,
std::array< PropertyT, N > & props )

Finds a property with the given name in the given array.

Template Parameters
PropertyT- Property class type
N- Size of the array
Parameters
name- The name of the property to find.
props- The array of properties to search.
Returns
PropertyT* - The property if found, nullptr otherwise.

◆ find_prop_meta()

template<typename PropertyMetaT, std::size_t N>
const PropertyMetaT * prop::find_prop_meta ( std::string name,
const std::array< PropertyMetaT, N > & prop_metas )

Finds a property definition with the given name in the given array.

Template Parameters
PropertyMetaT- PropertyMeta class type
N- Size of the array
Parameters
name- The name of the property definition to find.
prop_metas- The array of property definitions to search.
Returns
const PropertyMetaT* - The property definition if found, nullptr otherwise.

◆ make_props_array()

template<std::size_t N, typename PropertyT, std::size_t... Is, typename PropertyMetaT>
std::array< PropertyT, N > prop::make_props_array ( const PropertyMetaT(&) prop_meta[N])

Creates an array of properties from the given property definitions.

Template Parameters
N- Size of the array
PropertyT- Property class type
Is- Index sequence
PropertyMetaT- PropertyMeta class type
Parameters
prop_meta- The array of property definitions to create properties from.
Returns
std::array<PropertyT, N> - The array of properties bound to meta information.

◆ pack_props()

template<typename PropertyT, std::size_t N>
void prop::pack_props ( const std::array< PropertyT, N > & props,
std::vector< uint8_t > & buf )

Packs the given properties into the given buffer.

Template Parameters
PropertyT- Property class type
N- Size of the array
Parameters
props- The array of properties to pack.
buf- The buffer to pack the properties into.

◆ set_prop()

template<typename PropertyT, std::size_t N>
bool prop::set_prop ( std::string name,
PropertyValue value,
std::array< PropertyT, N > & props,
std::any on_change_arg = std::any() )

Sets the value of a property with the given name in the given array.

Template Parameters
PropertyT- Property class type
N- Size of the array
Parameters
name- The name of the property to set.
value- The value to set the property to. Value is clamped to the property's min/max values, if applicable.
props- The array of properties to search.
on_change_arg- Optional argument to pass to the property's on_change callback.
Returns
true - The property was found and set.

◆ unpack_props()

template<typename PropertyT, std::size_t N>
size_t prop::unpack_props ( const std::vector< uint8_t > & buf,
std::array< PropertyT, N > & props )

Unpacks the given buffer into the given properties.

Template Parameters
PropertyT- Property class type
N- Size of the array
Parameters
buf- The buffer to unpack.
props- The array of properties to unpack into.
Returns
size_t - The number of properties unpacked.