Skip to main content

Reflection

Last Updated Time: 09/05/2023

Reflection Mark Macros Headers

public/macros_reflection.h

Any type that needs to generate reflection information must contain this header, which defines the macro to be used in the generation phase of the reflection.

reflection_test_define.h

#ifndef _REFLECTION_TEST_DEFINE_H
#define _REFLECTION_TEST_DEFINE_H

#include "../public/i_entity.h"
#include "../public/i_interface.h"
#include "../utils/pod_traits.h"

#include "../public/macros_reflection.h"

typedef int int8;

namespace flexi
{
enum EnumTest
{
A,
B,
C,
D,
E,
F,
G,
}FX_ENUM();
}

Reflection Mark Macros

Interface Type Reflection Mark Macro

Any interface type in need of reflection should mark FX_INTERFACE () after its definition.

reflection_test_define.h

    FX_PROPERTY() 
float y;
}FX_CLASS();

class TestInterface : public IInterface
{
public:
virtual bool Init() override
{
return true;
}

virtual bool Shut() override
{
return true;
}
}FX_INTERFACE();

Entity Type Reflection Mark Macro

Any entity type in need of reflection should mark FX_ENTITY() after its definition.

relection_test_define.h

    }
}FX_INTERFACE();

class TestEntity : public IEntity
{
public:
virtual bool Init(const IVarList& args) override
{
return true;
}

virtual bool Shut() override
{
return true;
}

FX_METHOD()
float TestMethod(FX_META(Type=double) float x, float y)
{
return x + y;
}
}FX_ENTITY();

Meta Supported:

  1. Parent=MyBaseEntity (key–value pair)

Description: optional, to specify MyBaseEntity as its parent type.

(1)scene_trace_adapter.h

class TraceQueryFilter;

class SceneTraceAdapter : public ITraceAdapter
{
public:
SceneTraceAdapter();
~SceneTraceAdapter();

virtual bool Init(const IVarList& args) override;
virtual bool Shut() override;

virtual void SetAdapteeID(const PERSISTID& adaptee_id) override;

virtual bool TraceDetail(CXMVECTOR src, CXMVECTOR dir,
dx_trace_info_t& result) override;
virtual bool TraceHitted(CXMVECTOR src, CXMVECTOR dir) override;
virtual bool TraceSphere(CXMVECTOR center, float radius) override;

FX_METHOD()
void SetTraceMask(const char* type, bool mask);

private:
LScene* m_pScene;

TraceQueryFilter* m_pFilter;
}FX_ENTITY();

#endif // _SCENE_TRACE_ADAPTER_H

scene_trace_adapter_gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H
#define REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H


DECLARE_ENTITY("", SceneTraceAdapter, ITraceAdapter)
DECLARE_METHOD_VOID_2(SceneTraceAdapter, SetTraceMask, const char *, bool)


#endif //REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H

(2)scene_trace_adapter.h

class TraceQueryFilter;

class SceneTraceAdapter : public ITraceAdapter
{
public:
SceneTraceAdapter();
~SceneTraceAdapter();

virtual bool Init(const IVarList& args) override;
virtual bool Shut() override;

virtual void SetAdapteeID(const PERSISTID& adaptee_id) override;

virtual bool TraceDetail(CXMVECTOR src, CXMVECTOR dir,
dx_trace_info_t& result) override;
virtual bool TraceHitted(CXMVECTOR src, CXMVECTOR dir) override;
virtual bool TraceSphere(CXMVECTOR center, float radius) override;

FX_METHOD()
void SetTraceMask(const char* type, bool mask);

private:
LScene* m_pScene;

TraceQueryFilter* m_pFilter;
}FX ENTITY(Parent=IEntify);

scene_trace_adapter_gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H
#define REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H


DECLARE_ENTITY("", SceneTraceAdapter, IEntify)
DECLARE_METHOD_VOID_2(SceneTraceAdapter, SetTraceMask, const char *, bool)


#endif //REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H
  1. IsAbstract (key)

Description: optional, to decide whether it is an abstract type.

(1)scene_trace_adapter.h

class TraceQueryFilter;

