Topic: C++0x: Reflections
Author: odie@hal9000.vc-graz.ac.at (Christoph Rabel)
Date: Mon, 16 Sep 2002 00:41:09 +0000 (UTC) Raw View
Hi!
I think support for Reflections (as in Java) would be a very
useful feature.
What do you think?
Christoph
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nagle@animats.com (John Nagle)
Date: Mon, 16 Sep 2002 04:00:47 +0000 (UTC) Raw View
Christoph Rabel wrote:
> I think support for Reflections (as in Java) would be a very useful
> feature.
>
> What do you think?
It needs to be designed. Who's been down this road?
Mechanisms for remote procedure and object calling (CORBA,
Sun's RPC, Microsoft's DCOM, Java RPC), when interfaced to
C and C++, have generally required either some clunky
mechanism external to the language (like an IDL or a C
code generator) or extensive manual coding for each
remotely callable object. This is not good.
Java, C#, and VB have better-integrated support
for such things, and it gets used. C++ is weak
in this area. The problem needs to be addressed.
John Nagle
Animats
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jules@REMOVETHIS.op59.net (Julian Smith)
Date: Mon, 16 Sep 2002 12:05:03 +0000 (UTC) Raw View
On Mon, 16 Sep 2002 04:00:47 +0000 (UTC)
nagle@animats.com (John Nagle) wrote:
> Christoph Rabel wrote:
>
> > I think support for Reflections (as in Java) would be a very useful
> > feature.
> >
> > What do you think?
>
>
> It needs to be designed. Who's been down this road?
>
> Mechanisms for remote procedure and object calling (CORBA,
> Sun's RPC, Microsoft's DCOM, Java RPC), when interfaced to
> C and C++, have generally required either some clunky
> mechanism external to the language (like an IDL or a C
> code generator) or extensive manual coding for each
> remotely callable object. This is not good.
I'm experimenting with a serialisation system using my Cmm as a
source-level translator. I couldn't think of a really generic language
extention that would allow simple generation of serialisation functions,
so I'm using the following non-generic syntax:
@cmm_memberrecursivefn <function prototype>
This requires that the first parameter in the function is a simple
reference to a class, and is translated into a complete function. The
function body consists of a series of calls to the same named function,
passing each of the class's member variables in turn. In addition, the
class's base classes (if any) are also treated in the same way.
So:
struct Base { int x; };
struct Derived : Base { std::string foo; };
@cmm_memberrecursivefn void Serialise( const Base& b, XDR& xdr);
@cmm_memberrecursivefn void Serialise( const Derived& d, XDR& xdr);
- is translated into:
struct Base { int x; };
struct Derived : Base { std::string foo; };
void Serialise( const Base& b, XDR& xdr)
{
Serialise( b.x;);
}
void Serialise( const Derived& d, XDR& xdr)
{
Serialise( static_cast< Base&>( d), xdr);
Serialise( d.foo, xdr);
}
Providing suitable overloads for Serialise() are written that take basic
types such as int, std::string etc, this results in full serialisation
code being generated. Unserialisation code can be generated in the same
way, although it wouldn't generate constructors; instead it would
overwrite the members of existing structures.
I'm also extending the system to automatically generate memberrecursive
functions for all classes derived from a particular base class. So
@cmm_memberrecursivefn void Serialise( virtual const Base& b, XDR& xdr)
would force generation of Serialise() functions for all classes derived
from Base. In combination with Cmm's multimethods, this can provide for
automatic serialisation of dynamic types at runtime.
I anyone can come up with a nice syntax for representing/dealing with
structure members, I'd be interested. I guess my overloading trick is
fairly complete, but maybe a foreach-style member iterator would be nice
too, if some way could be found of representing any type.
- Julian
--
http://www.op59.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]