Skip to content

Commit

Permalink
Don't Cast Returned interfaces to the minimal implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeWey committed Jun 16, 2013
1 parent 5073a70 commit ab66408
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/gio/AppInfoT.d
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public template AppInfoT(TStruct)
{
foreach ( void delegate(AppInfoIF, GVariant*, AppInfoIF) dlg ; _appInfoIF.onLaunchedListeners )
{
dlg(ObjectG.getDObject!(AppInfo)(arg1), arg2, _appInfoIF);
dlg(ObjectG.getDObject!(AppInfo, AppInfoIF)(arg1), arg2, _appInfoIF);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/gio/DBusObjectManagerT.d
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public template DBusObjectManagerT(TStruct)
{
foreach ( void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg ; _dBusObjectManagerIF.onInterfaceAddedListeners )
{
dlg(ObjectG.getDObject!(DBusObject)(object), ObjectG.getDObject!(DBusInterface)(iface), _dBusObjectManagerIF);
dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), _dBusObjectManagerIF);
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public template DBusObjectManagerT(TStruct)
{
foreach ( void delegate(DBusObjectIF, DBusInterfaceIF, DBusObjectManagerIF) dlg ; _dBusObjectManagerIF.onInterfaceRemovedListeners )
{
dlg(ObjectG.getDObject!(DBusObject)(object), ObjectG.getDObject!(DBusInterface)(iface), _dBusObjectManagerIF);
dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), _dBusObjectManagerIF);
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ public template DBusObjectManagerT(TStruct)
{
foreach ( void delegate(DBusObjectIF, DBusObjectManagerIF) dlg ; _dBusObjectManagerIF.onObjectAddedListeners )
{
dlg(ObjectG.getDObject!(DBusObject)(object), _dBusObjectManagerIF);
dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), _dBusObjectManagerIF);
}
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public template DBusObjectManagerT(TStruct)
{
foreach ( void delegate(DBusObjectIF, DBusObjectManagerIF) dlg ; _dBusObjectManagerIF.onObjectRemovedListeners )
{
dlg(ObjectG.getDObject!(DBusObject)(object), _dBusObjectManagerIF);
dlg(ObjectG.getDObject!(DBusObject, DBusObjectIF)(object), _dBusObjectManagerIF);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gio/DBusObjectT.d
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public template DBusObjectT(TStruct)
{
foreach ( void delegate(DBusInterfaceIF, DBusObjectIF) dlg ; _dBusObjectIF.onInterfaceAddedListeners )
{
dlg(ObjectG.getDObject!(DBusInterface)(iface), _dBusObjectIF);
dlg(ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), _dBusObjectIF);
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ public template DBusObjectT(TStruct)
{
foreach ( void delegate(DBusInterfaceIF, DBusObjectIF) dlg ; _dBusObjectIF.onInterfaceRemovedListeners )
{
dlg(ObjectG.getDObject!(DBusInterface)(iface), _dBusObjectIF);
dlg(ObjectG.getDObject!(DBusInterface, DBusInterfaceIF)(iface), _dBusObjectIF);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gio/SocketClient.d
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public class SocketClient : ObjectG
{
foreach ( void delegate(GSocketClientEvent, SocketConnectableIF, IOStream, SocketClient) dlg ; _socketClient.onListeners )
{
dlg(event, ObjectG.getDObject!(SocketConnectable)(connectable), ObjectG.getDObject!(IOStream)(connection), _socketClient);
dlg(event, ObjectG.getDObject!(SocketConnectable, SocketConnectableIF)(connectable), ObjectG.getDObject!(IOStream)(connection), _socketClient);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/gio/VolumeMonitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(DriveIF, VolumeMonitor) dlg ; _volumeMonitor.onDriveChangedListeners )
{
dlg(ObjectG.getDObject!(Drive)(drive), _volumeMonitor);
dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumeMonitor);
}
}

Expand All @@ -199,7 +199,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(DriveIF, VolumeMonitor) dlg ; _volumeMonitor.onDriveConnectedListeners )
{
dlg(ObjectG.getDObject!(Drive)(drive), _volumeMonitor);
dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumeMonitor);
}
}

Expand All @@ -226,7 +226,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(DriveIF, VolumeMonitor) dlg ; _volumeMonitor.onDriveDisconnectedListeners )
{
dlg(ObjectG.getDObject!(Drive)(drive), _volumeMonitor);
dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumeMonitor);
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(DriveIF, VolumeMonitor) dlg ; _volumeMonitor.onDriveEjectButtonListeners )
{
dlg(ObjectG.getDObject!(Drive)(drive), _volumeMonitor);
dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumeMonitor);
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(DriveIF, VolumeMonitor) dlg ; _volumeMonitor.onDriveStopButtonListeners )
{
dlg(ObjectG.getDObject!(Drive)(drive), _volumeMonitor);
dlg(ObjectG.getDObject!(Drive, DriveIF)(drive), _volumeMonitor);
}
}

