#include "govaluetype.h"

#define DEFINE_GOVALUETYPE(N) \
    template<> QMetaObject GoValueType<N>::staticMetaObject = QMetaObject(); \
    template<> GoTypeInfo *GoValueType<N>::typeInfo = 0; \
    template<> GoTypeSpec_ *GoValueType<N>::typeSpec = 0;

#define DEFINE_GOPAINTEDVALUETYPE(N) \
    template<> QMetaObject GoPaintedValueType<N>::staticMetaObject = QMetaObject(); \
    template<> GoTypeInfo *GoPaintedValueType<N>::typeInfo = 0; \
    template<> GoTypeSpec_ *GoPaintedValueType<N>::typeSpec = 0;

DEFINE_GOVALUETYPE(1)
DEFINE_GOVALUETYPE(2)
DEFINE_GOVALUETYPE(3)
DEFINE_GOVALUETYPE(4)
DEFINE_GOVALUETYPE(5)
DEFINE_GOVALUETYPE(6)
DEFINE_GOVALUETYPE(7)
DEFINE_GOVALUETYPE(8)
DEFINE_GOVALUETYPE(9)
DEFINE_GOVALUETYPE(10)
DEFINE_GOVALUETYPE(11)
DEFINE_GOVALUETYPE(12)
DEFINE_GOVALUETYPE(13)
DEFINE_GOVALUETYPE(14)
DEFINE_GOVALUETYPE(15)
DEFINE_GOVALUETYPE(16)
DEFINE_GOVALUETYPE(17)
DEFINE_GOVALUETYPE(18)
DEFINE_GOVALUETYPE(19)
DEFINE_GOVALUETYPE(20)
DEFINE_GOVALUETYPE(21)
DEFINE_GOVALUETYPE(22)
DEFINE_GOVALUETYPE(23)
DEFINE_GOVALUETYPE(24)
DEFINE_GOVALUETYPE(25)
DEFINE_GOVALUETYPE(26)
DEFINE_GOVALUETYPE(27)
DEFINE_GOVALUETYPE(28)
DEFINE_GOVALUETYPE(29)
DEFINE_GOVALUETYPE(30)

DEFINE_GOPAINTEDVALUETYPE(1)
DEFINE_GOPAINTEDVALUETYPE(2)
DEFINE_GOPAINTEDVALUETYPE(3)
DEFINE_GOPAINTEDVALUETYPE(4)
DEFINE_GOPAINTEDVALUETYPE(5)
DEFINE_GOPAINTEDVALUETYPE(6)
DEFINE_GOPAINTEDVALUETYPE(7)
DEFINE_GOPAINTEDVALUETYPE(8)
DEFINE_GOPAINTEDVALUETYPE(9)
DEFINE_GOPAINTEDVALUETYPE(10)
DEFINE_GOPAINTEDVALUETYPE(11)
DEFINE_GOPAINTEDVALUETYPE(12)
DEFINE_GOPAINTEDVALUETYPE(13)
DEFINE_GOPAINTEDVALUETYPE(14)
DEFINE_GOPAINTEDVALUETYPE(15)
DEFINE_GOPAINTEDVALUETYPE(16)
DEFINE_GOPAINTEDVALUETYPE(17)
DEFINE_GOPAINTEDVALUETYPE(18)
DEFINE_GOPAINTEDVALUETYPE(19)
DEFINE_GOPAINTEDVALUETYPE(20)
DEFINE_GOPAINTEDVALUETYPE(21)
DEFINE_GOPAINTEDVALUETYPE(22)
DEFINE_GOPAINTEDVALUETYPE(23)
DEFINE_GOPAINTEDVALUETYPE(24)
DEFINE_GOPAINTEDVALUETYPE(25)
DEFINE_GOPAINTEDVALUETYPE(26)
DEFINE_GOPAINTEDVALUETYPE(27)
DEFINE_GOPAINTEDVALUETYPE(28)
DEFINE_GOPAINTEDVALUETYPE(29)
DEFINE_GOPAINTEDVALUETYPE(30)

