Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Meta

Flecs reflection framework. More...

Classes

struct  EcsMetaType
 Component that is automatically added to every type with the right kind. More...
 
struct  EcsPrimitive
 
struct  EcsMember
 
struct  ecs_member_t
 Element type of members vector in EcsStruct. More...
 
struct  EcsStruct
 
struct  ecs_enum_constant_t
 
struct  EcsEnum
 
struct  ecs_bitmask_constant_t
 
struct  EcsBitmask
 
struct  EcsArray
 
struct  EcsVector
 
struct  ecs_serializer_t
 Serializer interface. More...
 
struct  EcsOpaque
 
struct  ecs_unit_translation_t
 
struct  EcsUnit
 
struct  EcsUnitPrefix
 
struct  ecs_meta_type_op_t
 
struct  EcsMetaTypeSerialized
 
struct  ecs_meta_scope_t
 
struct  ecs_meta_cursor_t
 Type that enables iterating/populating a value using reflection data. More...
 
struct  ecs_primitive_desc_t
 Used with ecs_primitive_init. More...
 
struct  ecs_enum_desc_t
 Used with ecs_enum_init. More...
 
struct  ecs_bitmask_desc_t
 Used with ecs_bitmask_init. More...
 
struct  ecs_array_desc_t
 Used with ecs_array_init. More...
 
struct  ecs_vector_desc_t
 Used with ecs_vector_init. More...
 
struct  ecs_struct_desc_t
 Used with ecs_struct_init. More...
 
struct  ecs_opaque_desc_t
 Used with ecs_opaque_init. More...
 
struct  ecs_unit_desc_t
 Used with ecs_unit_init. More...
 
struct  ecs_unit_prefix_desc_t
 Used with ecs_unit_prefix_init. More...
 

Macros

#define FLECS_META_H
 
#define ECS_MEMBER_DESC_CACHE_SIZE   (32)
 
#define ECS_META_MAX_SCOPE_DEPTH   (32) /* >32 levels of nesting is not sane */
 
#define ecs_primitive(world, ...)    ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )
 
#define ecs_enum(world, ...)    ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )
 
#define ecs_bitmask(world, ...)    ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )
 
#define ecs_array(world, ...)    ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )
 
#define ecs_vector(world, ...)    ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )
 
#define ecs_opaque(world, ...)    ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )
 
#define ecs_struct(world, ...)    ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )
 
#define ecs_unit(world, ...)    ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )
 
#define ecs_unit_prefix(world, ...)    ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )
 
#define ecs_quantity(world, ...)    ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
 

Typedefs

typedef bool ecs_bool_t
 Primitive type definitions. More...
 
typedef char ecs_char_t
 
typedef unsigned char ecs_byte_t
 
typedef uint8_t ecs_u8_t
 
typedef uint16_t ecs_u16_t
 
typedef uint32_t ecs_u32_t
 
typedef uint64_t ecs_u64_t
 
typedef uintptr_t ecs_uptr_t
 
typedef int8_t ecs_i8_t
 
typedef int16_t ecs_i16_t
 
typedef int32_t ecs_i32_t
 
typedef int64_t ecs_i64_t
 
typedef intptr_t ecs_iptr_t
 
typedef float ecs_f32_t
 
typedef double ecs_f64_t
 
typedef char * ecs_string_t
 
typedef enum ecs_type_kind_t ecs_type_kind_t
 Type kinds supported by reflection type system.
 
typedef struct EcsMetaType EcsMetaType
 Component that is automatically added to every type with the right kind.
 
typedef enum ecs_primitive_kind_t ecs_primitive_kind_t
 
typedef struct EcsPrimitive EcsPrimitive
 
typedef struct EcsMember EcsMember
 
typedef struct ecs_member_t ecs_member_t
 Element type of members vector in EcsStruct.
 
typedef struct EcsStruct EcsStruct
 
typedef struct ecs_enum_constant_t ecs_enum_constant_t
 
typedef struct EcsEnum EcsEnum
 
typedef struct ecs_bitmask_constant_t ecs_bitmask_constant_t
 
typedef struct EcsBitmask EcsBitmask
 
typedef struct EcsArray EcsArray
 
typedef struct EcsVector EcsVector
 