Expand All @@ -309,7 +309,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(MountIF, VolumeMonitor) dlg ; _volumeMonitor.onMountAddedListeners )
{
dlg(ObjectG.getDObject!(Mount)(mount), _volumeMonitor);
dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumeMonitor);
}
}

Expand All @@ -336,7 +336,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(MountIF, VolumeMonitor) dlg ; _volumeMonitor.onMountChangedListeners )
{
dlg(ObjectG.getDObject!(Mount)(mount), _volumeMonitor);
dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumeMonitor);
}
}

Expand All @@ -363,7 +363,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(MountIF, VolumeMonitor) dlg ; _volumeMonitor.onMountPreUnmountListeners )
{
dlg(ObjectG.getDObject!(Mount)(mount), _volumeMonitor);
dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumeMonitor);
}
}

Expand All @@ -390,7 +390,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(MountIF, VolumeMonitor) dlg ; _volumeMonitor.onMountRemovedListeners )
{
dlg(ObjectG.getDObject!(Mount)(mount), _volumeMonitor);
dlg(ObjectG.getDObject!(Mount, MountIF)(mount), _volumeMonitor);
}
}

Expand All @@ -417,7 +417,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(VolumeIF, VolumeMonitor) dlg ; _volumeMonitor.onVolumeAddedListeners )
{
dlg(ObjectG.getDObject!(Volume)(volume), _volumeMonitor);
dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumeMonitor);
}
}

