Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
mlomb committed Oct 26, 2020
1 parent ef6e654 commit 25a80c0
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# MetaCPP - Reflection & Serialization
The objective is to generate reflection information and enable serialization/deserialization with the least or -zero- *manual* code possible.

Note that this project is not production ready, there are many bugs and lacks proper testing.

## Example
You can find the definition of this objects in [Example/objects.hpp](Example/objects.hpp).
You can find the definition of the following objects in [Example/objects.hpp](Example/objects.hpp).
```C++
// load the auto-generated metadata
metacpp::Storage* storage = metacpp::Runtime::GetStorage();
Expand All @@ -22,17 +24,20 @@ monster->scary_factor = 42.123;

Map map;
map.entities = { player, monster };

map.magic_numbers = { 4, 2 };

map.map = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 },
};

metacpp::JsonSerializer serializer = metacpp::JsonSerializer(storage);

// serialize
std::string json = serializer.Serialize(&map, true /* pretty print */);

std::cout << json << std::endl;

// deserialize
Expand All @@ -43,42 +48,41 @@ The code above spits out a JSON like this:
[{
"magic_numbers": [4, 2],
"map": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
"entities": [1, 2]
}, {
"entities": [1, 2, null, ...]
}, {
"reflection_class": "Player",
"health": 255,
"position": {
"x": 5.0,
"y": 5.0
"x": 5.0,
"y": 5.0
},
"velocity": {
"x": 1.0,
"y": 1.0
"x": 1.0,
"y": 1.0
},
"name": "mlomb"
}, {
}, {
"reflection_class": "Monster",
"health": 255,
"position": {
"x": 10.0,
"y": 10.0
"x": 10.0,
"y": 10.0
},
"velocity": {
"x": -1.0,
"y": -1.0
"x": -1.0,
"y": -1.0
},
"scary_factor": 42.12300109863281
}]
```
You can find the full code for this example [here](Example/).

## Setup
You can set it up very simple if you are using CMake.
You can set it up using CMake.
First clone the repository under your project directory.

Then, inside your `CMakeLists.txt` add the following:
```CMake
# If you don't want to compile the CLI and use the precompiled version see MetaPrebuild.cmake
add_subdirectory(MetaCPP/MetaCPP-CLI)
...
Expand All @@ -100,7 +104,7 @@ int main() {
```

## Dependencies
MetaCPP relies on Clang's LibTooling to generate all the metadata, fortunately if you use the precompiled version you don't need to.
MetaCPP relies on Clang's LibTooling to generate all the metadata.
These are the dependencies:
- [Clang's Libtooling](https://clang.llvm.org/docs/LibTooling.html) to gather metadata (only for CLI)
- [Mustache](https://github.com/kainjow/Mustache) to generate the metadata source code (only for CLI)
Expand All @@ -110,5 +114,9 @@ Mustache and rapidjson are included as submodules so don't forget to clone with

If you need to compile the CLI make sure to have installed Clang's Libtooling. In Windows you should have in `PATH` the Clang and LLVM binaries.

## Known issues

* Arrays of pointers are broken ([#pr-3](https://github.com/mlomb/MetaCPP/pull/3#issuecomment-716345878))

## License
See [LICENSE](LICENSE).

0 comments on commit 25a80c0

Please sign in to comment.