typedef struct ecs_serializer_t ecs_serializer_t
 Serializer interface.
 
typedef int(* ecs_meta_serialize_t) (const ecs_serializer_t *ser, const void *src)
 Callback invoked serializing an opaque type. More...
 
typedef struct EcsOpaque EcsOpaque
 
typedef struct ecs_unit_translation_t ecs_unit_translation_t
 
typedef struct EcsUnit EcsUnit
 
typedef struct EcsUnitPrefix EcsUnitPrefix
 
typedef enum ecs_meta_type_op_kind_t ecs_meta_type_op_kind_t
 
typedef struct ecs_meta_type_op_t ecs_meta_type_op_t
 
typedef struct EcsMetaTypeSerialized EcsMetaTypeSerialized
 
typedef struct ecs_meta_scope_t ecs_meta_scope_t
 
typedef struct ecs_meta_cursor_t ecs_meta_cursor_t
 Type that enables iterating/populating a value using reflection data.
 
typedef struct ecs_primitive_desc_t ecs_primitive_desc_t
 Used with ecs_primitive_init.
 
typedef struct ecs_enum_desc_t ecs_enum_desc_t
 Used with ecs_enum_init.
 
typedef struct ecs_bitmask_desc_t ecs_bitmask_desc_t
 Used with ecs_bitmask_init.
 
typedef struct ecs_array_desc_t ecs_array_desc_t
 Used with ecs_array_init.
 
typedef struct ecs_vector_desc_t ecs_vector_desc_t
 Used with ecs_vector_init.
 
typedef struct ecs_struct_desc_t ecs_struct_desc_t
 Used with ecs_struct_init.
 
typedef struct ecs_opaque_desc_t ecs_opaque_desc_t
 Used with ecs_opaque_init.
 
typedef struct ecs_unit_desc_t ecs_unit_desc_t
 Used with ecs_unit_init.
 
typedef struct ecs_unit_prefix_desc_t ecs_unit_prefix_desc_t
 Used with ecs_unit_prefix_init.
 

Enumerations

enum  ecs_type_kind_t {
  EcsPrimitiveType , EcsBitmaskType , EcsEnumType , EcsStructType ,
  EcsArrayType , EcsVectorType , EcsOpaqueType , EcsTypeKindLast = EcsOpaqueType
}
 Type kinds supported by reflection type system. More...
 
enum  ecs_primitive_kind_t {
  EcsBool = 1 , EcsChar , EcsByte , EcsU8 ,
  EcsU16 , EcsU32 , EcsU64 , EcsI8 ,
  EcsI16 , EcsI32 , EcsI64 , EcsF32 ,
  EcsF64 , EcsUPtr , EcsIPtr , EcsString ,
  EcsEntity , EcsPrimitiveKindLast = EcsEntity
}
 
enum  ecs_meta_type_op_kind_t {
  EcsOpArray , EcsOpVector , EcsOpOpaque , EcsOpPush ,
  EcsOpPop , EcsOpScope , EcsOpEnum , EcsOpBitmask ,
  EcsOpPrimitive , EcsOpBool , EcsOpChar , EcsOpByte ,
  EcsOpU8 , EcsOpU16 , EcsOpU32 , EcsOpU64 ,
  EcsOpI8 , EcsOpI16 , EcsOpI32 , EcsOpI64 ,
  EcsOpF32 , EcsOpF64 , EcsOpUPtr , EcsOpIPtr ,
  EcsOpString , EcsOpEntity , EcsMetaTypeOpKindLast = EcsOpEntity
}
 

Functions

FLECS_API const ecs_entity_t ecs_id (EcsMetaType)
 
FLECS_API const ecs_entity_t ecs_id (EcsMetaTypeSerialized)
 
FLECS_API const ecs_entity_t ecs_id (EcsPrimitive)
 
FLECS_API const ecs_entity_t ecs_id (EcsEnum)
 
FLECS_API const ecs_entity_t ecs_id (EcsBitmask)
 
FLECS_API const ecs_entity_t ecs_id (EcsMember)
 
FLECS_API const ecs_entity_t ecs_id (EcsStruct)
 
FLECS_API const ecs_entity_t ecs_id (EcsArray)
 
