Re: [ROOT] Sending mixed templated/non-templated objects through ROOT I/O

From: George A. Heintzelman (gah@bnl.gov)
Date: Fri Oct 13 2000 - 20:56:42 MEST


Brett,

Be aware that CINT does not really support template members, so much of 
your template machinery will have to be hidden from CINT in order for 
it to work at the command line. (Either that or you'll have to talk to 
Masaharu Goto personally to figure out how to implement what you need. 
;)

Basically, you need to figure out what interface you want to use to the 
ROOT streamers for the registry items. Personally, I would probably do 
it something like this:

In Registry::Streamer, loop over the map writing out the key (either as 
a root TString or with your own TBuffer & operator<<(const std::string 
&) ), the value type (from a virtual RegistryItem function call). and 
the value. The value you write out with a virtual function call in 
RegistryItem, which you will have to specialize for types which are not 
ROOT TObjects.

The tricky part will be deciding how to tell the write out what 
absolute type it is. Unfortunately, you can't portably use the 
type_info::name() function since it is implementation-defined, which is 
precisely why the ROOT guys use their ClassName() and such the way they 
do. If you want to write out ROOT objects, you're set -- just use the 
class's ClassName function. For other classes, you probably ought to 
write a specialization of RegistryItemXxx<T>::Name. For read in, you 
supply a registry of RegistryItemXxx<T>::Name which can look up a 
static function returning a T* for the relevant classname string.

You DO realize you're basically redoing ROOT-io in the way it would 
probably have been done had the ROOT guys been able to portably use 
template machinery when they first wrote it, right?

George Heintzelman
gah@bnl.gov


> // The container
> class Registry
> {
> public:
>         // non-templated ctor/dtor
> 
>         // templated accessors
>         template<class T>    T GetVal(string key);
>         template<class T> void SetVal(string key, T value);

This of course should be SetVal(string key, const T & value), right? 
You don't want to make more copies than you must (and you must make one 
when you create your RegistryItemXXX).

> private:
>         map<string, RegistryItem*> fMap;
> };

> 
> // The generic class which the container holds
> class RegistryItem
> {
> public:
>         // non-templated ctor/dtor
>         // that's it
> };
> 
> // The templated class holding a specific typed value
> template<class T>
> class RegistryItemXxx : public RegistryItem
> {
> public:
>         // templated ctor/dtor
> 
>         // templated accessors
>           T* Get(void);
>         void Set(T* data);
> private:
>         T* fData;
> };



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:35 MET