C++ Reflection Parser / Runtime Skeleton

Overview

C++ Reflection

Join the chat at https://gitter.im/CPP-Reflection/Lobby

Preface

I worked on a complete reflection pipeline starting in the summer of 2015 for a game project / editor. My intent by creating this repository was to share my experience and how I came about developing it. The response from the community motivated me to make it a tad bit more official by allowing others to consume and build it easily, rather than just giving you code and saying "fill in the pieces".

I created a blog where I talk more in detail about the process and try to share my experiences as best as possible. You can find the blog here -

https://austinbrunkhorst.com/cpp-reflection-part-1/

Building

There are three buildable sections in this repository - Runtime, Parser and Examples. I setup an environment for building using CMake - yes it's insane but it's also awesome so let's just go with it. All examples are assuming you're working from the root of this repository.

Requirements

  • LLVM 3.8.0+ (for libClang)
  • Boost 1.59+
  • A C++11 compliant compiler - I've tested on MSVC 14, G++ 4.8 and Clang++ 3.6.

Runtime

There are no dependencies in the runtime so building is pretty straightforward.

Create a build directory.

mkdir Build && cd Build

Generate a build system using any desired generator in CMake.

cmake -G "<Desired Generator>" ../Source/Runtime

Build - you can use any IDE if applicable to the generator, but you can also just build straight from CMake.

cmake --build . --target MetaRuntime

Parser

There are more moving parts in this because the parser actually has dependencies and builds to an executable. Don't worry though! I'm here to walk you through this.

Install LLVM 3.8 for LibClang

Windows - download the 32 bit or 64 bit pre-built binaries.

Unix based systems - find the appropriate package. On Linux Mint I just did the following.

sudo apt-get install libclang-3.8-dev

The installation should be located in /usr/lib/llvm-3.8

Once installed, set an environment variable LLVM_ROOT to the root of the installation directory. You can skip this step, but an environment variable makes the CMake command simpler.

Install Boost 1.59

This part sucks, but we've gotta do it. Download the sources and build it using these instructions.

Once installed, set an environment variable to BOOST_ROOT like we did for LLVM.

Create a build directory.

mkdir Build && cd Build

Generate a build system using any desired generator in CMake.

cmake -G "<Desired Generator>" ../Source/Parser

If you skipped creating environment variables, you'll have to define variables for resolution in CMake directly - just add these two switches in the command above.

-DLLVM_ROOT=<PATH> -DBOOST_ROOT=<PATH>

Build - you can use any IDE if applicable to the generator, but you can also just build straight from CMake.

cmake --build . --target MetaParser

Examples

You will need to follow the same steps for setting up the dependencies explained in the Parser build instructions.

Just like the other two targets you'll do the following -

Create a build directory.

mkdir Build && cd Build

Generate a build system using any desired generator in CMake.

cmake -G "<Desired Generator>" ../Examples

Build - you can use any IDE if applicable to the generator, but you can also just build straight from CMake.

cmake --build .

Remember to add the extra switches for defining LLVM_ROOT and BOOST_ROOT if you skipped adding them as an environment variable.

All of the examples build to a simple executable that demonstrates the specific features/functionality in use.

I don't have immediate intentions of documenting the interfaces and such with the runtime library, but hopefully the examples cover all parts of the runtime and people can get the whole picture there. My blog posts cover the development process and the reason I made the decisions I did.

Feel free to contact me with any questions or concerns! Also, pull requests are very welcome!