FLECS_API const ecs_entity_t ecs_id (EcsVector)
 
FLECS_API const ecs_entity_t ecs_id (EcsOpaque)
 
FLECS_API const ecs_entity_t ecs_id (EcsUnit)
 
FLECS_API const ecs_entity_t ecs_id (EcsUnitPrefix)
 
FLECS_API const ecs_entity_t ecs_id (ecs_bool_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_char_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_byte_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_u8_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_u16_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_u32_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_u64_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_uptr_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_i8_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_i16_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_i32_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_i64_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_iptr_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_f32_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_f64_t)
 
FLECS_API const ecs_entity_t ecs_id (ecs_string_t)
 
FLECS_API ecs_meta_cursor_t ecs_meta_cursor (const ecs_world_t *world, ecs_entity_t type, void *ptr)
 
FLECS_API void * ecs_meta_get_ptr (ecs_meta_cursor_t *cursor)
 Get pointer to current field.
 
FLECS_API int ecs_meta_next (ecs_meta_cursor_t *cursor)
 Move cursor to next field.
 
FLECS_API int ecs_meta_elem (ecs_meta_cursor_t *cursor, int32_t elem)
 Move cursor to a element.
 
FLECS_API int ecs_meta_member (ecs_meta_cursor_t *cursor, const char *name)
 Move cursor to member.
 
FLECS_API int ecs_meta_dotmember (ecs_meta_cursor_t *cursor, const char *name)
 Move cursor to member, supports dot-separated nested members.
 
FLECS_API int ecs_meta_push (ecs_meta_cursor_t *cursor)
 Push a scope (required/only valid for structs & collections)
 
FLECS_API int ecs_meta_pop (ecs_meta_cursor_t *cursor)
 Pop a struct or collection scope (must follow a push)
 
FLECS_API bool ecs_meta_is_collection (const ecs_meta_cursor_t *cursor)
 Is the current scope a collection?
 
FLECS_API ecs_entity_t ecs_meta_get_type (const ecs_meta_cursor_t *cursor)
 Get type of current element.
 
FLECS_API ecs_entity_t ecs_meta_get_unit (const ecs_meta_cursor_t *cursor)
 Get unit of current element.
 
FLECS_API const char * ecs_meta_get_member (const ecs_meta_cursor_t *cursor)
 Get member name of current member.
 
FLECS_API int ecs_meta_set_bool (ecs_meta_cursor_t *cursor, bool value)
 Set field with boolean value.
 
FLECS_API int ecs_meta_set_char (ecs_meta_cursor_t *cursor, char value)
 Set field with char value.
 
FLECS_API int ecs_meta_set_int (ecs_meta_cursor_t *cursor, int64_t value)
 Set field with int value.
 
FLECS_API int ecs_meta_set_uint (ecs_meta_cursor_t *cursor, uint64_t value)
 Set field with uint value.
 
FLECS_API int ecs_meta_set_float (ecs_meta_cursor_t *cursor, double value)
 Set field with float value.
 
FLECS_API int ecs_meta_set_string (ecs_meta_cursor_t *cursor, const char *value)
 Set field with string value.
 
FLECS_API int ecs_meta_set_string_literal (ecs_meta_cursor_t *cursor, const char *value)
 Set field with string literal value (has enclosing "")
 
FLECS_API int ecs_meta_set_entity (ecs_meta_cursor_t *cursor, ecs_entity_t value)
 Set field with entity value.
 
FLECS_API int ecs_meta_set_null (ecs_meta_cursor_t *cursor)
 Set field with null value.
 
FLECS_API int ecs_meta_set_value (ecs_meta_cursor_t *cursor, const ecs_value_t *value)
 Set field with dynamic value.
 
FLECS_API bool ecs_meta_get_bool (const ecs_meta_cursor_t *cursor)
 Get field value as boolean.
 
FLECS_API char ecs_meta_get_char (const ecs_meta_cursor_t *cursor)
 Get field value as char.
 
FLECS_API int64_t ecs_meta_get_int (const ecs_meta_cursor_t *cursor)
 Get field value as signed integer.
 
FLECS_API uint64_t ecs_meta_get_uint (const ecs_meta_cursor_t *cursor)
 Get field value as unsigned integer.
 
