Mercurial > projects > dbus-d
view dbus-d/dsrc/org/freedesktop/dbus/Variant.d @ 5:7c2c75740370
code generation for signals
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 21 Oct 2007 19:22:41 +0200 |
parents | a5576806d36d |
children |
line wrap: on
line source
/* * Copyright (C) 2007 Frank Benoit * * Licensed under the Academic Free License version 2.1 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ module org.freedesktop.dbus.Variant; //import tango.core.Variant; import org.freedesktop.dbus.c.Protocol; import org.freedesktop.dbus.Struct; //alias Variant DBusVariant; abstract class DBusVariant { abstract public char[] getSig(); } template DBusTypeIdFromDType(T){ //pragma( msg, "DBusTypeIdFromDType: "~typeof(T).stringof ); static if(false){} else static if( is( T == char[] ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_STRING; } else static if( is( T == bool ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BOOLEAN; } else static if( is( T == byte ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_BYTE; } else static if( is( T == short ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT16; } else static if( is( T == ushort ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT16; } else static if( is( T == int ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT32; } else static if( is( T == uint ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT32; } else static if( is( T == long ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_INT64; } else static if( is( T == ulong ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_UINT64; } else static if( is( T == double ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_DOUBLE; } else static if( is( T : DBusVariant ) ){ const int DBusTypeIdFromDType = DBUS_TYPE_VARIANT; } else static assert(false); } class DBusVariantValue( T ) : DBusVariant { public T value; static const char sig = DBusTypeIdFromDType!(T); public char[] getSig(){ return [sig]; } } alias DBusVariantValue!( bool ) DBusVariantValueBool; alias DBusVariantValue!( byte ) DBusVariantValueByte; alias DBusVariantValue!( short ) DBusVariantValueShort; alias DBusVariantValue!( ushort ) DBusVariantValueUShort; alias DBusVariantValue!( int ) DBusVariantValueInt; alias DBusVariantValue!( uint ) DBusVariantValueUInt; alias DBusVariantValue!( long ) DBusVariantValueLong; alias DBusVariantValue!( ulong ) DBusVariantValueULong; alias DBusVariantValue!( double ) DBusVariantValueDouble; alias DBusVariantValue!( char[] ) DBusVariantValueString; alias DBusVariantValue!( DBusVariant ) DBusVariantValueVariant; class DBusVariantStruct : DBusVariant { public DBusVariant[] values; public this(){ } public char[] getSig(){ char[] res = DBUS_STRUCT_BEGIN_CHAR_AS_STRING; foreach( value; values ){ res ~= value.getSig(); } res ~= DBUS_STRUCT_END_CHAR_AS_STRING; return res; } } class DBusVariantArray : DBusVariant { private char[] sig; public DBusVariant[] values; public this( char[] sig ){ this.sig = DBUS_TYPE_ARRAY_AS_STRING ~ sig; } public char[] getSig(){ return sig; } } struct DBusVariantMapItem{ DBusVariant key; DBusVariant value; } class DBusVariantMap : DBusVariant { public DBusVariantMapItem[] values; private char[] sig; public this( char[] sigKey, char[] sigValue ){ sig = DBUS_TYPE_ARRAY_AS_STRING ~ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING ~ sigKey ~ sigValue ~ DBUS_DICT_ENTRY_END_CHAR_AS_STRING; } public char[] getSig(){ return sig; } }