www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - RTTI concepts

reply James Dunne <jdunne4 bradley.edu> writes:
Maybe this has already been answered before, in some form or another...

I'm working on a very simple and basic MMORPG server/client pair software for an
independent study course.  I chose to implement it in D, of course :).  The
project has been a breeze so far!  I love the socketstream class and the thread
class.  So easy to use...

Anyways, I've hit a stumbling block on the network protocol.  I'd like to be
able to dynamically create instances of classes which are identified by a unique
ID (a uint value).  Basically the ClassFactory concept.  I know it can be done
in C++ without any RTTI and some static initialization magic, but I'd like mine
to be a bit more elegant than that.

I know ClassInfo and TypeInfo exist, but I'm not sure on how to use them
effectively to achieve this goal.  In fact, I'm not sure how to use them at all!
The extent of my use for them so far has been to retrieve
someobject.classinfo.name.

Anyone care to do some explaining here?

Regards,
James Dunne
Jan 29 2005
parent Kris <Kris_member pathlink.com> writes:
Mango does something very similar, in terms of freezing and thawing classes.
Take a look at PickleRegistry, PickleReader and PickleWriter within the Mango.io
package.

There's a fairly extensive 'example' of how one can use these classes within the
Mango.cluster package, which disperses D classes around the network. Now that D
supports Dlls, Mango.cluster will fully enable the distribution and execution of
mobile code.

Hopefully you'll find something of value there. Heck, you might even start using
Mango! Server/client applications is what that library is all about.

http://svn.dsource.org/svn/projects/mango/trunk/doc/html/index.html

http://www.dsource.org/forums/viewtopic.php?t=148

- Kris


In article <ctfmqv$2340$1 digitaldaemon.com>, James Dunne says...
Maybe this has already been answered before, in some form or another...

I'm working on a very simple and basic MMORPG server/client pair software for an
independent study course.  I chose to implement it in D, of course :).  The
project has been a breeze so far!  I love the socketstream class and the thread
class.  So easy to use...

Anyways, I've hit a stumbling block on the network protocol.  I'd like to be
able to dynamically create instances of classes which are identified by a unique
ID (a uint value).  Basically the ClassFactory concept.  I know it can be done
in C++ without any RTTI and some static initialization magic, but I'd like mine
to be a bit more elegant than that.

I know ClassInfo and TypeInfo exist, but I'm not sure on how to use them
effectively to achieve this goal.  In fact, I'm not sure how to use them at all!
The extent of my use for them so far has been to retrieve
someobject.classinfo.name.

Anyone care to do some explaining here?

Regards,
James Dunne

Jan 29 2005