FLECS_API double ecs_meta_get_float (const ecs_meta_cursor_t *cursor)
 Get field value as float.
 
FLECS_API const char * ecs_meta_get_string (const ecs_meta_cursor_t *cursor)
 Get field value as string. More...
 
FLECS_API ecs_entity_t ecs_meta_get_entity (const ecs_meta_cursor_t *cursor)
 Get field value as entity. More...
 
FLECS_API double ecs_meta_ptr_to_float (ecs_primitive_kind_t type_kind, const void *ptr)
 Convert pointer of primitive kind to float.
 
FLECS_API ecs_entity_t ecs_primitive_init (ecs_world_t *world, const ecs_primitive_desc_t *desc)
 Create a new primitive type.
 
FLECS_API ecs_entity_t ecs_enum_init (ecs_world_t *world, const ecs_enum_desc_t *desc)
 Create a new enum type.
 
FLECS_API ecs_entity_t ecs_bitmask_init (ecs_world_t *world, const ecs_bitmask_desc_t *desc)
 Create a new bitmask type.
 
FLECS_API ecs_entity_t ecs_array_init (ecs_world_t *world, const ecs_array_desc_t *desc)
 Create a new array type.
 
FLECS_API ecs_entity_t ecs_vector_init (ecs_world_t *world, const ecs_vector_desc_t *desc)
 Create a new vector type.
 
FLECS_API ecs_entity_t ecs_struct_init (ecs_world_t *world, const ecs_struct_desc_t *desc)
 Create a new struct type.
 
FLECS_API ecs_entity_t ecs_opaque_init (ecs_world_t *world, const ecs_opaque_desc_t *desc)
 Create a new opaque type. More...
 
FLECS_API ecs_entity_t ecs_unit_init (ecs_world_t *world, const ecs_unit_desc_t *desc)
 Create a new unit.
 
FLECS_API ecs_entity_t ecs_unit_prefix_init (ecs_world_t *world, const ecs_unit_prefix_desc_t *desc)
 Create a new unit prefix.
 
FLECS_API ecs_entity_t ecs_quantity_init (ecs_world_t *world, const ecs_entity_desc_t *desc)
 Create a new quantity.
 
FLECS_API void FlecsMetaImport (ecs_world_t *world)
 

Variables

FLECS_API const ecs_entity_t EcsConstant
 
FLECS_API const ecs_entity_t EcsQuantity
 

Detailed Description

Flecs reflection framework.

Macro Definition Documentation

◆ ecs_array

#define ecs_array (   world,
  ... 
)     ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )

Definition at line 861 of file meta.h.

◆ ecs_bitmask

#define ecs_bitmask (   world,
  ... 
)     ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )

Definition at line 858 of file meta.h.

◆ ecs_enum

#define ecs_enum (   world,
  ... 
)     ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )

Definition at line 855 of file meta.h.

◆ ECS_MEMBER_DESC_CACHE_SIZE

#define ECS_MEMBER_DESC_CACHE_SIZE   (32)

Definition at line 78 of file meta.h.

◆ ECS_META_MAX_SCOPE_DEPTH

#define ECS_META_MAX_SCOPE_DEPTH   (32) /* >32 levels of nesting is not sane */

Definition at line 476 of file meta.h.

◆ ecs_opaque

#define ecs_opaque (   world,
  ... 
)     ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )

Definition at line 867 of file meta.h.

◆ ecs_primitive

#define ecs_primitive (   world,
  ... 
)     ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )

Definition at line 852 of file meta.h.

◆ ecs_quantity

#define ecs_quantity (   world,
  ... 
)     ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )

Definition at line 879 of file meta.h.

◆ ecs_struct

#define ecs_struct (   world,
  ... 
)     ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )

Definition at line 870 of file meta.h.

◆ ecs_unit

#define ecs_unit (   world,
  ... 
)     ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )

Definition at line 873 of file meta.h.

◆ ecs_unit_prefix

#define ecs_unit_prefix (   world,
  ... 
)     ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )

Definition at line 876 of file meta.h.

◆ ecs_vector

#define ecs_vector (   world,
  ... 
)     ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )

Definition at line 864 of file meta.h.

◆ FLECS_META_H