class SceneTraceAdapter : public ITraceAdapter
{
public:
SceneTraceAdapter();
~SceneTraceAdapter();

virtual bool Init(const IVarList& args) override;
virtual bool Shut() override;

virtual void SetAdapteeID(const PERSISTID& adaptee_id) override;

virtual bool TraceDetail(CXMVECTOR src, CXMVECTOR dir,
dx_trace_info_t& result) override;
virtual bool TraceHitted(CXMVECTOR src, CXMVECTOR dir) override;
virtual bool TraceSphere(CXMVECTOR center, float radius) override;

FX_METHOD()
void SetTraceMask(const char* type, bool mask);

private:
LScene* m_pScene;

TraceQueryFilter* m_pFilter;
}FX_ENTITY();

scene_trace_adapter_gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H
#define REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H


DECLARE_ENTITY("", SceneTraceAdapter, ITraceAdapter)
DECLARE_METHOD_VOID_2(SceneTraceAdapter, SetTraceMask, const char *, bool)


#endif //REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H

(2)scene_trace_adapter.h

class TraceQueryFilter;

class SceneTraceAdapter : public ITraceAdapter
{
public:
SceneTraceAdapter();
~SceneTraceAdapter();

virtual bool Init(const IVarList& args) override;
virtual bool Shut() override;

virtual void SetAdapteeID(const PERSISTID& adaptee_id) override;

virtual bool TraceDetail(CXMVECTOR src, CXMVECTOR dir,
dx_trace_info_t& result) override;
virtual bool TraceHitted(CXMVECTOR src, CXMVECTOR dir) override;
virtual bool TraceSphere(CXMVECTOR center, float radius) override;

FX_METHOD()
void SetTraceMask(const char* type, bool mask);

private:
LScene* m_pScene;

TraceQueryFilter* m_pFilter;
}FX_ENTITY(IsAbstract);

#endif // _SCENE_TRACE_ADAPTER_H

scene_trace_adapter_gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H
#define REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H



DECLARE_ABSTRACT_ENTITY("", SceneTraceAdapter, ITraceAdapter)
DECLARE_METHOD_VOID_2(SceneTraceAdapter, SetTraceMask, const char *, bool)



#endif //REFLANG_METADATA_CODE_GEN_EDITOR_SCENE_TRACE_ADAPTER_GEN_H

Class Type Reflection Mark Macro

Any class type in need of reflection should mark FX_CLASS () after its definition.

reflection_test_define.h

class ClassTest
{
public:
ClassTest()
{
x = 0.0;
y = 0.0;
}

private:
FX_PROPERTY()
float x;
FX_PROPERTY()
float y;
}FX_CLASS();

Meta Supported:

  1. Parent=MyBaseClass (key–value pair)

Description: optional, to specify MyBaseClass as its parent type.

(1)test_ref.h

#ifndef _TEST_REF_H
#define _TEST_REF_H

#include "flexi/public/macros_reflection.h"

class ClassBase

{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();
}FX_CLASS();

#endif // _TEST_REF_H

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#ifndef _TEST_REF_H
#define _TEST_REF_H

#include "flexi/public/macros_reflection.h"

class ClassBase

{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass : public ClassBase
{
public:
TestClass();
virtual ~TestClass();
}FX_CLASS();

#endif // _TEST_REF_H

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS_WITH_PARENT("", TestClass, ClassBase)

#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(3)test_ref.h

#ifndef _TEST_REF_H
#define _TEST_REF_H

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass : public ClassBase
{
public:
TestClass();
virtual ~TestClass();
}FX_CLASS(Parent="");

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)

#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

Struct Type Reflection Mark Macro

Any struct type in need of reflection should mark FX_STRUCT () after its definition.

reflection_test_define.h

class StructTest
{
public:
StructTest()
{
x = 0.0;
y = 0.0;
}

FX_PROPERTY()
float x;
FX_PROPERTY()
float y;
}FX_STRUCT();

Meta Supported:

  1. Parent=MyBaseStruct (key–value pair)

Description: optional, to specify MyStructClass as its parent type.

(1)test_struct.h

#ifndef _TEST_STRUCT_H
#define _TEST_STRUCT_H

#include "flexi/public/macros_reflection.h"

struct struct_base_t
{
int x;
}FX_STRUCT();

struct test_struct_t
{
int y;
}FX_STRUCT();

#endif //_TEST_STRUCT_H

test_struct.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H


DECLARE_STRUCT("", struct_base_t)


DECLARE_STRUCT("", test_struct_t)

#endif //REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H

(2)test_struct.h

#ifndef _TEST_STRUCT_H
#define _TEST_STRUCT_H

#include "flexi/public/macros_reflection.h"

struct struct_base_t
{
int x;
}FX_STRUCT();

