view qt/qtd/MetaMarshall.d @ 293:8627891e4556 signals

QList updates
author eldar
date Fri, 13 Nov 2009 19:09:28 +0000
parents 19498f420252
children 55ee4603365d
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(T.__isQObjectType);
}

template isObjectType(T) // is a Qt Object type that belongs to the library
{
    enum isObjectType = is(T.__isObjectType);
}

template isValueType(T) // is a Qt Value type that belongs to the library
{
    enum isValueType = is(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;
}