#define FLECS_META_H

Definition at line 72 of file meta.h.

Typedef Documentation

◆ ecs_bool_t

typedef bool ecs_bool_t

Primitive type definitions.

These typedefs allow the builtin primitives to be used as regular components: ecs_set(world, e, ecs_i32_t, {10});

Or a more useful example (create an enum constant with a manual value): ecs_set_pair_object(world, e, EcsConstant, ecs_i32_t, {10});

Definition at line 87 of file meta.h.

◆ ecs_byte_t

typedef unsigned char ecs_byte_t

Definition at line 89 of file meta.h.

◆ ecs_char_t

typedef char ecs_char_t

Definition at line 88 of file meta.h.

◆ ecs_f32_t

typedef float ecs_f32_t

Definition at line 100 of file meta.h.

◆ ecs_f64_t

typedef double ecs_f64_t

Definition at line 101 of file meta.h.

◆ ecs_i16_t

typedef int16_t ecs_i16_t

Definition at line 96 of file meta.h.

◆ ecs_i32_t

typedef int32_t ecs_i32_t

Definition at line 97 of file meta.h.

◆ ecs_i64_t

typedef int64_t ecs_i64_t

Definition at line 98 of file meta.h.

◆ ecs_i8_t

typedef int8_t ecs_i8_t

Definition at line 95 of file meta.h.

◆ ecs_iptr_t

typedef intptr_t ecs_iptr_t

Definition at line 99 of file meta.h.

◆ ecs_meta_serialize_t

typedef int(* ecs_meta_serialize_t) (const ecs_serializer_t *ser, const void *src)

Callback invoked serializing an opaque type.

Pointer to value to serialize

Definition at line 314 of file meta.h.

◆ ecs_string_t

typedef char* ecs_string_t

Definition at line 102 of file meta.h.

◆ ecs_u16_t

typedef uint16_t ecs_u16_t

Definition at line 91 of file meta.h.

◆ ecs_u32_t

typedef uint32_t ecs_u32_t

Definition at line 92 of file meta.h.

◆ ecs_u64_t

typedef uint64_t ecs_u64_t

Definition at line 93 of file meta.h.

◆ ecs_u8_t

typedef uint8_t ecs_u8_t

Definition at line 90 of file meta.h.

◆ ecs_uptr_t

typedef uintptr_t ecs_uptr_t

Definition at line 94 of file meta.h.

Enumeration Type Documentation

◆ ecs_meta_type_op_kind_t

Enumerator
EcsOpScope 

Marks last constant that can open/close a scope.

EcsOpPrimitive 

Marks first constant that's a primitive.

Definition at line 423 of file meta.h.

◆ ecs_primitive_kind_t

enum ecs_primitive_kind_t

Definition at line 160 of file meta.h.

◆ ecs_type_kind_t

Type kinds supported by reflection type system.

Definition at line 140 of file meta.h.

Function Documentation

◆ ecs_meta_get_entity()

FLECS_API ecs_entity_t ecs_meta_get_entity ( const ecs_meta_cursor_t cursor)

Get field value as entity.

This operation does not perform conversions.

◆ ecs_meta_get_string()

FLECS_API const char * ecs_meta_get_string ( const ecs_meta_cursor_t cursor)

Get field value as string.

This operation does not perform conversions. If the field is not a string, this operation will fail.

◆ ecs_opaque_init()

FLECS_API ecs_entity_t ecs_opaque_init ( ecs_world_t world,
const ecs_opaque_desc_t desc 
)

Create a new opaque type.

Opaque types are types of which the layout doesn't match what can be modelled with the primitives of the meta framework, but which have a structure that can be described with meta primitives. Typical examples are STL types such as std::string or std::vector, types with a nontrivial layout, and types that only expose getter/setter methods.

An opaque type is a combination of a serialization function, and a handle to a meta type which describes the structure of the serialized output. For example, an opaque type for std::string would have a serializer function that accesses .c_str(), and with type ecs_string_t.

The serializer callback accepts a serializer object and a pointer to the value of the opaque type to be serialized. The serializer has two methods:

  • value, which serializes a value (such as .c_str())
  • member, which specifies a member to be serialized (in the case of a struct)