Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an explicit public function to get D Classes from StructCtype*? #313

Open
aferust opened this issue Nov 6, 2020 · 1 comment
Open

Comments

@aferust
Copy link

aferust commented Nov 6, 2020

For instance,

I have extern (C) int sortList1(GtkListBoxRow* _row1, GtkListBoxRow* _row2, void* userData)

I pass it as listbox.setSortFunc(&sortList1, cast(void*)this, &_destroy2);

In the sortList1 function I want to access derived members of my ListBoxRowWithData such as:

auto row1 = cast(ListBoxRowWithData)getMyDObject!ListBoxRow(_row1);
auto row2 = cast(ListBoxRowWithData)getMyDObject!ListBoxRow(_row2);
if(row1.id < row2.id) return 1;

A regular cast returns null. T opCast(T)() in ObjectG.d returns null in this case. I dug into the sources a little, and my working solution is like:

template getCType(T)
{
    static if ( is(T == class) )
        alias getCType = typeof(T.tupleof[0]);
    else
        alias getCType = void*;
}

T getMyDObject(T, TC = getCType!T)(void* data){

    T ret = ObjectG.getDObject!(T)(cast(TC)data);

    return ret;
}

Is there an existing implementation for T getMyDObject(T, TC = getCType!T)(void* data)?

@aferust aferust changed the title Is there an explicit public function to get D Classes from Ctype*? Is there an explicit public function to get D Classes from StructCtype*? Nov 6, 2020
@MikeWey
Copy link
Member

MikeWey commented Nov 7, 2020

Currently there is only ObjectG.getDObject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants