Re: [vos-d] Message handler problem

2007-03-17 Thread Reed Hedges

> 
> Another thought: does your derived class *have* to inherit Base virtually?

Yes, basically. Well, in one case it doesn't and calling the method in 
the base class to register the handler works.  In another case it has to 
be virtual.

Maybe I can find a way to reorganize things to avoid it.

Reed

___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-16 Thread Ken Taylor
Reed Hedges wrote:
>
> For one thing, apparently you can't do this:
>
> class Base {
> public:
>   virtual void pure() = 0;
>   template register() {
> VobjectBase::registerHandler("message", &handler);
>   }
>   void handler(Message *m) {
> ...
>   }
> };
>
> class VirtualDerived : public virtual Base {
> public:
>   VirtualDerived() {
> Base::register();
>   }
>   virtual void pure() { ... };
> };
>

Another thought: does your derived class *have* to inherit Base virtually?
Are Base and VirtualDerived both meta-objects? Would there ever be a case
where you need to use multiple inheritance of two meta-objects? That
actually seems like a bad idea to me... If an object needs the functionality
of two meta-objects, just give it those types directly rather than making a
new meta-object class that tries to incorporate them both.

So if you don't ever need to multiply-inherit two meta-object types, there's
no need to inherit virutally. And if you don't inherit virtually, the
compiler should be able to convert (or if not, you should be able to cast) a
Base::* to a Derived::*, making the register() function work ok.

Still haven't tested it for myself, though :P

-Ken


___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-16 Thread Braden McDaniel
On Thu, 2007-03-15 at 23:39 -0700, Ken Taylor wrote:
> Ken Taylor wrote:
> > Reed Hedges wrote:
> > > Peter Amstutz wrote:
> > > > Try
> > > >
> > > >template register() {
> > > >  VobjectBase::registerHandler("message", &T::handler);
> > > >}
> > > >
> > > > (note T::handler)
> > >
> > > Same problem -- it can't use the method in the base class when the
> > > template parameter is the derived class--
> > >
> >
> > Could you use casting to make the compiler happy? Something like:
> >
> >   template register() {
> > VobjectBase::registerHandler("message", ( void (T::*)(Message*) )
> > &handler);
> >   }
> >
> > ... it should be safe to cast a pointer-to-base-class-member down to a
> > pointer-to-derived-class-member. Maybe a dynamic_cast is necessary instead
> > (especially in the case of a virtual derived class)? But I'm too lazy to
> > actually test any of this out right now ;)
> >
> 
> http://www.kuzbass.ru:8086/docs/isocpp/conv.html#conv.mem
> 
> Ick... it looks like you can't do this conversion with virtual inheritance
> :/
> 
> What the hell? If member function pointers are smart enough to resolve
> virtual functions, then why couldn't they resolve virtual inheritance, given
> that there's enough information to recognize that it's virutal inheritance
> at compile-time?

Because recognizing that virtual inheritance is involved is the extent
of what can happen at compile time. Introducing virtual inheritance
means that the class layout cannot be resolved at compile time. The
(somewhat) more familiar consequence of this is that dynamic_cast must
be used to downcast from a virtual base (rather than static_cast, which
is sufficient for nonvirtual bases).

-- 
Braden McDaniel   e-mail: <[EMAIL PROTECTED]>
Jabber: <[EMAIL PROTECTED]>



___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Ken Taylor
Ken Taylor wrote:
> Ken Taylor wrote:
> > Reed Hedges wrote:
> > > Peter Amstutz wrote:
> > > > Try
> > > >
> > > >template register() {
> > > >  VobjectBase::registerHandler("message", &T::handler);
> > > >}
> > > >
> > > > (note T::handler)
> > >
> > > Same problem -- it can't use the method in the base class when the
> > > template parameter is the derived class--
> > >
> >
> > Could you use casting to make the compiler happy? Something like:
> >
> >   template register() {
> > VobjectBase::registerHandler("message", ( void (T::*)(Message*) )
> > &handler);
> >   }
> >
> > ... it should be safe to cast a pointer-to-base-class-member down to a
> > pointer-to-derived-class-member. Maybe a dynamic_cast is necessary
instead
> > (especially in the case of a virtual derived class)? But I'm too lazy to
> > actually test any of this out right now ;)
> >
>
> http://www.kuzbass.ru:8086/docs/isocpp/conv.html#conv.mem
>
> Ick... it looks like you can't do this conversion with virtual inheritance
> :/
>
> What the hell? If member function pointers are smart enough to resolve
> virtual functions, then why couldn't they resolve virtual inheritance,
given
> that there's enough information to recognize that it's virutal inheritance
> at compile-time?
>
> Oh well. Looks like you might just have to add a message-handler stub in
the
> derived class that calls the base class or something, then use Peter's
> method for registering it.

Actually I guess this is the relevent section
http://www.kuzbass.ru:8086/docs/isocpp/expr.html#expr.cast (point -7-)

Same deal though.

-Ken


___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Ken Taylor
Ken Taylor wrote:
> Reed Hedges wrote:
> > Peter Amstutz wrote:
> > > Try
> > >
> > >template register() {
> > >  VobjectBase::registerHandler("message", &T::handler);
> > >}
> > >
> > > (note T::handler)
> >
> > Same problem -- it can't use the method in the base class when the
> > template parameter is the derived class--
> >
>
> Could you use casting to make the compiler happy? Something like:
>
>   template register() {
> VobjectBase::registerHandler("message", ( void (T::*)(Message*) )
> &handler);
>   }
>
> ... it should be safe to cast a pointer-to-base-class-member down to a
> pointer-to-derived-class-member. Maybe a dynamic_cast is necessary instead
> (especially in the case of a virtual derived class)? But I'm too lazy to
> actually test any of this out right now ;)
>

http://www.kuzbass.ru:8086/docs/isocpp/conv.html#conv.mem

Ick... it looks like you can't do this conversion with virtual inheritance
:/

What the hell? If member function pointers are smart enough to resolve
virtual functions, then why couldn't they resolve virtual inheritance, given
that there's enough information to recognize that it's virutal inheritance
at compile-time?

Oh well. Looks like you might just have to add a message-handler stub in the
derived class that calls the base class or something, then use Peter's
method for registering it.

-Ken


___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Ken Taylor
Reed Hedges wrote:
> Peter Amstutz wrote:
> > Try
> >
> >template register() {
> >  VobjectBase::registerHandler("message", &T::handler);
> >}
> >
> > (note T::handler)
>
> Same problem -- it can't use the method in the base class when the
> template parameter is the derived class--
>

Could you use casting to make the compiler happy? Something like:

  template register() {
VobjectBase::registerHandler("message", ( void (T::*)(Message*) )
&handler);
  }

... it should be safe to cast a pointer-to-base-class-member down to a
pointer-to-derived-class-member. Maybe a dynamic_cast is necessary instead
(especially in the case of a virtual derived class)? But I'm too lazy to
actually test any of this out right now ;)

-Ken


___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Reed Hedges
Peter Amstutz wrote:
> Try
> 
>template register() {
>  VobjectBase::registerHandler("message", &T::handler);
>}
> 
> (note T::handler)

Same problem -- it can't use the method in the base class when the
template parameter is the derived class--

A smaller example:

This won't compile because func() is in A not B, but B is passed in as T
in useMethPtr():

class A {
public:
template void useMethPtr() {
void(T::* fp)() = &T::func;
}
void func() { }
};

class B : public virtual A {
public:
B() {
A::useMethPtr();
}
};

