GitXplorerGitXplorer
h

reflectionpp

public
98 stars
14 forks
0 issues

Commits

List of commits on branch master.
Unverified
5777fd6b8388f8b02933d140695d14ff314faa87

update

hhczhcz committed 8 years ago
Unverified
04617d70c0cd4be7052e45bc29d17f0825974854

add readme

hhczhcz committed 9 years ago
Unverified
6bb07c119457facb06ad852fd539b40ecc4367a0

fix makefile

hhczhcz committed 9 years ago
Unverified
d6e4c64afcbbd3653cd56f8e975cd54e9ba99984

modify

hhczhcz committed 9 years ago
Unverified
43b538e14ec7101e45d2dea12b7163ad8a11bba0

add Ensure

hhczhcz committed 9 years ago
Unverified
f7ce3d0c8f2c01b923da70f74f7029f2157c1c81

HoldType -> GetReturn

hhczhcz committed 9 years ago

README

The README file for this repository.

Reflection++

Yet another (?) header-only C++11 reflection library.

Usage

Add meta information to an object:

struct TestStruct {
    int member1;
    float member2;
};
RPP_TYPE_OBJECT(
    __(member1)
    __(member2),
    TestStruct
)

Add meta information to an STL container:

template <class T, class... Args>
RPP_TYPE_DYNAMIC_GENERIC(T, std::vector<T, Args...>)

Create a visitor:

struct Visitor: public VisitorBase<> {
    void visit(int &value) {
        std::cerr << "int(" << value << ") ";
    }

    void visit(float &value) {
        std::cerr << "float(" << value << ") ";
    }

    template <class... Args>
    void operator()(AccessorSimple<Args...> &accessor) {
        visit(accessor());
    }

    template <class... Args>
    void operator()(AccessorObject<Args...> &accessor) {
        std::cerr << "object( ";

        for (rpp_size_t i = 0; i < accessor.size(); ++i) {
            accessor.doMemberVisit(*this, i);
        }

        std::cerr << ") ";
    }
};

Register the visitor and list all visitors:

RPP_VISITOR_REG(Visitor)
RPP_VISITOR_COLLECT(VisitorAll)

Add meta information to a variable:

TestStruct s{2, 3.5};
RPP_META_REF(s, VisitorAll) m;

Visit the variable:

Visitor v;
m.doVisit(v);

Build

Compile it like this:

clang++ -std=c++11 your_code.cpp

If you want to use the BSON visitor, bson-cxx is required.

License

LGPL v3 applies by default.