Git Product home page Git Product logo

flexiblereflection's Introduction

This project presents a small, flexible runtime reflection system using C++11 language features.

For more information, see the blog series "A Flexible Reflection System in C++".

Build Instructions

CMake is required. Quick start:

$ git clone https://github.com/preshing/FlexibleReflection
$ cd FlexibleReflection
$ mkdir build
$ cd build
$ cmake ..

For detailed build instructions, see "How to Build a CMake-Based Project".

Implementation

如何使用C++实现反射

  1. 对于需要实现反射的类,通过宏展开,向类中注入2个成员
  • typeDescriptor,作为实际保存反射相关信息的对象。
  • typeDescriptor的初始化函数。
  1. 初始化类中反射相关的数据
  • 声明typeDescriptor,调用初始化函数。
  • 初始化内容包括:名称、大小、成员名称、成员offset(运行时获取成员对象的指针)、成员的typeDescriptor(递归dump反射信息)。
  1. 提供查询反射数据的接口
  • 通过helper对象获取类型T的typeDescriptor,获取方式为模板SFINAE,判断类型T是否存在反射注入。
  • 拥有反射注入的类,返回typeDescriptor对象。
  • 没有反射注入的语言自有类型,返回源文件中定义,而不是模板生成的,primitiveDescriptor对象。

flexiblereflection's People

Contributors

preshing avatar fenzhu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.