VobjectBase uses the class name template parameter both for the typeid
string and for the class that the handler method is in. In my case I
want them to be different classes (because the handler method is in a
different class than the final MetaObject instance's class).  I.e.
something like

class Base {
protected:
   template void registerMessageHandlers() {
   VobjectBase::addMessageHandler("message",
&Base::handleMessage);
}
void handleMessage(Message *m) { }
};

class Derived : public virtual Base, MetaObject {
public:
  Derived() {
registerMessageHandlers();
  }
};


Maybe?

___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Peter Amstutz
Try

   template register() {
 VobjectBase::registerHandler("message", &T::handler);
   }

(note T::handler)

This should work, this is exactly how it works in s5.

On Thu, Mar 15, 2007 at 04:49:17PM -0400, Reed Hedges wrote:
> 
> For one thing, apparently you can't do this:
> 
> class Base {
> public:
>   virtual void pure() = 0;
>   template register() {
> VobjectBase::registerHandler("message", &handler);
>   }
>   void handler(Message *m) {
> ...
>   }
> };
> 
> class VirtualDerived : public virtual Base {
> public:
>   VirtualDerived() {
> Base::register();
>   }
>   virtual void pure() { ... };
> };
> 
> ___
> vos-d mailing list
> vos-d@interreality.org
> http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d

-- 
[   Peter Amstutz  ][ [EMAIL PROTECTED] ][ [EMAIL PROTECTED] ]
[Lead Programmer][Interreality Project][Virtual Reality for the Internet]
[ VOS: Next Generation Internet Communication][ http://interreality.org ]
[ http://interreality.org/~tetron ][ pgpkey:  pgpkeys.mit.edu  18C21DF7 ]



signature.asc
Description: Digital signature
___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Peter Amstutz
On Thu, Mar 15, 2007 at 04:11:41PM -0400, Reed Hedges wrote:
> Peter Amstutz wrote:
> > That's something that was introduced by the new event tables 
> > implementation in 0.24.  The solution is to make the registration 
> > function a templated class, and for the subclass to call the base class 
> > registration function with the subclass type to ensure that the method 
> > handlers are associated with the subclass as well as the base class.
> 
> Well, is there a way to avoid the subclass having to do this? I'm trying
> to make it easy to make a subclass of a local MetaObjects.   I haven't
> thought of a way yet but I didn't look too deeply into the way it stores
> the function pointers in VobjectBase yet...

Possibly, if typeid(this) in the base class will produce the typeinfo 
for the subclass, or the typeinfo can be propagated up some other way.  
The way the mechanism works is by getting the typeid() of the target 
vobject, looking that up in a table mapping object types to method 
pointers, then casting to the concrete type and calling the method in 
question.  It's the lookup step (where it maps from the concrete type to 
the handler) that it fails if the method has been registered by the base 
class but not the subclass.

-- 
[   Peter Amstutz  ][ [EMAIL PROTECTED] ][ [EMAIL PROTECTED] ]
[Lead Programmer][Interreality Project][Virtual Reality for the Internet]
[ VOS: Next Generation Internet Communication][ http://interreality.org ]
[ http://interreality.org/~tetron ][ pgpkey:  pgpkeys.mit.edu  18C21DF7 ]



signature.asc
Description: Digital signature
___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Reed Hedges

For one thing, apparently you can't do this:

class Base {
public:
  virtual void pure() = 0;
  template register() {
VobjectBase::registerHandler("message", &handler);
  }
  void handler(Message *m) {
...
  }
};

class VirtualDerived : public virtual Base {
public:
  VirtualDerived() {
Base::register();
  }
  virtual void pure() { ... };
};

___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Reed Hedges
Peter Amstutz wrote:
> That's something that was introduced by the new event tables 
> implementation in 0.24.  The solution is to make the registration 
> function a templated class, and for the subclass to call the base class 
> registration function with the subclass type to ensure that the method 
> handlers are associated with the subclass as well as the base class.

Well, is there a way to avoid the subclass having to do this? I'm trying
to make it easy to make a subclass of a local MetaObjects.   I haven't
thought of a way yet but I didn't look too deeply into the way it stores
the function pointers in VobjectBase yet...

Reed

___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


Re: [vos-d] Message handler problem

2007-03-15 Thread Peter Amstutz
That's something that was introduced by the new event tables 
implementation in 0.24.  The solution is to make the registration 
function a templated class, and for the subclass to call the base class 
registration function with the subclass type to ensure that the method 
handlers are associated with the subclass as well as the base class.

On Thu, Mar 15, 2007 at 02:40:06PM -0400, Reed Hedges wrote:
> 
> 
> Ran into a slightly confusing thing that VOS does:
> 
> If a base class registers a message handler, but then a subclass of that
> base class is the metaobject that's actually instantiated, then no
> messages can be delivered to that handler-- it seems that the list of
> handlers is keyed on typeid names, and VobjectBase is only able to find
> the handlers associated with the typeid of the subclass, not the base
> class.
> 
> Any ideas on how we can fix this in VOS?
> 
> Reed
> 
> 
> 
> ___
> vos-d mailing list
> vos-d@interreality.org
> http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d

-- 
[   Peter Amstutz  ][ [EMAIL PROTECTED] ][ [EMAIL PROTECTED] ]
[Lead Programmer][Interreality Project][Virtual Reality for the Internet]
[ VOS: Next Generation Internet Communication][ http://interreality.org ]
[ http://interreality.org/~tetron ][ pgpkey:  pgpkeys.mit.edu  18C21DF7 ]



signature.asc
Description: Digital signature
___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d


[vos-d] Message handler problem

2007-03-15 Thread Reed Hedges


Ran into a slightly confusing thing that VOS does:

If a base class registers a message handler, but then a subclass of that
base class is the metaobject that's actually instantiated, then no
messages can be delivered to that handler-- it seems that the list of
handlers is keyed on typeid names, and VobjectBase is only able to find
the handlers associated with the typeid of the subclass, not the base
class.

Any ideas on how we can fix this in VOS?

Reed



___
vos-d mailing list
vos-d@interreality.org
http://www.interreality.org/cgi-bin/mailman/listinfo/vos-d