struct test_struct_t : struct_base_t
{
int y;
}FX_STRUCT();

#endif //_TEST_STRUCT_H

test_struct.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H


DECLARE_STRUCT("", struct_base_t)


DECLARE_STRUCT_WITH_PARENT("", test_struct_t, struct_base_t)


#endif //REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H

(3)test_struct.h

#ifndef _TEST_STRUCT_H
#define _TEST_STRUCT_H

#include "flexi/public/macros_reflection.h"

struct struct_base_t
{
int x;
}FX_STRUCT();

struct test_struct_t : struct_base_t
{
int y;
}FX_STRUCT(Parent="");

#endif //_TEST_STRUCT_H

test_struct.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H


DECLARE_STRUCT("", struct_base_t)


DECLARE_STRUCT("", test_struct_t)

#endif //REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H

(4)test_struct.h

#ifndef _TEST_STRUCT_H
#define _TEST_STRUCT_H

#include "flexi/public/macros_reflection.h"

struct struct_base_t
{
int x;
}FX_STRUCT();

struct test_struct_t : struct_base_t
{
int y;
}FX_STRUCT(Parent=struct_base_t);

#endif //_TEST_STRUCT_H

test_struct.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang.!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H


DECLARE_STRUCT("", struct_base_t)


DECLARE_STRUCT_WITH_PARENT("", test_struct_t, struct_base_t)

#endif //REFLANG_METADATA_CODE_GEN_TEST_STRUCT_GEN_H

Enum Type Reflection Mark Macro

Any enum type in need of reflection should mark FX_ENUM () after its definition.

reflection_test_define.h

#ifndef _REFLECTION_TEST_DEFINE_H 
#define _REFLECTION_TEST_DEFINE_H

#include "../public/i_entity.h"
#include "../public/i_interface.h"
#include "../utils/pod_traits.h"

#include "../public/macros_reflection.h"

typedef int int8;

namespace flexi
{
enum EnumTest
{
A,
B,
C,
D,
E,
F,
G,
}FX_ENUM();
}

Global Function Reflection Mark Macro

Any global function in need of reflection should mark FX_FUNCTION () before its declaration.

FX_FUNCTION()
inline int TestFunction(int x, int y)
{
return x + y;
}

Meta Supported:

  1. ReturnType (key–value pair)

Description: optional, to change the global function’s return type.

(1)test_func.h

#ifndef _TEST_FUNC_H 
#define _TEST_FUNC_H

#include "flexi/public/macros_reflection.h"
#include "flexi/public/i_var_list.h"

FX_FUNCTION()
void TestFunction(const IVarList& args, IVarList& result);

test_func.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H


DECLARE_FUNCTION_N(TestFunction)
#endif //REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H

(2)test_func.h

#ifndef _TEST_FUNC_H 
#define _TEST_FUNC_H

#include "flexi/public/macros_reflection.h"
#include "flexi/public/i_var_list.h"

FX_FUNCTION(ReturnType=Table)
void TestFunction(const IVarList& args, IVarList& result);

#endif // _TEST_FUNC_H

test_func.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H


DECLARE_FUNCTION_T(TestFunction)
#endif //REFLANG_METADATA_CODE_GEN_TEST_FUNC_GEN_H

Property Reflection Mark Macro

Any property, namely variable of an entity, type or struct, if needs reflection, should mark FX_PROPERTY () before its declaration.

struct StructTest 
{
StructTest()
{
x = 0.0;
y = 0.0;
}

FX_PROPERTY()
float x;
FX_PROPERTY()
float y;
}FX_STRUCT();

Meta Supported:

  1. Name (key-value pair)

Description: Optional, to specify the name of the property.

No Name is written situation:

a. If there is an uppercase letter in the member variable, the substring starting with the first uppercase letter of the member variable and ending with the last character will be used as the property name.

b. If there is no uppercase letter in the member variable, the name of the member variable will be used as the name of the property.

(1)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

private:
FX_PROPERTY(Func)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, X, GetX, SetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

private:
FX_PROPERTY(Name=PropX, GetFunc=GetX, SetFunc=SetX)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, PropX, GetX, SetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
  1. ReadOnly (key)

Description: Optional, to turn it into a read-only property.

(1)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

private:
FX_PROPERTY(Func)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, X, GetX, SetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

private:
FX_PROPERTY(Func, ReadOnly)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_GET(int, TestClass, X, GetX, ReadOnly)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
  1. Func (key)