Expand All @@ -444,7 +444,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(VolumeIF, VolumeMonitor) dlg ; _volumeMonitor.onVolumeChangedListeners )
{
dlg(ObjectG.getDObject!(Volume)(volume), _volumeMonitor);
dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumeMonitor);
}
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public class VolumeMonitor : ObjectG
{
foreach ( void delegate(VolumeIF, VolumeMonitor) dlg ; _volumeMonitor.onVolumeRemovedListeners )
{
dlg(ObjectG.getDObject!(Volume)(volume), _volumeMonitor);
dlg(ObjectG.getDObject!(Volume, VolumeIF)(volume), _volumeMonitor);
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/gobject/ObjectG.d
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,27 @@ public class ObjectG
* obj = GObject containing the associations.
* Returns: the D Object if found, or a newly constructed object if no such Object exists.
*/
public static T getDObject(T, U)(U obj)
public static RT getDObject(T, RT=T, U)(U obj)
{
if ( obj is null )
return null;
{
return null;
}

static if ( is(T : ObjectG) )
{
auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject"));

if ( p !is null )
{
return cast(T)p;
static if ( is(RT == interface ) )
{
return cast(RT)cast(ObjectG)p;
}
else
{
return cast(RT)p;
}
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/gtk/CellArea.d
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public class CellArea : ObjectG, BuildableIF, CellLayoutIF
{
foreach ( void delegate(CellRenderer, CellEditableIF, GdkRectangle*, string, CellArea) dlg ; _cellArea.onAddEditableListeners )
{
dlg(ObjectG.getDObject!(CellRenderer)(renderer), ObjectG.getDObject!(CellEditable)(editable), cellArea, Str.toString(path), _cellArea);
dlg(ObjectG.getDObject!(CellRenderer)(renderer), ObjectG.getDObject!(CellEditable, CellEditableIF)(editable), cellArea, Str.toString(path), _cellArea);
}
}

Expand Down Expand Up @@ -416,7 +416,7 @@ public class CellArea : ObjectG, BuildableIF, CellLayoutIF
{
foreach ( void delegate(TreeModelIF, TreeIter, gboolean, gboolean, CellArea) dlg ; _cellArea.onApplyAttributesListeners )
{
dlg(ObjectG.getDObject!(TreeModel)(model), ObjectG.getDObject!(TreeIter)(iter), isExpander, isExpanded, _cellArea);
dlg(ObjectG.getDObject!(TreeModel, TreeModelIF)(model), ObjectG.getDObject!(TreeIter)(iter), isExpander, isExpanded, _cellArea);
}
}

Expand Down Expand Up @@ -479,7 +479,7 @@ public class CellArea : ObjectG, BuildableIF, CellLayoutIF
{
foreach ( void delegate(CellRenderer, CellEditableIF, CellArea) dlg ; _cellArea.onRemoveEditableListeners )
{
dlg(ObjectG.getDObject!(CellRenderer)(renderer), ObjectG.getDObject!(CellEditable)(editable), _cellArea);
dlg(ObjectG.getDObject!(CellRenderer)(renderer), ObjectG.getDObject!(CellEditable, CellEditableIF)(editable), _cellArea);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gtk/CellRenderer.d
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public class CellRenderer : ObjectG
{
foreach ( void delegate(CellEditableIF, string, CellRenderer) dlg ; _cellRenderer.onEditingStartedListeners )
{
dlg(ObjectG.getDObject!(CellEditable)(editable), Str.toString(path), _cellRenderer);
dlg(ObjectG.getDObject!(CellEditable, CellEditableIF)(editable), Str.toString(path), _cellRenderer);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gtk/EntryCompletion.d
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public class EntryCompletion : ObjectG, BuildableIF, CellLayoutIF
{
foreach ( bool delegate(TreeModelIF, TreeIter, EntryCompletion) dlg ; _entryCompletion.onCursorOnMatchListeners )
{
if ( dlg(ObjectG.getDObject!(TreeModel)(model), ObjectG.getDObject!(TreeIter)(iter), _entryCompletion) )
if ( dlg(ObjectG.getDObject!(TreeModel, TreeModelIF)(model), ObjectG.getDObject!(TreeIter)(iter), _entryCompletion) )
{
return 1;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ public class EntryCompletion : ObjectG, BuildableIF, CellLayoutIF
{
foreach ( bool delegate(TreeModelIF, TreeIter, EntryCompletion) dlg ; _entryCompletion.onMatchSelectedListeners )
{
if ( dlg(ObjectG.getDObject!(TreeModel)(model), ObjectG.getDObject!(TreeIter)(iter), _entryCompletion) )
if ( dlg(ObjectG.getDObject!(TreeModel, TreeModelIF)(model), ObjectG.getDObject!(TreeIter)(iter), _entryCompletion) )
{
return 1;
}
Expand Down
15 changes: 12 additions & 3 deletions wrap/APILookupGObject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,27 @@ code: start
* obj = GObject containing the associations.
* Returns: the D Object if found, or a newly constructed object if no such Object exists.
*/
public static T getDObject(T, U)(U obj)
public static RT getDObject(T, RT=T, U)(U obj)
{
if ( obj is null )
{
return null;

}

static if ( is(T : ObjectG) )
{
auto p = g_object_get_data(cast(GObject*)obj, Str.toStringz("GObject"));

if ( p !is null )
{
return cast(T)p;
static if ( is(RT == interface ) )
{
return cast(RT)cast(ObjectG)p;
}
else
{
return cast(RT)p;
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion wrap/utils/funct.d
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public struct Funct
}
else if (GtkDClass.endsWith(param.typeWrap, "IF"))
{
parmToGtkD = "ObjectG.getDObject!("~param.typeWrap[0..$-2]~")("~ param.convName ~")";
parmToGtkD = "ObjectG.getDObject!("~param.typeWrap[0..$-2]~", "~param.typeWrap~")("~ param.convName ~")";
}
else
{
Expand Down

0 comments on commit ab66408

Please sign in to comment.