{"id":15646812,"url":"https://github.com/mlomb/metacpp","last_synced_at":"2025-04-30T12:34:37.191Z","repository":{"id":50704376,"uuid":"112043903","full_name":"mlomb/MetaCPP","owner":"mlomb","description":"C++ Reflection \u0026 Serialization using Clang's LibTooling","archived":false,"fork":false,"pushed_at":"2020-10-26T23:46:04.000Z","size":118,"stargazers_count":49,"open_issues_count":0,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-03T12:19:31.854Z","etag":null,"topics":["clang","clang-libtooling","cpp","meta","metadata","reflection","serialization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlomb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-26T00:16:23.000Z","updated_at":"2024-01-06T15:19:33.000Z","dependencies_parsed_at":"2022-09-18T06:36:12.173Z","dependency_job_id":null,"html_url":"https://github.com/mlomb/MetaCPP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlomb%2FMetaCPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlomb%2FMetaCPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlomb%2FMetaCPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlomb%2FMetaCPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlomb","download_url":"https://codeload.github.com/mlomb/MetaCPP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221113219,"owners_count":16758426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang","clang-libtooling","cpp","meta","metadata","reflection","serialization"],"created_at":"2024-10-03T12:15:09.391Z","updated_at":"2024-10-22T16:08:25.576Z","avatar_url":"https://github.com/mlomb.png","language":"C++","readme":"# MetaCPP - Reflection \u0026 Serialization\nThe objective is to generate reflection information and enable serialization/deserialization with the least or -zero- *manual* code possible.\n\nNote that this project is not production ready, there are many bugs and lacks proper testing.\n\n## Example\nYou can find the definition of the following objects in [Example/objects.hpp](Example/objects.hpp).\n```C++\n// load the auto-generated metadata\nmetacpp::Storage* storage = metacpp::Runtime::GetStorage();\nmetacpp::generated::Load(storage);\n\nPlayer* player = new Player();\nplayer-\u003ehealth = 255;\nplayer-\u003eposition = { 5, 5 };\nplayer-\u003evelocity = { 1, 1 };\nplayer-\u003ename = \"mlomb\";\n\nMonster* monster = new Monster();\nmonster-\u003ehealth = 255;\nmonster-\u003eposition = { 10, 10 };\nmonster-\u003evelocity = { -1, -1 };\nmonster-\u003escary_factor = 42.123;\n\nMap map;\nmap.entities = { player, monster };\n\nmap.magic_numbers = { 4, 2 };\n\nmap.map = {\n        { 1, 2, 3 },\n        { 4, 5, 6 },\n        { 7, 8, 9 },\n};\n\nmetacpp::JsonSerializer serializer = metacpp::JsonSerializer(storage);\n\n// serialize\nstd::string json = serializer.Serialize(\u0026map, true /* pretty print */);\n\nstd::cout \u003c\u003c json \u003c\u003c std::endl;\n\n// deserialize\nMap* deserialized_map = serializer.DeSerialize\u003cMap\u003e(json);\n```\nThe code above spits out a JSON like this:\n```JSON\n[{\n    \"magic_numbers\": [4, 2],\n    \"map\": [[1, 2, 3], [4, 5, 6], [7, 8, 9]],\n    \"entities\": [1, 2, null, ...]\n}, {\n    \"reflection_class\": \"Player\",\n    \"health\": 255,\n    \"position\": {\n        \"x\": 5.0,\n        \"y\": 5.0\n    },\n    \"velocity\": {\n        \"x\": 1.0,\n        \"y\": 1.0\n    },\n    \"name\": \"mlomb\"\n}, {\n    \"reflection_class\": \"Monster\",\n    \"health\": 255,\n    \"position\": {\n        \"x\": 10.0,\n        \"y\": 10.0\n    },\n    \"velocity\": {\n        \"x\": -1.0,\n        \"y\": -1.0\n    },\n    \"scary_factor\": 42.12300109863281\n}]\n```\nYou can find the full code for this example [here](Example/).\n\n## Setup\nYou can set it up using CMake.\nFirst clone the repository under your project directory.\n\nThen, inside your `CMakeLists.txt` add the following:\n```CMake\nadd_subdirectory(MetaCPP/MetaCPP-CLI)\n\n...\n\n# MetaCPP automatic reflection\ninclude(MetaCPP/CMake/MetaPrebuild.cmake)\nmeta_generate(YOUR_TARGET \"FileToReflect.hpp\" \"Generated.hpp\" \"Generated.cpp\" \"\")\n```\nNext and last, include the following lines at the begining of your application to load all the metadata:\n```C++\n#include \u003cMetaCPP/Runtime.hpp\u003e\n\nint main() {\n  metacpp::Storage* storage = metacpp::Runtime::GetStorage();\n  metacpp::generated::Load(storage);\n \n  ...\n}\n```\n\n## Dependencies\nMetaCPP relies on Clang's LibTooling to generate all the metadata.  \nThese are the dependencies:\n- [Clang's Libtooling](https://clang.llvm.org/docs/LibTooling.html) to gather metadata (only for CLI)\n- [Mustache](https://github.com/kainjow/Mustache) to generate the metadata source code (only for CLI)\n- [rapidjson](https://github.com/Tencent/rapidjson) to enable JSON serialization\n\nMustache and rapidjson are included as submodules so don't forget to clone with `--recursive`.\n\nIf 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.\n\n## Known issues\n\n* Arrays of pointers are broken ([#pr-3](https://github.com/mlomb/MetaCPP/pull/3#issuecomment-716345878))\n\n## License\nSee [LICENSE](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlomb%2Fmetacpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlomb%2Fmetacpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlomb%2Fmetacpp/lists"}