September 28, 2008
On Sun, 28 Sep 2008 04:42:15 +0400, Sergey Gromov <snake.scaly@gmail.com> wrote:

> Sat, 27 Sep 2008 19:21:56 -0400,
> Christopher Wright wrote:
>> Sergey Gromov wrote:
>> > Sat, 27 Sep 2008 19:50:18 +0200,
>> > torhu wrote:
>> >> obj.classinfo doesn't work the way you'd expect with an interface,  
>> but
>> >> it works when you've got an object:
>> >>
>> >> writefln((cast(Object)thing).classinfo.name);
>> >
>> > Thanks for the tip!  It seems like classinfo of an interface contains
>> > information about the most derived interface implemented in an object:
>> >
>> > interface a {}
>> > interface aa : a {}
>> > class A : aa {}
>> > void main() {
>> >     writefln((cast(a) new A).classinfo.name);
>> > }
>> >
>> > prints "test.aa".  Though this functionality is of questionable
>> > usefulness (has anybody used it for something?) and besides it's  
>> broken:
>> >
>> > interface a {}
>> > interface aa : a {}
>> > class A : a, aa {}
>> > void main() {
>> >     writefln((cast(a) new A).classinfo.name);
>> > }
>> >
>> > prints "test.a" even though A implements the "aa" interface as well.
>>
>> Since .classinfo is essentially a virtual call, and interface vtbls are
>> filled from the class's vtbl, it shouldn't in theory be terribly
>> difficult to change this. Of course, I'd have to check the dmd source to
>> be sure.
>
> I'd say it's a bug.  Classinfo is for runtime class, and runtime class
> can never be an interface.

Do all IUknown interface instances have classinfo member? That's not a bug if they don't. That's the same reason why interfaces can't be casted to Object.
September 28, 2008
Mon, 29 Sep 2008 01:12:45 +0400,
Denis Koroskin wrote:
> On Sun, 28 Sep 2008 04:42:15 +0400, Sergey Gromov <snake.scaly@gmail.com> wrote:
> 
> > Sat, 27 Sep 2008 19:21:56 -0400,
> > Christopher Wright wrote:
> >> Since .classinfo is essentially a virtual call, and interface vtbls are filled from the class's vtbl, it shouldn't in theory be terribly difficult to change this. Of course, I'd have to check the dmd source to be sure.
> >
> > I'd say it's a bug.  Classinfo is for runtime class, and runtime class can never be an interface.
> 
> Do all IUknown interface instances have classinfo member? That's not a bug if they don't. That's the same reason why interfaces can't be casted to Object.

IUnknown cannot be a D interface because it does not comply with D ABI. IUnknown cannot have any .classinfo.  Iunknown cannot be cast to anything except by the means of QueryInterface().  You've chosen the wrong example.

Only D interfaces can have .classinfo.  You cannot instantiate a D interface, only a class.  Therefore whenever you get a reference it's either null or refers to an instantiated *class* which definitely has its one and only correct .classinfo.
October 03, 2008
Mon, 29 Sep 2008 03:02:58 +0400,
Sergey Gromov wrote:
> Mon, 29 Sep 2008 01:12:45 +0400,
> Denis Koroskin wrote:
> > On Sun, 28 Sep 2008 04:42:15 +0400, Sergey Gromov <snake.scaly@gmail.com> wrote:
> > 
> > > Sat, 27 Sep 2008 19:21:56 -0400,
> > > Christopher Wright wrote:
> > >> Since .classinfo is essentially a virtual call, and interface vtbls are filled from the class's vtbl, it shouldn't in theory be terribly difficult to change this. Of course, I'd have to check the dmd source to be sure.
> > >
> > > I'd say it's a bug.  Classinfo is for runtime class, and runtime class can never be an interface.
> > 
> > Do all IUknown interface instances have classinfo member? That's not a bug if they don't. That's the same reason why interfaces can't be casted to Object.
> 
> IUnknown cannot be a D interface because it does not comply with D ABI.

My apologies.  I didn't know that IUnknown were directly supported by a compiler as a special case of a super-interface.  Everything you say seems to be relevant now.
October 17, 2008
Did you ever figure out what you were trying to solve. typeof is evaluated at compile time so not very useful. If it helps you or anyone else reading this some sample code you may find usefull:

module test;

import tango.io.Stdout;

Object dupClass(Object o)
{
        Object newObj = o.classinfo.create;
        return newObj;
}

class Animal
{
        this(char[] name)
        {
                this.name = name;
        }
        this()
        {
                //
        }
        public char[] name;
        char[] kind()
        {
                return "animal";
        }
}

class Dog : Animal
{
        this(char[] name)
        {
                super(name);
        }
        this()
        {
                super();
        }
        char[] kind()
        {
                return "Dog";
        }
}

class Cat : Animal
{
        this(char[] name)
        {
                super(name);
        }
        this()
        {
                super();
        }
        char[] kind()
        {
                return "Cat";
        }
}

int main(char[][] args)
{
        Animal[] animals;

        Dog dog = new Dog("Scooby");
        Cat cat = new Cat("Garfield");

        /* create a new object of the same class as dog */
        animals ~= cast(Animal) dupClass(dog);

        /* new dog needs a name */
        animals[0].name = "Lassy";


        /* add the others to the array */
        animals ~= dog;
        animals ~= cat;

        foreach(Animal anim; animals)
        {
                Stdout(anim.kind~" : "~anim.name).newline;
        }

        return 0;
}



On Fri, 03 Oct 2008 14:44:11 +1300, Sergey Gromov <snake.scaly@gmail.com> wrote:

> Mon, 29 Sep 2008 03:02:58 +0400,
> Sergey Gromov wrote:
>> Mon, 29 Sep 2008 01:12:45 +0400,
>> Denis Koroskin wrote:
>> > On Sun, 28 Sep 2008 04:42:15 +0400, Sergey Gromov  
>> <snake.scaly@gmail.com>
>> > wrote:
>> >
>> > > Sat, 27 Sep 2008 19:21:56 -0400,
>> > > Christopher Wright wrote:
>> > >> Since .classinfo is essentially a virtual call, and interface  
>> vtbls are
>> > >> filled from the class's vtbl, it shouldn't in theory be terribly
>> > >> difficult to change this. Of course, I'd have to check the dmd  
>> source to
>> > >> be sure.
>> > >
>> > > I'd say it's a bug.  Classinfo is for runtime class, and runtime  
>> class
>> > > can never be an interface.
>> >
>> > Do all IUknown interface instances have classinfo member? That's not  
>> a bug
>> > if they don't. That's the same reason why interfaces can't be casted  
>> to
>> > Object.
>>
>> IUnknown cannot be a D interface because it does not comply with D ABI.
>
> My apologies.  I didn't know that IUnknown were directly supported by a
> compiler as a special case of a super-interface.  Everything you say
> seems to be relevant now.

1 2
Next ›   Last »