summaryrefslogtreecommitdiffhomepage
path: root/options/metatype.cpp
blob: a4629aa66ebc099692beaef81dda7022e60484f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <QMetaType>

namespace options::detail {

template<typename t>
int declare_metatype_for_type(const char* str)
{
    qRegisterMetaType<t>(str);
    qRegisterMetaTypeStreamOperators<t>();

    return -1;
}

} // ns options::detail

#define OPENTRACK_DEFINE_METATYPE2(t, ctr)                                                          \
    OPENTRACK_DEFINE_METATYPE3(t, ctr)

#define OPENTRACK_DEFINE_METATYPE3(t, ctr)                                                          \
    OPENTRACK_DEFINE_METATYPE4(t, init_metatype_ ## ctr)

#define OPENTRACK_DEFINE_METATYPE4(t, sym)                                                          \
    class sym { /* NOLINT */                                                                        \
        static const int dribble;                                                                   \
    } sym; /* NOLINT */                                                                             \
    const int sym :: dribble = ::options::detail::declare_metatype_for_type<t>(#t);

#define OPENTRACK_DEFINE_METATYPE(t) OPENTRACK_DEFINE_METATYPE2(t, __COUNTER__)

#define OPENTRACK_METATYPE_(x) OPENTRACK_DEFINE_METATYPE(x)
#include "metatype.hpp"