Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/maksasj/omni_reflector

Omni reflector - C++ reflection/serialization library
https://github.com/maksasj/omni_reflector

cpp reflection serialization

Last synced: about 6 hours ago
JSON representation

Omni reflector - C++ reflection/serialization library

Awesome Lists containing this project

README

        




# 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](https://github.com/nlohmann/json) library*

> omni reflector is not a new javascript framework btw !

Cool looking widgets
stars
build
build



## Usage example
```c++
#define OMNI_REFLECTOR_ENABLE_SERIALIZER
#include "omni_reflector.h"

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

struct MyChildStruct : Reflected {
float someRandomFloatField;

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

struct MyStruct : Reflected {
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`` :) )*:
```json
{
"childStruct": {
"someRandomFloatField": 4.590373509435236e-41
},
"poggers": -981426683,
"stringField": ""
}
```

## Build
```bash
cmake -B build -G Ninja

make.bat
```

## Testing
```bash
test.bat
```

## License
*Todo*