Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/maksasj/omni_reflector
- Owner: Maksasj
- License: mit
- Created: 2023-05-16T17:32:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-23T16:19:45.000Z (about 1 year ago)
- Last Synced: 2023-10-23T17:30:50.830Z (about 1 year ago)
- Topics: cpp, reflection, serialization
- Language: C++
- Homepage:
- Size: 82 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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
## 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 Ninjamake.bat
```## Testing
```bash
test.bat
```## License
*Todo*