 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Mon Apr 30, 2007 9:10 am Post subject: Announcing Xrtti - Extended Runtime Type Information for C++ |
|
|
Xrtti is a tool and accompanying C++ library which extends the
standard runtime type system of C++ to provide a much richer set of
reflection information about classes and methods to manipulate these
classes and their members.
It is intended to provide a much more complete set of reflection
capabilities to C++ than the standard C++ rtti feature.
I have released the first public version of this tool, version 0.1,
under the GNU GPLv2, and would welcome feedback on it.
Xrtti is at:
http://www.ischo.com/xrtti
Thank you, and best wishes,
Bryan
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Mathias Gaunard Guest
|
Posted: Tue May 01, 2007 5:50 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On Apr 30, 11:16 am, bji-gg...@ischo.com wrote:
| Quote: | Xrtti is a tool and accompanying C++ library which extends the
standard runtime type system of C++ to provide a much richer set of
reflection information about classes and methods to manipulate these
classes and their members.
|
Wouldn't compile-time reflection be more than enough?
Is there really a need for that kind of reflection at runtime?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Richard Smith Guest
|
Posted: Tue May 01, 2007 9:10 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
Mathias Gaunard wrote:
| Quote: | On Apr 30, 11:16 am, bji-gg...@ischo.com wrote:
Xrtti is a tool and accompanying C++ library which extends the
standard runtime type system of C++ to provide a much richer set of
reflection information about classes and methods to manipulate these
classes and their members.
Wouldn't compile-time reflection be more than enough?
Is there really a need for that kind of reflection at runtime?
|
The same can be said of typeid / std::type_info. Much of the time the
type system provides this information at compile time, and we don't need
std::type_info. But occasionally it can be useful to access this
information at runtime.
I haven't used this library, but I imagine the same applies here.
Compile-time reflection might well be nicer, but it is also harder to
provide. But even if compile-time reflection were available, I'm sure
there would be cases when accessing this information at runtime would be
useful, just as std::type_info has its place.
And as this is a library, if you don't want it, don't use it.
--
Richard Smith
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Andrew Marlow Guest
|
Posted: Tue May 01, 2007 9:10 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On Mon, 30 Apr 2007 03:16:17 -0600, bji-ggcpp wrote:
| Quote: | Xrtti is a tool and accompanying C++ library which extends the
standard runtime type system of C++ to provide a much richer set of
reflection information about classes and methods to manipulate these
classes and their members.
It is intended to provide a much more complete set of reflection
capabilities to C++ than the standard C++ rtti feature.
I have released the first public version of this tool, version 0.1,
under the GNU GPLv2, and would welcome feedback on it.
|
What is the ETA for some examples please?
-Andrew Marlow
--
There is an emerald here the size of a plover's egg!
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Tue May 01, 2007 9:10 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 1, 5:50 pm, Mathias Gaunard <loufo...@gmail.com> wrote:
| Quote: | Wouldn't compile-time reflection be more than enough?
Is there really a need for that kind of reflection at runtime?
|
I am sure that some creative people can think of useful things to do
with this kind of enhanced runtime reflection. I have thought of a
few:
- Write a tool that allows one to "script" C++; if you linked this
tool into your program, it would use the reflection information
presented by Xrtti to let you via a command line interface, create
objects, call methods on them, change values, etc. Not sure exactly
what kind of program could take full advantage of this kind of
capability but it is interesting.
- Some kind of automated testing support? If you can call any method
on any class via reflection, you could write a library that supported
some kind of automated testing by walking the tree of classes in your
program and instantiating objects, calling methods on them, etc.
- You can serialize and deserialize instances of any class you define,
via a single library that uses the extended runtime type information
to walk over the data members of your classes.
In fact, the last one is the reason that I wrote Xrtti; I had written
a tool that adds serialization support to all of your classes "for
free", without any changes necessary to your class definitions (unlike
other C++ serialization systems that I have seen, such as
Boost::Serialization and s11n, which just provide frameworks to assist
you in serializing your objects, but you still have to write the
serialization code).
I then realized that this could be done more cleanly in two parts: 1)
a tool that generates extended runtime type information, and 2) a
serializer library that operates on this information. I assumed that
since I found something useful to do with (1), others may think of
other interesting things to do with it as well.
Thanks,
Bryan
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Mathias Gaunard Guest
|
Posted: Tue May 01, 2007 10:52 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 1, 7:20 pm, ali <albrecht.fritzs...@gmx.net> wrote:
| Quote: | Hm, now I am curious - how can you, say, create a function which calls
on
every class (of your program) all functions starting with "test_" via /
compile time
reflection/? Including calling it with the correct parameters?
|
Code that executes at compile-time, template metaprogramming, is quite
tricky to write.
To be honest, I don't even have enough knowledge about the MPL to know
how to know whether a mpl::vector_c starts with test_.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Tue May 01, 2007 10:57 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 2, 5:20 am, ali <albrecht.fritzs...@gmx.net> wrote:
| Quote: | Hm, now I am curious - how can you, say, create a function which calls
on
every class (of your program) all functions starting with "test_" via /
compile time
reflection/? Including calling it with the correct parameters?
|
Using the Xrtti API, you could do this:
using namespace Xrtti;
void CallAllTest_Methods()
{
// Look at each context, picking out the classes ...
U32 contextCount = GetContextCount();
for (U32 i = 0; i < contextCount; i++) {
const Context &context = GetContext(i);
// Skip it if it's not a class
if (context.GetType() != Context::Type_Class) {
continue;
}
// OK, we have a class. Look at each method to find methods
whose
// names begin with test_
const Class &classRef = (const Class &) context;
void *pInstance = NULL;
U32 methodCount = classRef.GetMethodCount();
for (U32 i = 0; i < methodCount; i++) {
const Method &method = classRef.GetMethod(i);
// Does the method's name begin with "test_"? If so, it's
// one we may want to call
if (strncmp(method.GetName(), "test_", 5)) {
// Doesn't begin with test_, skip it
continue;
}
// Now we would have to have some logic here to detect the
// argument types of this test_ method, and come up with
suitable
// arguments. This would be policy that you would have to
define
// for your own test_ methods; this would be by far the
hardest
// part of coming up with a general test framework, and
I'm sorry
// but I can't solve this problem in this short example.
Suffice
// it to say, the Xrtti API would let you look at the
argument
// number and types, and return type, of this method, to
allow
// this kind of automated argument building
// For this example, to gloss over the above problem,
we'll just
// skip anything that returns non-void or has arguments.
if ((method.GetSignature().GetReturnType().GetBaseType() !
=
Type::BaseType_Void) ||
(method.GetSignature().GetArgumentCount() != 0)) {
// It either has a return type, or takes arguments.
Skip it.
continue;
}
// Now that we have a method to call, we'll need an
instance to
// call it on
if (pInstance == NULL) {
// Note that this call will result in the actual
default
// constructor of the given class being called, and
the
// resulting constructed object being returned as a
void *
void *pInstance = classRef.Create();
// This can actually return NULL if the class is not
// constructable, i.e. is an abstract class, so skip
it
if (pInstance == NULL) {
continue;
}
}
// OK, this is a method with signature void test_xxx();
Invoke it.
// We always have to supply a place to put the return
value, even
// though this method returns no value.
Value returnValue;
method.Invoke(pInstance, returnValue, NULL);
}
// Now delete the constructed instance, if there was one
if (pInstance != NULL) {
classRef.Delete(pInstance);
}
}
}
I haven't tested this code, I just wrote it out quickly, and there are
probably bugs and typos. But it illustrates the general technique you
would use to do this. The hardest part by far is having an algorithm
to "make up" test method arguments. I would expect that this would be
something you'd have to supply some kind of configuration file for.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Tue May 01, 2007 10:57 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 1, 9:49 pm, "Andrew Marlow" <use...@marlowa.plus.com> wrote:
| Quote: | What is the ETA for some examples please?
|
Thank you for your interest! I hadn't written any examples yet
because I was just trying to get the thing out the door. There are
some "examples" in the software itself, consisting of the test
programs I wrote to test Xrtti functionality. They show actual usage
of the API, but they are not the clearest or most concise way to
demonstrate Xrtti functionality.
I have just posted a short example in response to another question in
this list, showing how to call all test_ methods that your classes
define. But even that is just a code fragment.
I will work on getting some good examples put together, and will try
to have them up on my site in a day or two. I will post to a response
to this message when I have done so.
Thanks again, and best wishes,
Bryan
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 02, 2007 12:36 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 2, 2:35 am, Mathias Gaunard <loufo...@gmail.com> wrote:
| Quote: | On May 1, 11:50 am, bji-gg...@ischo.com wrote:
- Write a tool that allows one to "script" C++; if you linked this
tool into your program, it would use the reflection information
presented by Xrtti to let you via a command line interface, create
objects, call methods on them, change values, etc. Not sure exactly
what kind of program could take full advantage of this kind of
capability but it is interesting.
You simply cannot create new types at runtime, so I don't see why you
couldn't do this with compile-time reflection.
|
Well with Xrtti, you could write a library method once which could
perform this task on any class that any program defines. You wouldn't
have to custom-write code to know specifically about your classes.
| Quote: | - Some kind of automated testing support? If you can call any method
on any class via reflection, you could write a library that supported
some kind of automated testing by walking the tree of classes in your
program and instantiating objects, calling methods on them, etc.
Same, I don't see why you couldn't do it with compile-time reflection,
especially in that case where walking the tree of classes and where
therefore the types of the objects manipulated are known.
|
Like I said, if you are writing a library method to do this, the types
of objects manipulated will *not* be known. You can write a generic
algorithm for walking any class definitions and creating instances of
these classes and calling methods on them. You could write this
method one time, put it into a library, and now anyone can link that
library into that code and use it on their classes. If you relied
solely on implicit knowledge of the classes you are working with (as
you would have to if you didn't have this kind of runtime reflection),
then you would have to modify and recompile your test library each
time to let it know about new classes or remove classes that you no
longer define. It turns the problem from hand-crafted code written
for each program, to a library method that can work for any program.
Of course, the hardest part would be coming up with a way to construct
meaningful argument lists to methods that you have no implicit
knowledge of. This would certainly require some kind of extra
configuration information that your library would depend on, meaning
that the process couldn't be 100% entirely automated, but at least
with runtime reflection you could do a large chunk of it in a library
method instead of as a one-off in each program you write.
| Quote: |
- You can serialize and deserialize instances of any class you define,
via a single library that uses the extended runtime type information
to walk over the data members of your classes.
That's only useful if you want to serialize objects which you don't
know the real type of.
But indeed, that might be required.
|
But if you write your serialization code as a library method, then it
doesn't know the real type of *any* object. With extended runtime
reflection, you can write serialization methods, put them in a
library, and make that library available to any application to link
against, and get the full serialization functionality for any classes
defined in that application, *without having to write any custom
serialization code in the application whatsoever*.
This is the essential point of extended runtime type information - you
can write generic algorithms that could apply to any class whatsoever,
and release them as libraries that can be linked against any program
to provide that functionality to all classes of that program without
the program having to do any special set up (aside from generate
extended runtime type info via my Xrtti tool!) to get that
functionality.
After I flesh out the Xrtti release a little bit (add examples, port
the library and make tool that it depends upon to other architectures
so that it is available for more than just Fedora Linux), my next task
will be to write a generic serialization library using Xrtti that any
program can link against and "magically" get serialization support for
any class defined in the application.
Thanks,
Bryan
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Tom Lynch Guest
|
Posted: Wed May 02, 2007 9:10 am Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 2, 10:36 am, bji-gg...@ischo.com wrote:
| Quote: | But if you write your serialization code as a library method, then it
doesn't know the real type of *any* object. With extended runtime
reflection, you can write serialization methods, put them in a
library, and make that library available to any application to link
against, and get the full serialization functionality for any classes
defined in that application, *without having to write any custom
serialization code in the application whatsoever*.
|
Except for the machine-generated custom serialization code that you
create, right? You don't have to write it, but you do have to
generate, compile and link it as an entity separate to the XRTTI
library.
i.e. I take it XRTTI relies on preprocessing the classes to be
reflected to produce run-time reflection metaclasses, the
preprocessing step being the enabler for things like mapping string
literals to methods, objects and data.
I can't see why it's not possible to generate compile-time reflection
metaclasses using a similar method. Am I missing something?
Tom
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Hyman Rosen Guest
|
Posted: Wed May 02, 2007 6:06 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
Al wrote:
| Quote: | Another way to ask it is, is there anything that runtime reflection can
do, in the limit, that compile-time cannot (again, assuming perfect
compile-time reflection)? If so, what is it?
|
You are clearly not familiar with reflection as practiced in Java
and C#. Systems with true reflection can load up dynamic libraries
at runtime and examine the types and objects found therein. They
can use that information to create objects of those types, and to
call methods on those objects. Design studio applications often
work like this. You dynamically load up control libraries, and the
program figures out what controls are present and what methods they
support. It displays them to the designer, who can then hook them
up and make them talk to each other. Message processing systems use
reflection too, allowing new serialized messages to be processed.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Zeljko Vrba Guest
|
Posted: Wed May 02, 2007 6:57 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On 2007-05-02, Al <two (AT) haik (DOT) us> wrote:
| Quote: |
Another way to ask it is, is there anything that runtime reflection can
do, in the limit, that compile-time cannot (again, assuming perfect
compile-time reflection)? If so, what is it?
|
struct A { ... };
struct A1 : A { ... };
struct A2 : A { ... };
struct P {
A *parent;
};
There. Now imagine A being interface to the scheduler, A1 and A2 concrete
implementations of scheduler nodes (with corresponding instances), and P a
process that the system administrator can switch between scheduler instances
A1 and A2. How can you in compile-time discover the exact type of the
parent of P?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Markus Schoder Guest
|
Posted: Wed May 02, 2007 6:58 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
Al wrote:
| Quote: | Hi,
Tom Lynch wrote:
On May 2, 10:36 am, bji-gg...@ischo.com wrote:
But if you write your serialization code as a library method, then
it
doesn't know the real type of *any* object. With extended runtime
reflection, you can write serialization methods, put them in a
library, and make that library available to any application to link
against, and get the full serialization functionality for any
classes defined in that application, *without having to write any
custom serialization code in the application whatsoever*.
Except for the machine-generated custom serialization code that you
create, right? You don't have to write it, but you do have to
generate, compile and link it as an entity separate to the XRTTI
library.
i.e. I take it XRTTI relies on preprocessing the classes to be
reflected to produce run-time reflection metaclasses, the
preprocessing step being the enabler for things like mapping string
literals to methods, objects and data.
I can't see why it's not possible to generate compile-time reflection
metaclasses using a similar method. Am I missing something?
I'm very curious about this too, from a sort of theoretical point of
view.
*Assuming* C++ had sufficiently powerful compile-time reflection (e.g.
better syntax, better constructs, and so forth), is there any
advantage at all in using runtime reflection?
Another way to ask it is, is there anything that runtime reflection
can do, in the limit, that compile-time cannot (again, assuming
perfect compile-time reflection)? If so, what is it?
(So far, I believe the OP has not provided such a case).
|
Consider the following:
A large application that is dynamically linked against a library. The
application uses dynamic reflection to access objects from the library
e.g. to display attributes, store them in a database and allow setting
of values by the user.
It is now possible to release and deploy a new version of the library
without releasing a new version of the whole application while allowing
for substantial new functionality.
There are of course other ways to achieve this but they usually involve
using an ugly application specific API in the library.
I will certainly have a closer look at this stuff.
--
Markus
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Wed May 02, 2007 7:00 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 1, 6:36 pm, bji-gg...@ischo.com wrote:
| Quote: | On May 2, 2:35 am, Mathias Gaunard <loufo...@gmail.com> wrote:
- You can serialize and deserialize instances of any class you define,
via a single library that uses the extended runtime type information
to walk over the data members of your classes.
That's only useful if you want to serialize objects which you don't
know the real type of.
But indeed, that might be required.
But if you write your serialization code as a library method, then it
doesn't know the real type of *any* object. With extended runtime
reflection, you can write serialization methods, put them in a
library, and make that library available to any application to link
against, and get the full serialization functionality for any classes
defined in that application, *without having to write any custom
serialization code in the application whatsoever*.
This is the essential point of extended runtime type information - you
can write generic algorithms that could apply to any class whatsoever,
and release them as libraries that can be linked against any program
to provide that functionality to all classes of that program without
the program having to do any special set up (aside from generate
extended runtime type info via my Xrtti tool!) to get that
functionality.
|
Your approach requires generating code and compiling that code before
you can generate the marshalling code and build the application.
It would be slower than the already sluggish C++ build process.
In my opinion the functionality should be integrated into the compiler
and that is the hard part.
I agree with you though that the generated code should be available
to people if they want to read it.
--
Brian Wood
Ebenezer Enterprises
www.webEbenezer.net
Unless the Lord builds the system(house), they labor in vain that build
it: unless the Lord keeps the server farm(city), the watchman waketh
but in vain. Psalm 127:1
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
ali Guest
|
Posted: Wed May 02, 2007 10:10 pm Post subject: Re: Announcing Xrtti - Extended Runtime Type Information for |
|
|
On May 2, 12:57 am, bji-gg...@ischo.com wrote:
| Quote: | Using the Xrtti API, you could do this:
using namespace Xrtti;
void CallAllTest_Methods()
{
// Look at each context, picking out the classes ...
U32 contextCount = GetContextCount();
for (U32 i = 0; i < contextCount; i++) {
const Context &context = GetContext(i);
....
if (strncmp(method.GetName(), "test_", 5)) {
// Doesn't begin with test_, skip it
continue;
}
.... |
Thanks for your example. You might add such an example to your web
page, w/o any example it could mean everything. And finally you might
even C++-ish your code With this I mean using iterators to allow
user-friendly accesses, using strings, ...
Ali
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|