• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Metareflect is a lightweight reflection system for C++, based on LLVM and Clangs libtooling.

MetaReflect

Metareflect is a lightweight reflection system for C++, based on LLVM and Clangs libtooling.

  • Lookup members of reflected classes: Once reflection data has been generated, you can query the members of the class, inspect their types, size and where they're located in the class, as well as qualifiers and storage class.
  • Control over which classes are reflected: By annotating your class with CLASS, and each member which you want to be reflected with PROPERTY, you have fine-grained control over what you want to reflect, and what you want to keep completely private.
  • Extensible: It's easy to add new flags, which can be queried at runtime. This allows for easily adding any feature you like. Currently used to provide serialization from and to a byte stream for annotated classes.

Getting Started

To get started download the latest release here.

Setting Up The Runtime

Metareflect requires the runtime, it's consisting of the interface and a couple helper macros for annotating your classes. To include it into your project, simply copy over the /metareflect folder into your project. Unfortunately, the runtime is not fully header-only and requires you to compile the files ending in .cxx.

Annotating Your Classes

Every class which you want to be reflected needs to be annotated.

point.hxx:

#include <metareflect/metareflect.hxx>

CLASS() Point
{
public:
    PROPERTY()
    int x;

    PROPERTY()
    int y;

    PROPERTY()
    int z;

    FUNCTION()
    size_t Hash() const
    {
        return x ^ y ^ z;
    }
};

point.cxx:

#include "point.hxx"
#include "point.generated.hxx"

/* rest of the code */

For a full example take a look at our /example.

Run The Metareflect Tool

To provide the reflection data, the metareflect tool generates a header-file which contains the reflection data in a format consumable by the runtime. The generated file needs to be in your include path and included into the implementation file of the reflected class.

Since metareflect is based on libtooling, all the flags common to libtooling tools apply to it to. That means if you have a build system which can generate a compile_commands.json (for example: ninja or CMake) you can simply provide it the path to your compilation database and metareflect will pick the correct flags automatically. For further information, consult the LLVM documentation for libtooling.

To generate a compilation database using CMake, pass it -DCMAKE_EXPORT_COMPILE_COMMANDS=ON while generating your build files.

Contributing

Any contribution is welcome. Take a look at the open tickets to get started with the development of metareflect.

Requirements

  • A clone of the LLVM 6.0.0 source code, including clang and clang-extra-tools. See LLVM_SETUP how to setup LLVM for development.
  • A clone of the metareflect repository
  • A beefy computer, otherwise compiling LLVM will take some time

Structure

Metareflect consists of two parts, the runtime and the libtooling tool.

The runtime lives in the metareflect/ folder, while the tooling/ folder contains the source code for the tool.

Getting Started

Once you've cloned the LLVM repo (by following the guide at LLVM_SETUP), navigate to path/to/llvm/tools/clang/tools/extra/metareflect/metareflect. The directory contains the source code for metareflect and anything you need to get started developing metareflect.

The following resources give an insight into how to develop an libtooling application:

To contribute your changes back, please open a pull request! We welcome any contribution.

Inspiration

Parts of the design and how the tool works has been based upon prior research done in Unreal Engine 4s UHT (Unreal Header Tool) and Qts moc. If you've used either of the two, you might spot the similarities.

License

MIT License

Copyright (c) 2018 Arvid Gerstmann.

More Repositories

1

WindowsHModular

A modular Windows.h Header. Licensed under Public Domain & MIT.
C
374
star
2

VisualStudioStandalone

Make your Visual Studio Portable
Batchfile
201
star
3

ownDrop

Your One-Click upload client for ownCloud
Objective-C
53
star
4

ClangOnWindows

Source code for my blog post:
Batchfile
43
star
5

ActionBar-with-Tabs

Example for ActionBar with Tabs
Java
36
star
6

ScreenRecorder-for-Android

Use the new Android 4.4 screen recording feature, to record your screen. Requires root access!
Shell
30
star
7

PackCC

PackCC is a packrat parser generator for C.
C
22
star
8

gpulib

C++
16
star
9

Generic-Makefile

Generic Makefile for your C / C++ projects
Makefile
15
star
10

p4fs

Perforce as Filesystem in Userspace (FUSE)
C
11
star
11

dotfiles

My dotfiles
Vim Script
10
star
12

TinyAnalytics

A lightweight library for Google Analytics.
Objective-C
10
star
13

SteamBMC

*Working* fork of the original SteamBMC
Python
9
star
14

fastbuild-example

Example Repository for my Meeting C++ Lightning Talk
C++
9
star
15

thor

C
9
star
16

BashBuild

Replace CMake with less than 100 lines of Bash
Shell
8
star
17

std-sort-in-c

C
5
star
18

SignatureView

SignatureView for iOS / Android
Java
4
star
19

Ultimate-Blackwatch

Ultimate Blackwatch for iOS
Objective-C
4
star
20

Line-Counter-For-Android

C++
4
star
21

tinyprofiler

Json generator for about:tracing / chrome://tracing profiler
C
4
star
22

bob

C
3
star
23

fbxconvert

3
star
24

compile-multiarch-ios

Simple bash script to compile a static library for multiple architectures
Shell
3
star
25

meta

An exercise in exploring compile time code generation in C++
C++
3
star
26

AOKP-Easy-Compile

Shell
2
star
27

gccbug

C
2
star
28

MoneyTracker-Strings

String Resources for Money Tracker, available for Translation.
2
star
29

Color-Schemes

My personal color schemes for the applications I use
2
star
30

flycamera

C
2
star
31

advent_of_code_2020

Yet another Advent of Code. This time, it's in rust.
Rust
1
star
32

golang-devops-test

Go
1
star
33

XBMC-Repository

Leandros' Repository for all XBMC Stuff
Python
1
star
34

peg-leg

Recursive-descent parser generator for C.
C
1
star
35

rust-node-napi

Trying to trick Nodejs
Rust
1
star
36

breakpad-mirror

C++
1
star
37

convertPlistToJson

Convert PLIST files to JSON
Objective-C
1
star
38

cheatsheets

Various cheatsheets for software I use
1
star
39

AdventOfCode

The answers to the Advent of Code
C
1
star
40

dyld-bug

Objective-C
1
star
41

resize

Resize script for Mac OS X command line
Shell
1
star
42

Sketch-AndroidStudio

Automatically export assets from Sketch into Android Studio
Java
1
star
43

vim-misc

My miscellaneous vim syntaxes and other stuff
Vim Script
1
star
44

python-devops-test

Python
1
star