Re: function to resize a UML class object's extent?

Le ven, nov 30, 2001, à 01:06:35 -0600, Lars Clausen a écrit:

I was thinking of the vtable things, and AFAIR it doesn't really do
inheritance.  If a sub'class' of Connection has a NULL in its vtable, it
doesn't mean the superclass's function gets called.  Is there anything
prohibiting the class constructor from copying functions from the
superclass when the vtable has a NULL?

It's 100% manual ; you do what you want. Oh, I think I see what you really

typedef struct { .... } A_ops;
typedef struct { A_ops* ops; .... } A;

typedef struct { A_ops a_ops; .... } B_ops;
typedef struct { A a; .... } B;

static B_ops B_vtable = { { a_op1,  
                            NULL, /* meaning, implicit a_op3 */
                          NULL, /* meaning, implicit b_op2 */
                          b_op3 };

void a_init(A* a) { 
   if (!(a->ops->op1)) a->ops->op1 = a_op1;
   if (!(a->ops->op2)) a->ops->op2 = a_op2;
   if (!(a->ops->op3)) a->ops->op3 = a_op3;
   /* init of the A objet itself */

void b_init(B* b) {
  A_ops* a_ops = &b->a.ops;
  B_ops* b_ops = (B_ops*)a_ops;
  A* a = &b->a;

  if (!b_ops->op1) b_ops->op1 = b_op1;
  if (!b_ops->op2) b_ops->op2 = b_op1;
  if (!b_ops->op3) b_ops->op3 = b_op1;

(of course, dia does things slightly differently)
I see nothing wrong with that (except a few nanoseconds at instance
construction). The day we allow C99 litterals, we'll be able to remove a lot
of clutter from the operations structures. However, how does this stuff
relate to GObject ? Isn't GObject supposed to provide these mechanisms
already ?

        -- Cyrille


Lars Clausen (| Hårdgrim of Numenor
"I do not agree with a word that you say, but I   |----------------------------
will defend to the death your right to say it."   | Where are we going, and
    --Evelyn Beatrice Hall paraphrasing Voltaire  | what's with the handbasket?
Dia-list mailing list
Dia-list gnome org


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]