static int goValueTypeN = 0;
static int goPaintedValueTypeN = 0;

template<int N>
int registerSingletonN(char *location, int major, int minor, char *name, GoTypeInfo *info, GoTypeSpec_ *spec) {
    GoValueType<N>::init(info, spec);
    return qmlRegisterSingletonType< GoValueType<N> >(location, major, minor, name, [](QQmlEngine *qmlEngine, QJSEngine *jsEngine) -> QObject* {
        QObject *singleton = new GoValueType<N>();
        QQmlEngine::setContextForObject(singleton, qmlEngine->rootContext());
        return singleton;
    });
}

template<int N>
int registerPaintedSingletonN(char *location, int major, int minor, char *name, GoTypeInfo *info, GoTypeSpec_ *spec) {
    GoPaintedValueType<N>::init(info, spec);
    return qmlRegisterSingletonType< GoPaintedValueType<N> >(location, major, minor, name, [](QQmlEngine *qmlEngine, QJSEngine *jsEngine) -> QObject* {
        QObject *singleton = new GoPaintedValueType<N>();
        QQmlEngine::setContextForObject(singleton, qmlEngine->rootContext());
        return singleton;
    });
}

#define GOVALUETYPE_CASE_SINGLETON(N) \
        case N: return registerSingletonN<N>(location, major, minor, name, info, spec);
#define GOPAINTEDVALUETYPE_CASE_SINGLETON(N) \
        case N: return registerPaintedSingletonN<N>(location, major, minor, name, info, spec);

int registerSingleton(char *location, int major, int minor, char *name, GoTypeInfo *info, GoTypeSpec_ *spec)
{
    if (!info->paint) {
        switch (++goValueTypeN) {
        GOVALUETYPE_CASE_SINGLETON(1)
        GOVALUETYPE_CASE_SINGLETON(2)
        GOVALUETYPE_CASE_SINGLETON(3)
        GOVALUETYPE_CASE_SINGLETON(4)
        GOVALUETYPE_CASE_SINGLETON(5)
        GOVALUETYPE_CASE_SINGLETON(6)
        GOVALUETYPE_CASE_SINGLETON(7)
        GOVALUETYPE_CASE_SINGLETON(8)
        GOVALUETYPE_CASE_SINGLETON(9)
        GOVALUETYPE_CASE_SINGLETON(10)
        GOVALUETYPE_CASE_SINGLETON(11)
        GOVALUETYPE_CASE_SINGLETON(12)
        GOVALUETYPE_CASE_SINGLETON(13)
        GOVALUETYPE_CASE_SINGLETON(14)
        GOVALUETYPE_CASE_SINGLETON(15)
        GOVALUETYPE_CASE_SINGLETON(16)
        GOVALUETYPE_CASE_SINGLETON(17)
        GOVALUETYPE_CASE_SINGLETON(18)
        GOVALUETYPE_CASE_SINGLETON(19)
        GOVALUETYPE_CASE_SINGLETON(20)
        GOVALUETYPE_CASE_SINGLETON(21)
        GOVALUETYPE_CASE_SINGLETON(22)
        GOVALUETYPE_CASE_SINGLETON(23)
        GOVALUETYPE_CASE_SINGLETON(24)
        GOVALUETYPE_CASE_SINGLETON(25)
        GOVALUETYPE_CASE_SINGLETON(26)
        GOVALUETYPE_CASE_SINGLETON(27)
        GOVALUETYPE_CASE_SINGLETON(28)
        GOVALUETYPE_CASE_SINGLETON(29)
        GOVALUETYPE_CASE_SINGLETON(30)
        }
    } else {
        switch (++goPaintedValueTypeN) {
        GOPAINTEDVALUETYPE_CASE_SINGLETON(1)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(2)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(3)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(4)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(5)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(6)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(7)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(8)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(9)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(10)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(11)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(12)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(13)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(14)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(15)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(16)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(17)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(18)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(19)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(20)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(21)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(22)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(23)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(24)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(25)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(26)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(27)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(28)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(29)
        GOPAINTEDVALUETYPE_CASE_SINGLETON(30)
        }
    }
    panicf("too many registered types; please contact the Go QML developers");
    return 0;
}