Issues
  • can you add some document about cmake rule?

    can you add some document about cmake rule?

    it's a cool library, thanks. i use the library in my project, i write my cmake file on the basis of example's cmake file. i generate the vs project, and generate the needed meta files, but these files is empty. i can't debug this, i don't know where is wrong. can you add some document about cmake rule? for example, explain the "meta_parser_prebuild" and "meta_parser_build". Thanks.

    opened by chena1982 6
  • Examples fail to link

    Examples fail to link

    Hi @AustinBrunkhorst When compiling the Examples, everything seems to go fine (both Parser and Runtime compile) but the Serialization.cpp fails to link. This is the output I get. If I look at the files of the Generated folder, all of them but the *.includes one are empty. I think there is something wrong with the meta_parser_build command, like if it was not triggering the Parser. Any ideas?

    [ 23%] Built target MetaParser
    [ 55%] Built target MetaRuntime
    [ 61%] Built target TestModule
    [ 62%] Linking CXX executable Serialization
    CMakeFiles/Serialization.dir/Serialization.cpp.o: En la función `main':
    Serialization.cpp:(.text+0xcb): referencia a `meta_generated::ModuleTestModule::ModuleTestModule(ursine::meta::ReflectionDatabase&)' sin definir
    Serialization.cpp:(.text+0xda): referencia a `meta_generated::ModuleTestModule::~ModuleTestModule()' sin definir
    collect2: error: ld devolvió el estado de salida 1
    make[2]: *** [CMakeFiles/Serialization.dir/build.make:193: Serialization] Error 1
    make[1]: *** [CMakeFiles/Makefile2:70: CMakeFiles/Serialization.dir/all] Error 2
    

    I am under linux, using GCC 6.2.0, libclang 3.8.1 and boost 1.6.1 Best, Arnau

    bug help wanted 
    opened by ArnauPrat 6
  • Documentation issue (CMake)

    Documentation issue (CMake)

    In README.md you state

    Note: this assumes you have created empty files for ${META_GENERATED_HEADER} and ${META_GENERATED_SOURCE} and added it to the list of sources when calling add_executable( ). Otherwise, CMake will complain about the files not existing initially.

    The recommended approach is not to create empty files for generated files (especially as you will be tempted to put them in the source directory instead of the build directory). Instead you should set the GENERATED on the corresponding sources:

    set_source_files_properties(
        ${META_GENERATED_HEADER} ${META_GENERATED_SOURCE}
        PROPERTIES
        GENERATED ON
    )
    

    Furthermore you use a PRE_BUILD TARGET add_custom_command which only works on Visual Studio. Using a non-TARGET add_custom_command might be better (and also sets the GENERATED property automatically).

    opened by l0calh05t 5
  • Can this project to be used as a code generator?

    Can this project to be used as a code generator?

    Does this project supposed to:

    1. Parse the C++ source code with full language features via clang? Which means it could parse code with template, macro etc.
    2. Get all the information about all the classes and user defined meta data?
    3. Generate code based on the information with customizable template?
    opened by Jayatubi 4
  • Get Type with string name  Problem.

    Get Type with string name Problem.

    In Test Projects With MetaProperties.The Code Say: // you can also use type meta::Type::Get( "SoundEffect" ) based on a string name Type soundEffectType = typeof( SoundEffect );

    But,when i Replace the code with: Type soundEffectType = ursine::meta::Type::Get("SoundEffect");

    The soundEffectType Result not Right! SoundEffectType.m_id is 0,and then the program crash with null pointer read!

    opened by molixiaoge 2
  • Type Meta Data not work

    Type Meta Data not work

    I have read the section of Type Meta Data, but I can't make it work.

    Range is inherit from Object, but there are two pure virtual method:

            virtual Type GetType(void) const = 0;
            virtual Object *Clone(void) const = 0;
    

    so, I can't got a instance of Range

    And I can't find any code in the Parser to handle the annotate attribute of libclang

    So, I want to know, is the annotate attribute is ready to be use or some code must be modify before I can use it.

    Thank's very much

    opened by mink365 2
  • The examples can not work on Mac OS!

    The examples can not work on Mac OS!

    I found the content of generated files is empty! the compile error is :

    Undefined symbols for architecture x86_64: "meta_generated::ModuleTestModule::ModuleTestModule(ursine::meta::ReflectionDatabase&)", referenced from: _main in Enums.o "meta_generated::ModuleTestModule::~ModuleTestModule()", referenced from: _main in Enums.o

    opened by youZhuang 1
  • Can not set struct as array

    Can not set struct as array

    I defined two struct to test.

    struct arrStruct
    {
        int c;
        int d;
    
    } Meta(Enable);
    
    struct TestStruct
    {
        int a;
        int b;
    
        struct arrStruct arr[2];
    } Meta(Enable);
    

    test code:

    void ShowVec(const vector<Field>& valList)
    {
        for (auto iter = valList.cbegin(); iter != valList.cend(); iter++)
        {
            Field f = *iter;
            Type t = f.GetType();
            if (t.IsArray())
            {
                auto arrayCtor = t.GetArrayConstructor();
                auto instance = arrayCtor.Invoke();
                auto wrapper = instance.GetArray();
                std::cout << "array's size:" << wrapper.Size() << std::endl;
            }
            if (t.IsClass())
            {
                std::vector<Field> fields = t.GetFields();
                ShowVec(fields);
            }
            std::cout << "field's name:" << (*iter).GetName() << std::endl;
        }
    }
    
    
    

    when compile:

    source\runtime\Impl/FieldSetter.hpp(64): error C3863

    help wanted 
    opened by oceanlight-cn 1
  • TypeInfo.hpp DecayedType

    TypeInfo.hpp DecayedType

    I think this line should be:

    typedef typename std::decay<T>::type Decayed;
    

    rather than:

    typedef std::decay<T> Decayed;
    

    Because you wanna check if the decayed type of T is a primitive/enum/class/etc.. and not check if the instantiated template std::decay<T> is a primitive/enum/class/etc.. (which would always generate the same results: class = true, primitive = false, enum =false).

    opened by brunogouveia 1
  • Is this a work-in-progress source?

    Is this a work-in-progress source?

    It has tons of problems and bugs, this uploaded version is clearly not working. I had to insert a lot of modifications to make it compile and the Meta attributes is still not working as well.

    opened by ujhazib 1
  • The runtime type limit?

    The runtime type limit?

    I test "Serialization" Project ,change the ComplexType struct's ursine::Array<int> arrayValue; with std::list<int> arraryValue; and also change the generate code with type.AddField<ComplexType, std::list<int>>

    Then complile and run, the Result of arraryValue is empty.I look at the function SerializeJson(const Variant &instance, bool invokeHook) ,and find that's no std::list serialize function.

    So,can you tell me all types, that i can use with runtime?

    opened by molixiaoge 0
Owner
Austin Brunkhorst
@PlayFab @microsoft
Austin Brunkhorst
Customizable C++17 Runtime Reflection Library

Refureku Check the Wiki for more documentation and use examples! Refureku is a powerful C++17 RTTI free runtime reflection library based on Kodgen. It

Julien SOYSOUVANH 164 Jun 12, 2022
C++ reflection library with Lua binding, and JSON and XML serialisation.

Ponder Linux & OSX: - Windows: Currents status: 3.2-alpha. API is unstable as features added/changed. New: Version 3 V1 replaced Boost with C++11. V2

Bill Quith 545 Jun 20, 2022
C++ Reflection Library

!New Release - 0.9.6! RTTR C++ Reflection Library RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspe

rttr.org 2.2k Jun 20, 2022
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

null 347 Jun 24, 2022
A modern compile-time reflection library for C++ with support for overloads, templates, attributes and proxies

refl-cpp v0.12.1 Documentation refl-cpp encodes type metadata in the type system to allow compile-time reflection via constexpr and template metaprogr

Veselin Karaganev 658 Jun 23, 2022
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

null 347 Jun 24, 2022
A compiling time static reflection framework for C++

static_reflect This is a fully compiling time static reflection lightweight framework for C++. It provides a very rich compile-time reflection functio

null 7 May 14, 2022
BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser) See http://pypi.python.org/pypi/bllipparser/ for Python module.

BLLIP Reranking Parser Copyright Mark Johnson, Eugene Charniak, 24th November 2005 --- August 2006 We request acknowledgement in any publications that

Brown Laboratory for Linguistic Information Processing 211 May 29, 2022
BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser)

BLLIP reranking parser (also known as Charniak-Johnson parser, Charniak parser, Brown reranking parser)

Brown Laboratory for Linguistic Information Processing 211 May 29, 2022
Header-only, non-intrusive and macro-free runtime reflection system in C++

Header-only runtime reflection system in C++ The reflection system was born within EnTT and is developed and enriched there. This project is designed

Michele Caini 418 Jun 21, 2022
Customizable C++17 Runtime Reflection Library

Refureku Check the Wiki for more documentation and use examples! Refureku is a powerful C++17 RTTI free runtime reflection library based on Kodgen. It

Julien SOYSOUVANH 164 Jun 12, 2022
High-performance C++ multibody dynamics/physics library for simulating articulated biomechanical and mechanical systems like vehicles, robots, and the human skeleton.

Simbody Simbody is a high-performance, open-source toolkit for science- and engineering-quality simulation of articulated mechanisms, including biomec

Simbody Project 1.9k Jun 27, 2022
Assignment skeleton for course on Discrete Differential Geometry (15-458/858)

ddg-exercises This repo contains C++ skeleton code for course assignments from Discrete Differential Geometry (15-458/858). For the JavaScript version

Geometry Collective 67 May 24, 2022
Unreal Engine Plugin to wrap Nuitrack SDK ( skeleton tracking solution by 3DiVi )

Nuitrack for Unreal Engine Unreal Engine plugin to bridge Nuitrack. Nuitrack is a middleware to provide 3d skeleton tracking solution using a depth se

Ayumu Nagamatsu 10 Jun 14, 2022
Skeleton of a C++ command line application

Here is an example of a command line C++ application. Anytime you want to start a new command line tool in C++, feel free to use this code as a skelet

Serge Vakulenko 2 Mar 27, 2022
A skeleton C compiler in C++

cppc C compiler in C++ Background This is a learning project for Crafting interpreters. Most part of C is supported. Support for pointer is hacky. For

Yujia Qiao 6 Feb 10, 2022
Spooky, scary skeleton!

PS4 Skeleton Synopsis A "base" package for those interested in creating homebrew with the Open Orbis Toolchain. It include functions that set up easy

Al Azif 12 Mar 6, 2022
🦴 Takes base Rokoko animation export and uses my pre-made bone remapping to map to the default UE4 skeleton.

?? RokokoToUE4-pipeline ?? Takes base rokoko animation export and uses my pre-made bone remapping to map to the default UE4 skeleton. How to use: Down

Matthew Jigalin 3 Jan 10, 2022
tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)

PicoHTTPParser Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase, Shigeo Mitsunari PicoHTTPParser is a tiny, primitive, fast HTTP r

H2O 1.5k Jun 22, 2022
Fast C/C++ CSS Parser (Cascading Style Sheets Parser)

MyCSS — a pure C CSS parser MyCSS is a fast CSS Parser implemented as a pure C99 library with the ability to build without dependencies. Mailing List:

Alexander 119 Jun 18, 2022
udmp-parser: A Windows user minidump C++ parser library.

udmp-parser: A Windows user minidump C++ parser library. This is a cross-platform (Windows / Linux / OSX / x86 / x64) C++ library that parses Windows

Axel Souchet 89 Jun 23, 2022
C++ reflection library with Lua binding, and JSON and XML serialisation.

Ponder Linux & OSX: - Windows: Currents status: 3.2-alpha. API is unstable as features added/changed. New: Version 3 V1 replaced Boost with C++11. V2

Bill Quith 545 Jun 20, 2022
C++ Reflection Library

!New Release - 0.9.6! RTTR C++ Reflection Library RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspe

rttr.org 2.2k Jun 20, 2022
A miniature library for struct-field reflection in C++

visit_struct A header-only library providing structure visitors for C++11 and C++14. Motivation In C++ there is no built-in way to iterate over the me

null 347 Jun 24, 2022
config-loader is a static reflection framework written in C++17 from parse configuration file to native data structure.

config-loader is a static reflection framework written in C++17 from parse configuration file to native data structure.

Netcan 94 Jun 23, 2022
Selective Compile-Time Reflection for C++

Introspective Some quotes from StackOverflow regarding reflection in C++: "Inspection by iterating over members of a type, enumerating its methods and

Josip Palavra 26 Mar 10, 2022