Description: Optional, if there is a Func key, the property can be accessed via the function whose name merges from Get and Set.

(1)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

public:
FX_PROPERTY()
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_OFFSET(int, TestClass, X, m_nX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

public:
FX_PROPERTY(Func)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, GetX, SetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
  1. GetFunc (key or key-value pair)

Description: Optional, works only when there is no Func key.

If there is a GetFunc key, the property can be obtained from the GetFunc value, or through the Get merged property function name. Otherwise, it will access the member variable directly.

(1)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

public:
FX_PROPERTY()
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_OFFSET(int, TestClass, X, m_nX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }

public:
FX_PROPERTY(GetFunc)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_GET(int, TestClass, X, GetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(3)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }

public:
FX_PROPERTY(GetFunc=GetPropX)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_GET(int, TestClass, X, GetPropX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
  1. SetFunc (key or key-value pair)

Description: Optional, only work when there is the GetFunc key.

If there is a SetFunc key, the property can be set by the SetFunc value or the Set merged property name. Otherwise, it is a read-only property.

(1)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }

public:
FX_PROPERTY(GetFunc)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY_GET(int, TestClass, X, GetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }

public:
FX_PROPERTY(GetFunc, SetFunc)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, X, GetX, SetX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(3)test_ref.h

#include "flexi/public/macros_reflection.h"

class ClassBase
{
public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }
void SetPropX(int val) { m_nX = val; }
public:
FX_PROPERTY(GetFunc, SetFunc=SetPropX)
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, X, GetX, SetPropX)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
  1. Type (key-value pair)

Description: Optional, to change the type of the property.

(1)test_ref.h

    ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }
void SetPropX(int val) { m_nX = val; }

const char* GetString() const { return m_strString.c_str(); }
void SetString(const char* val) { m_strString = val; }

public:
FX_PROPERTY(Func)
int m_nX;

FX_PROPERTY(Func)
core_string m_strString;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, GetX, SetX)
DECLARE_PROPERTY(core_string, TestClass, String, GetString, SetString)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

    ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

int GetPropX() const { return m_nX; }
void SetPropX(int val) { m_nX = val; }

const char* GetString() const { return m_strString.c_str(); }
void SetString(const char* val) { m_strString = val; }

public:
FX_PROPERTY(Func)
int m_nX;

FX_PROPERTY(Func, Type=const char*)
core_string m_strString;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, GetX, SetX)
DECLARE_PROPERTY(const char*, TestClass, String, GetString, SetString)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

Member Function Reflection Mark Macro

Any member function, namely member method of an entity, type or struct, if needs reflection, should mark FX_METHOD () before its declaration.

class TestEntity : public IEntity
{
public:
virtual bool Init(const IVarList& args) override
{
return true;
}

virtual bool Shut() override
{
return true;
}

FX_METHOD()
float TestMethod(FX_META(Type=double) float x, float y)
{
return x + y;
}
}FX_ENTITY;

Meta Supported:

  1. ReturnType (key-value pair)

Description: Optional, to change the return type of the member function.

(1)test_ref.h

public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

FX_METHOD(Name=PropX,GetFunc,SetFunc=SetX)
int GetPropX() const { return m_nX; }
void SetPropX(int val) { m_nX = val; }

FX_METHOD()
void GetList(const IVarList& args, IVarList& res) {}

public:
int m_nX;
}FX_CLASS();

#endif // _TEST_REF_H

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, PropX, GetPropX, SetX)
DECLARE_METHOD_N(TestClass, GetList)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

(2)test_ref.h

public:
ClassBase();
virtual ~ClassBase();
}FX_CLASS();

class TestClass
{
public:
TestClass();
virtual ~TestClass();

int GetX() const { return m_nX; }
void SetX(int val) { m_nX = val; }

FX_METHOD(Name=PropX,GetFunc,SetFunc=SetX)
int GetPropX() const { return m_nX; }
void SetPropX(int val) { m_nX = val; }

FX_METHOD(ReturnType=Table)
void GetList(const IVarList& args, IVarList& res) {}

public:
int m_nX;
}FX_CLASS();

test_ref.gen.h

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!! This file is auto-generated by Reflang. !!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#ifndef REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H
#define REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H


DECLARE_CLASS("", ClassBase)


DECLARE_CLASS("", TestClass)
DECLARE_PROPERTY(int, TestClass, PropX, GetPropX, SetX)
DECLARE_METHOD_T(TestClass, GetList)