#define GOVALUETYPE_CASE(N) \
    case N: GoValueType<N>::init(info, spec); return qmlRegisterType< GoValueType<N> >(location, major, minor, name);
#define GOPAINTEDVALUETYPE_CASE(N) \
    case N: GoPaintedValueType<N>::init(info, spec); return qmlRegisterType< GoPaintedValueType<N> >(location, major, minor, name);

int registerType(char *location, int major, int minor, char *name, GoTypeInfo *info, GoTypeSpec_ *spec)
{
    if (!info->paint) {
        switch (++goValueTypeN) {
        GOVALUETYPE_CASE(1)
        GOVALUETYPE_CASE(2)
        GOVALUETYPE_CASE(3)
        GOVALUETYPE_CASE(4)
        GOVALUETYPE_CASE(5)
        GOVALUETYPE_CASE(6)
        GOVALUETYPE_CASE(7)
        GOVALUETYPE_CASE(8)
        GOVALUETYPE_CASE(9)
        GOVALUETYPE_CASE(10)
        GOVALUETYPE_CASE(11)
        GOVALUETYPE_CASE(12)
        GOVALUETYPE_CASE(13)
        GOVALUETYPE_CASE(14)
        GOVALUETYPE_CASE(15)
        GOVALUETYPE_CASE(16)
        GOVALUETYPE_CASE(17)
        GOVALUETYPE_CASE(18)
        GOVALUETYPE_CASE(19)
        GOVALUETYPE_CASE(20)
        GOVALUETYPE_CASE(21)
        GOVALUETYPE_CASE(22)
        GOVALUETYPE_CASE(23)
        GOVALUETYPE_CASE(24)
        GOVALUETYPE_CASE(25)
        GOVALUETYPE_CASE(26)
        GOVALUETYPE_CASE(27)
        GOVALUETYPE_CASE(28)
        GOVALUETYPE_CASE(29)
        GOVALUETYPE_CASE(30)
        }
    } else {
        switch (++goPaintedValueTypeN) {
        GOPAINTEDVALUETYPE_CASE(1)
        GOPAINTEDVALUETYPE_CASE(2)
        GOPAINTEDVALUETYPE_CASE(3)
        GOPAINTEDVALUETYPE_CASE(4)
        GOPAINTEDVALUETYPE_CASE(5)
        GOPAINTEDVALUETYPE_CASE(6)
        GOPAINTEDVALUETYPE_CASE(7)
        GOPAINTEDVALUETYPE_CASE(8)
        GOPAINTEDVALUETYPE_CASE(9)
        GOPAINTEDVALUETYPE_CASE(10)
        GOPAINTEDVALUETYPE_CASE(11)
        GOPAINTEDVALUETYPE_CASE(12)
        GOPAINTEDVALUETYPE_CASE(13)
        GOPAINTEDVALUETYPE_CASE(14)
        GOPAINTEDVALUETYPE_CASE(15)
        GOPAINTEDVALUETYPE_CASE(16)
        GOPAINTEDVALUETYPE_CASE(17)
        GOPAINTEDVALUETYPE_CASE(18)
        GOPAINTEDVALUETYPE_CASE(19)
        GOPAINTEDVALUETYPE_CASE(20)
        GOPAINTEDVALUETYPE_CASE(21)
        GOPAINTEDVALUETYPE_CASE(22)
        GOPAINTEDVALUETYPE_CASE(23)
        GOPAINTEDVALUETYPE_CASE(24)
        GOPAINTEDVALUETYPE_CASE(25)
        GOPAINTEDVALUETYPE_CASE(26)
        GOPAINTEDVALUETYPE_CASE(27)
        GOPAINTEDVALUETYPE_CASE(28)
        GOPAINTEDVALUETYPE_CASE(29)
        GOPAINTEDVALUETYPE_CASE(30)
        }
    }
    panicf("too many registered types; please contact the Go QML developers");
    return 0;
}

// vim:sw=4:st=4:et:ft=cpp
