view qt/qtd/MetaMarshall.d @ 291:0d2094800bdb signals

QList native implementation
author eldar
date Mon, 09 Nov 2009 20:49:26 +0000
parents f9559a957be9
children 19498f420252
line wrap: on
line source

module qt.qtd.MetaMarshall;

import std.traits;

template isQObjectType(T) // is a QObject type that belongs to the library
{
    enum isQObjectType = is(typeof(mixin("T." ~ "__isQObjectType")));
}

template isObjectType(T) // is a QObject type that belongs to the library
{
    enum isQObjectType = is(typeof(mixin("T." ~ "__isObjectType")));
}

template isValueType(T) // is a QObject type that belongs to the library
{
    enum isQObjectType = is(typeof(mixin("T." ~ "__isValueType")));
}

template isNativeType(T) // type that doesn't require conversion i.e. is the same in C++ and D
{
    enum isNativeType = isNumeric!T || is(T == bool);
}

// converts an argumnent from C++ to D in qt_metacall
string metaCallArgument(T)(string ptr)
{
    static if (isQObjectType!T)
        return T.stringof ~ ".__getObject(*cast(void**)(" ~ ptr ~ "))";
    else static if (isNativeType!T)
        return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
    else
        return "*(cast(" ~ T.stringof ~ "*)" ~ ptr ~ ")";
        //res = T.stringof;
}

// converts a D argument type to C++ for registering in Qt meta system
string qtDeclArg(T)()
{
    static if (isQObjectType!T)
        return T.stringof ~ "*";
    else static if (isNativeType!T)
        return T.stringof;
    else
        return T.stringof;
}

// converts an argument from D to C++ in a signal emitter
string convertSignalArgument(T)(string arg)
{
    static if (isQObjectType!T)
        return arg ~ ".__nativeId";
    else static if (isNativeType!T)
        return arg;
    else
        return arg;
}