Home

Awesome

Vzor

Vzor is a reflection library for C++. Unlike other existing reflection systems, this one focuses on preserving your code's readability, without adding macros and other intermediate languages. You use standard C++ attributes to mark types from reflection and you use standard C++ to query type info at runtime.

Vzor firstly runs a python program which extracts valuable information from your code and then generates a database-like file containing all of the information necessary, accessible from your C++.

The library is a work in progress - unstable and unusable. I am happy to hear your feedback, so do scroll below for an overview and let me know what you think (open an issue or contact me directly over email).

Requirements

Usage

Put [[reflect::type]] on types you want to reflect and [[reflect::data]] on data members:

struct [[reflect::type]] Vector3
{
	[[reflect::data]]
	float X;
	[[reflect::data]]
	float Y;
	[[reflect::data]]
	float Z;
};

Then query information about your type:

const Vzor::ReflectedType& vectorTypeInfo = Vzor::TypeOf<Vector3>();
printf("The name of type is %s.\n", vectorTypeInfo.Name);
for (int i = 0; i < 3; i++)
{
    printf("Its next member is named %s and of type %s",
        vectorTypeInfo.DataMembers[i].Name,
        Vzor::TypeOf(vectorTypeInfo.DataMembers[i].TypeId).Name);
}

You can also query query information about your type (as long as your type derives from Vzor::EnableReflectionFromThis):

class [[reflect::type]] TransformData : public Vzor::EnableReflectionFromThis<TransformData>
{
	[[reflect::data]]
	Quaternion Rotation;
	[[reflect::data]]
	Vector3 Translation;
	[[reflect::data]]
	float Scale;
};
...

TransformData data;
const ReflectedType& typeFromInstance = Vzor::TypeOf(data);
printf("My obj is of type: %s", typeFromInstance.Name);

Integration

// If this is vector3.h, define your class
struct [[reflect::type]] Vector3
{
	[[reflect::data]]
	float X;
	[[reflect::data]]
	float Y;
	[[reflect::data]]
	float Z;
};
// And then include the generated file
#include "vzorgenerated/Vector3.h"

What it can do currently

Explore the public API to learn more, which right now consits of these:

See the tests project for examples.

Missing features

  1. Reflecting nested classes
  2. No support for types in different namespaces with the same names.
  3. No docs
  4. No support for const in pointers (e.g. Foo const *)
  5. Performance / stress / sanity tests
  6. Support for accessing actual property / function values (atm you can see a description of the properties, but can't access their value)
  7. Support for functions
  8. Support for enums
  9. Better error reporting