一個簡單而功能強大的C++反射系統:eXtendedMirror

jopen 9年前發布 | 15K 次閱讀 C/C++開發 eXtendedMirror

eXtendedMirror是一個簡單而功能強大的C++反射系統。它具有以下特性:

  • Compiler Independent
  • Non intrusive
  • No mandatory parser required
  • Variant based interface
  • Dry-est possible interface
  • </ul>

    它支持語言(有一些限制)幾乎所有的構建體如:

    • Primitive Types
    • Pointer Types
    • References
    • C Array Types
    • Classes
    • Multiple Inheritance
    • Abstract Classes
    • Methods
    • Static Functions
    • Namespaces
    • Class Templates
    • Constants
    • Enumerators
    • Static and Global Variables

    You can find a lot of useful information in this article.

    依賴

    The code only depends on the c++11 standard library, but the build system depends on CMake and Python To generate the documentation you need Doxygen

    構建

    To build the library you first have to run CMake from the project directory

    cmake -DCMAKE_BUILD_TYPE=Debug .

    You can change Debug with Release if you want, and you can set some other parameters such as

    • FUNC_PARAM_MAX: maximum number of supported function parameters (defaults to 8).
    • GET_N_SET_EXTR_PARAM_MAX: Maximum number of supported extra parameters for getters and setters, that is the maximum number of parameters for getters, and the maximum number of parameters for setters, beyond the first (i.e. the value to set) (defaults to 3).
    • TEMPL_PARAM_MAX: Maximum number of supported template parameters, for class templates (defaults to 4).

    After running CMake, you can build the library and the tests by running

    make

    To install on your system type

    make install

    To build the documentation

    make doc

    Using the library

    To use the library include the header XM/xMirror.hpp in your compile units and link to the libxMirror library. You can get more info here

    MyClass.hpp

    #include<XM/xMirror.h>
    
    class MyClass {
    public:
        int myMethod(int a, int b);
        int myField;
    
        int getMyField2();
        void setMyField2(int val);
    
    private:
        int myField2;
    };
    XM_DECLARE_CLASS(MyClass);

    MyClass.cpp

    // Methods definition here
    
    XM_DEFINE_CLASS(MyClass)
    {
        // Binds a method with automatic name extrapolation
        bindMethod(XM_MNP(myMethod));
    
        // Binds a property from a field
        bindProperty(XM_MNP(myField));
    
        // Binds a property from get and set methods
        bindProperty("myField2", &MyClass::getMyField2, &MyClass::setMyField2);
    }
    
    XM_REGISTER_TYPE(MyClass);

    項目主頁:http://www.baiduhome.net/lib/view/home/1439034991254

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!