Skip to content

Omni reflector - C++ reflection/serialization library

License

Notifications You must be signed in to change notification settings

Maksasj/omni_reflector

Repository files navigation

Omni reflector

Omni reflector - C++ reflection/serialization library, that uses c++ metaprogramming to manage fields of class and structs at compile time. Depends only on c++ standard library, not event boost funsion or hana required.

Note serialization api depeneds on nlohmann/json library

omni reflector is not a new javascript framework btw !

Cool looking widgets stars build build


Usage example

#define OMNI_REFLECTOR_ENABLE_SERIALIZER
#include "omni_reflector.h"

using namespace omni::reflector;
using namespace omni::reflector::serialization;

struct MyChildStruct : Reflected<MyChildStruct> {
	float someRandomFloatField;

	const constexpr static auto meta = std::make_tuple(
		field(someRandomFloatField)
	);
};

struct MyStruct : Reflected<MyStruct> {
	std::string stringField;
	int poggers;
	MyChildStruct childStruct;

	const constexpr static auto meta = std::make_tuple(
		field(stringField),
		field(poggers),
		field(childStruct)
	);
};

int main() {
	MyStruct someRandomStruct;

	/* Filling struct with some values*/

	nlohmann::json object = JsonSerializer::json_serialize(someRandomStruct);
	const auto representation = object.dump(4);
	std::cout << representation << "\n";

	return 0;
};

After serializing someRandomStruct, eventually we get json structure, that will have following layout (Note fields filled with garbage, since I haven't filled the someRandomStruct :) ):

{
    "childStruct": {
        "someRandomFloatField": 4.590373509435236e-41
    },
    "poggers": -981426683,
    "stringField": ""
}

Build

cmake -B build -G Ninja

make.bat

Testing

test.bat

License

Todo

About

Omni reflector - C++ reflection/serialization library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published