#endif //REFLANG_METADATA_CODE_GEN_TEST_REF_GEN_H

Function Parameter Reflection Mark Macro

Any function parameter, if needs to add Meta information, should mark FX_META () before its parameter declaration.

class TestEntity : public IEntity
{
public:
virtual bool Init(const IVarList& args) override
{
return true;
}

virtual bool Shut() override
{
return true;
}

FX_METHOD()
float TestMethod(FX_META(Type=double) float x, float y)
{
return x + y;
}
}FX_ENTITY();

Meta Supported:

  1. Type (key-pair value)

Description: type, to change the function parameter type.

Generating Reflection Information Files

Included Reflection Headers

In this case, if the input file is test.h, a corresponding reflection information file test.gen.h will be generated, which needs to be included in the test.cpp file.

reflection_test_define.cpp

#include "reflection_test_define.h"
#include "../public/module.h"

#include "reflection_test_define.gen.h"

reflang.exe looks for the .h header files to be parsed according to .gen.h. The specific rules are:

  1. Generate the reflection of the Flexi public header file:

    The code_gen path of this module: [module_path]/code_gen/

    Path of the header file to be parsed: flexi/xxx/yyy/zzz.h

    The relative module path of the current CPP file: [module_path]/aaa/bbb.cpp

    The current CPP includes path: #include "flexi/xxx/yyy/zzz.h"

    .gen.h format: #include "flexi/xxx/yyy/zzz.gen.h"

  1. Generate the reflection of the external header file of this module:

    The code_gen path of this module: [module_path]/code_gen/

    Path of the header file to be parsed: [module_path]/../xxx/yyy/zzz.h

    The current CPP file path: [module_path]/aaa/bbb.cpp

    Then the current CPP includes path: #include "../../../xxx/yyy/zzz.h"

    .gen.h format: #include "external_dependency/./xxx/yyy/zzz.gen.h" // Search for "bbb.h" relative to the current module path (When searching, ignore "gen." and "external_dependency/", replace '.' with '..')

  1. Generate the reflection of the internal header file of this module:

    The code_gen path of this module: [module_path]/code_gen/

The cpp and h files with the same name in the same directory:

Path of the header file to be parsed: [module_path]/aaa/bbb.h

The current CPP file path: [module_path]/aaa/bbb.cpp

Then the current CPP includes path: #include "bbb.h"

.gen.h format: #include "bbb.gen.h" // Search for "bbb.h" relative to the current module path (Ignore "gen." when searching)

The cpp and h files in different directories:

Path of the header file to be parsed: [module_path]/xxx/yyy/zzz.h

The current CPP file path: [module_path]/aaa/bbb.cpp

Then the current CPP includes path: #include "../xxx/yyy/zzz.h"

.gen.h format: #include "xxx/yyy/zzz.gen.h" // Search for "xxx/yyy/zzz.h" relative to the current module path (Ignore "gen." when searching)

Configuring Pre-Build Events

Add the following command to the module’s PreBuildEvent:

$(SolutionDir)extern/reflang/bin/release/reflang.exe --solution_path $(SolutionDir) --module_path $(ProjectName) --input_file_filter ".+.h|.+.cpp" --code_gen_path code_gen --temp_path $(IntermediateOutputPath) --log_level summary --out_log "" --include_paths "" -- -std=c++11 -g -DREFLECTION_PARSER

Description: This command will scan the files that meet the conditions in the given module and only generate reflection information for types, and their properties and methods that have reflection marks.

Description of the command’s parameters:

--solution_path: Path of the solution

--module_path: Module path (relative to the solution path)

--input_file_filter: Filtering the input file

--code_gen_path: The output path of the reflection information file

--temp_path: Temporary directory for middle files

-- log_level: Level of logs (error, warning, summary, summary_input, log, verbose, very_verbose)

--out_log: Enter the log file name (relative to the temporary directory for middle files)

--include_paths: Additional including paths in parsing

-std=c++11: Employing std::c++11

-g: Generating debugging information

-D__REFLECTION_PARSER__: Parsing the reflection information

-I<dir>, --include-directory<arg>, --include-directory=<arg>

Add directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored

For more command parameters, please refer to: https://clang.llvm.org/docs/ClangCommandLineReference.html

Building Projects

Before the build: Configured Pre-Build Events will be triggered, generating the reflection information files in the project.

Build projects: If the project code contains Generated Reflection Headers in the pre-build events, the reflection information will be compiled to the compilation units.