项目作者: ghassanpl

项目描述 :
A small tool to create reflection information for C++ projects, ala Unreal's UHT
高级语言: C++
项目地址: git://github.com/ghassanpl/reflector.git
创建时间: 2019-07-14T20:37:06Z
项目社区:https://github.com/ghassanpl/reflector

开源协议:Other

下载


reflector

NOTE: This is still a work in progress. Right now the tool mostly works, but is imperfect,
generates imperfect code, and has bugs. Use at your own risk.

Pull requests welcomed and encouraged and begged for!

What is it?

Reflector is a C++20 reflection generation tool similar to the Unreal Header Tool. It will scan the headers in your codebase for types/methods/fields annotated with a special reflection syntax, and create files containing reflection information about those entities. The main type of file it will create is the *.mirror file, which you are meant to include in the files Reflector is scanning. This will inject reflection information straight into your files, allowing for compile-time reflection of these entities.

  1. #include "Component.h.mirror"
  2. RClass(); /// Annotation will cause the class below to be reflected
  3. class Component : public Reflector::Reflectable
  4. {
  5. RBody(); /// Required in every reflected class
  6. RField(Required, Setter = false, Editor = false); /// Annotation will cause Name to be reflected
  7. std::string Name;
  8. /// ^ The Name field will be required when deserializing, will not be settable
  9. /// from scripts, and will not be editable in the editor.
  10. /// These comment lines will be included in the auto-generated documentation
  11. /// for SetName. The `ScriptPrivate` attribute means that this function will
  12. /// not be callable from script.
  13. RMethod(ScriptPrivate); /// Annotation will cause SetName to be reflected
  14. void SetName(std::string_view name) { if (VerifyName(name)) Name = name; }
  15. protected:
  16. /// This field will be reflected, and a public GetParentObject function will
  17. /// be generated for it.
  18. RField();
  19. class Object* mParentObject = nullptr;
  20. };
  21. REnum();
  22. enum class TestEnum
  23. {
  24. Open = 5,
  25. Visible,
  26. REnumerator(Opposite = Dead);
  27. Alive,
  28. };

How to use

See Usage in the wiki.

Example

See the example in the wiki.

Dependencies

Projects Using Reflector

  • C++20 (C++17 support could be added if requested)
  • optional nlohmann/json if you want out-of-the-box JSON serialization support

The Reflector Tool Itself

See the vcpkg.json file for up-to date dependency information.

UNTODO

These are things I am not planning on doing unless someone asks nicely:

  • support for generating code for older C++ versions
  • other platforms (the code is fairly portable, just needs the memory mapping code to be written for non-windows platforms)
  • scriptability/pluginability