Boost logo

Boost :

From: Stefan Roiser (stefan.roiser_at_[hidden])
Date: 2006-02-03 06:54:47


On 2 Feb 2006, at 01:51, Edward Diener wrote:

> David Abrahams wrote:
>> Edward Diener <eddielee_at_[hidden]> writes:
>>
>>> David Abrahams wrote:
>>>> Stefan Roiser <stefan.roiser_at_[hidden]> writes:
>>>>
>>>>> On 31 Jan 2006, at 19:40, David Abrahams wrote:
>>>>>
>>>>>> Stefan Roiser <stefan.roiser_at_[hidden]> writes:
>>>>>>
>>>>>>> On 30 Jan 2006, at 17:08, Stefan Seefeld wrote:
>>>>>>>
>>>>>>> With interaction with objects I meant e.g. through the meta-
>>>>>>> level
>>>>>>> instantiate a class, get/set the data member values, call a
>>>>>>> function
>>>>>>> on that instance, retrieve the function's return value and so
>>>>>>> on. I
>>>>>>> may have missed that, but I couldn't find examples on the
>>>>>>> synopsis
>>>>>>> page for this functionality.
>>>>>>>
>>>>>>> Reflex code for this would look something like
>>>>>>>
>>>>>>> Type t = Type::ByName("foo");
>>>>>>> Object instance = t.Construct();
>>>>>>> Object ret_obj = instance.Invoke("myFunction");
>>>>>> Very interesting. Where do you get the object code for
>>>>>> foo::myFunction? Or have you implemented a full C++ interpreter?
>>>>> foo::myFunction will be invoked through a stub function which
>>>>> is part
>>>>> of the dictionary library for class foo. A dictionary library
>>>>> may be
>>>>> dynamically loaded in a program.
>>>> Soooo.... what about templates? Do you have to do something to
>>>> manually instantiate them? Or do you do some kind of on-the-fly
>>>> compilation?
>>> Since templates are not types, I would leave out the
>>> instantiation of
>>> templates into types, which is a compile-time mechanism, from a
>>> run-time
>>> reflection system
>>
>> That presumes that the only thing worth reflecting about are
>> types. I
>> of course want reflection into templates (and not just class
>> templates, either). But -- no offense intended of course --
>
> No offense taken.
>
>> unless
>> you're part of this effort, I'm not really asking what you would do.
>> I want to know what the Cern people are doing and are planning to do.
>
> The Cern people will have to speak for themselves.

Reflex does provide reflection information for template instances
(classes, functions) and template families. An instantiated template
class is a Reflex::Type, an instantiated template function is a
Reflex::Member. There are two additional classes in the API
(TypeTemplate, MemberTemplate) which will allow the user to
introspect/interact with a template family (e.g. std::vector<T>), but
this information only get's filled once the first template instance
in the dictionary source code comes along.

The TypeTemplate/MemberTemplate currently allow to loop over template
parameters, look at parameter defaults (if any, this also needs some
extra handling - gxxml won't give us this info) and loop over the
instances of this template currently available in the system.

With Reflex our scope was, as also pointed out by Edward, mainly the
runtime reflection part. We are using Reflex at the moment for
persistence of objects and interactive usage of objects (with
language bindings - eg. Python). If I understood correctly your
point, I think the two "xxxTemplate" classes are going in the
direction of template introspection you intend to do, but you
probably want to have more information. But how to retrieve this
additional information?

Related to this topic is the generation of dictionary information for
a template instance. When generating dictionary information we
normally select which information we want to generate (we don't want
to generate the dictionary for vector<int> n times). So in general we
generate it once and provide these "common" dictionary libraries to
our users. In order to do that we have devloped a selection mechanism
which is passed as an xml description to the dictionary generation
step. To generate the dictionary for an vector of int and double
would be generated like.

MyVector.h
==========
#include <vector>
namespace {
   struct _Dict {
     std::vector<int> m1;
     std::vector<double> m2;
   };
}

This syntax is currently needed because we use a quite old version of
gccxml. In the future only the declaration of the template type will
be needed to trigger gccxml to output the information for a template
type.

selection.xml
=============
<lcgdict>
   <class pattern="std::vector<*>"/>
</lcgdict>

(yes, "<" and ">" are allowed in the xml descriptions as text for
convenience)

the syntax for the xml selections is more powerful than this simple
example. You may have a look at http://seal-reflex.web.cern.ch/seal-
reflex/gendict.html#selection_syntax for details.

python genreflex.py MyVector.h -s selection.xml --gccxmplath=/my/path/
to/gccxml/bin

The so into a library compiled dictionary from MyVector_rflx.cpp will
when loaded into Reflex produce a TypeTemplate "std::vector" which
contains a list of instances for the vector<int> and the vector<double>

-- 
Stefan Roiser
CERN, PH Department
CH - 1211 Geneva 23
Mob:+41 76 487 5334
Tel:+41 22 767 4838
Fax:+41 22 767 9425

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk