[ROOT] RE: Template question ...

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Sep 27 2001 - 23:40:50 MEST


Hi Marc,

For the time being (i.e. until we finally get around to implement a 
better solution), there is a family of ClassDefT macros (see 
$ROOTSYS/include/Rtypes.h for the gory details):

ClassDefT(ClassName,ClassId)  :  Used as the end of the class definition
	in the case of template class, ClassName is of a form similar to 
	TemplateName<T> 

ClassDefT2(ClassName, TemplateParam) 
ClassDef2T2(ClassName, TemplateParam1, TemplateParam2 )
ClassDef3T2(ClassName, TemplateParam1, TemplateParam2, TemplateParam3 )
	Used in the header file of the class template definition.
	with the parameter

ClassImpT(ClassName, TemplateParam)
ClassImp2T(ClassName, TemplateParam1, TemplateParam2 )
ClassImp3T(ClassName, TemplateParam1, TemplateParam2, TemplateParam3 )
	Implement the required static data member and ImplFileName type
	of methods.  Should be in a .cxx file.

So In your case:

//---- GuardedMap.hh
// K denotes the key, O denotes the Object
template <typename K, typename O>
class TGuardedMap
{
  // private typedefs
  typedef map<K, O> KO_Map;
  typedef map<K, O>::iterator KO_iter;

  //on UNIX it occurs a Deadlock with normal Mutex!!!
  TThreadMutex      m_Mutex; // the Mutex to protect the map
...
public:

   ClassDef(TGuardedMap<K,O>,1)
};
ClassDef2T2(TGuardedMap,K,O)

//---- ImpGuardedMap.cxx
#include "GuardedMap.hh"
#include "MyKeyAndObject.hh"

ClassImp2T(TGuardedMap,K,O)

TGuardedMap<MyKey,MyObject> dummy;

Cheers,
Philippe.


-----Original Message-----
From: hemberg@[62.52.27.101] [mailto:hemberg@[62.52.27.101]]On Behalf Of
Marc Hemberger
Sent: Thursday, September 27, 2001 2:37 PM
To: Philippe Canal
Cc: roottalk@pcroot.cern.ch
Subject: Template question ...


Hi Philippe,

just another template question:

I have a templated class, which wraps a map<Key, Object> in a thread
safe way. This works fine in C++. How can I give this TGuardedMap now
over to CINT with the ClassDefT etc. macros? They all allow only one
template argument. How can that be done:

// K denotes the key, O denotes the Object
template <typename K, typename O>
class TGuardedMap
{
  // private typedefs
  typedef map<K, O> KO_Map;
  typedef map<K, O>::iterator KO_iter;

  //on UNIX it occurs a Deadlock with normal Mutex!!!
  TThreadMutex      m_Mutex; // the Mutex to protect the map
...
};

This works in compiled code, but I want to have this template also
available with all what the ClassDef's give to it. I have not found
anything about these templates with more than one argument. Could you
guide me to the source of HOWTO ?;-)

Greetings,

Marc


--

Dr. Marc Hemberger
                /\_/\
               ( o.o )
                > ^ <
       |\      _,,,---,,         realTech                privat:
ZZZzz  /,`.-'`'    -.  ;-;;,_    system consulting GmbH
      |,4-  ) )-,_. ,\ (  `'-'   Industriestr. 39c       Marstallstr. 49d
     '---''(_/--'  `-'\_)        69190 Walldorf          68723 Schwetzingen

     Marc.Hemberger@realtech.de                          MHemberger@csi.com

** Disclaimer: My views/comments/beliefs, as strange as they are, are my own.**



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:00 MET