Skip to content

pribault/CppReflection

Repository files navigation

CppReflection

GitHub license Maintenance

A non intrusive, powerful c++ reflection library.
This library currently supports:

  • class reflection and introspection
  • c++ fundamental types (booleans, floating point numbers, signed and unsigned integers, pointers)
  • some stl containers (std::string, std::vector, std::list, std::map)
  • runtime type check
  • json and yaml serialization and deserialization.

Documentation

Getting started

Dependencies

Before compiling the project, you need to install the following dependencies :

  • python3
  • cmake
  • vcpkg
  • a c++ compiler depending on your platform (msvc for Windows, clang++ or g++ for Unix systems), minimum c++ version: 11

The environment variable VCPKG_PATH needs to be defined to the vcpkg install directory. You also need to install some dependencies using vcpkg, on Windows:

vcpkg install --triplet=x64-windows yaml-cpp jsoncpp gtest

On Linux systems:

vcpkg install --triplet=x64-linux yaml-cpp jsoncpp gtest

Build

Some scripts are present inside the scripts directory to easily build and package this library.

python ./scripts/cmake.py
python ./scripts/build.py
python ./scripts/runTests.py
python ./scripts/release.py

The resulting binaires will be located inside the build/bin directory. Some examples and unit tests will also be built, feel free to try them

Releases

You can find the release builds here : https://github.com/pribault/CppReflection/releases

Tests

This project uses GoogleTest to guarantee quality and stability over time.

A quick example

#include <CppReflection/Reflectable.h>
#include <CppReflection/YamlWriter.h>
#include <iostream>

using namespace	CppReflection;

class	Point : public Reflectable
{
	public:

		START_REFLECTION(Point)
		REFLECT_ATTRIBUTE(x)
		REFLECT_ATTRIBUTE(y)
		END_REFLECTION()

		int	x;
		int	y;
};

int main()
{
	Point	point;

	point.x = 42;
	point.y = 42;
	std::cout << YamlWriter::compute(point) << std::endl;
	return 0;
}

This example demonstrates how to reflectable a class and serialize it to yaml. Take a look at the wiki for more informations.

About

A non intrusive, powerful c++ reflection system

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages