Logo ROOT  
Reference Guide
TCollectionProxyFactory.cxx
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Markus Frank 28/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TError.h"
13 #include "TClassEdit.h"
15 #include "TGenCollectionProxy.h"
16 #include "TGenCollectionStreamer.h"
17 
18 #include "TEmulatedMapProxy.h"
20 
21 // Do not clutter global namespace with shit....
22 namespace {
23  static ROOT::ESTLType stl_type(const std::string& class_name) {
24  // return the STL type.
25  int nested = 0;
26  std::vector<std::string> inside;
27  int num = TClassEdit::GetSplit(class_name.c_str(),inside,nested);
28  if ( num > 1 ) {
29  return (ROOT::ESTLType)TClassEdit::STLKind(inside[0]);
30  }
31  return ROOT::kNotSTL;
32  }
33 
34  static TEmulatedCollectionProxy* GenEmulation(const char* class_name, Bool_t silent) {
35  // Generate an emulated collection proxy.
36 
37  if ( class_name ) {
38  std::string cl = class_name;
39  if ( cl.find("stdext::hash_") != std::string::npos )
40  cl.replace(3,10,"::");
41  if ( cl.find("__gnu_cxx::hash_") != std::string::npos )
42  cl.replace(0,16,"std::");
43  TEmulatedCollectionProxy * result = 0;
44  switch ( stl_type(cl) ) {
45  case ROOT::kNotSTL:
46  return 0;
47  case ROOT::kSTLmap:
48  case ROOT::kSTLmultimap:
49  result = new TEmulatedMapProxy(class_name,silent);
50  break;
51  default:
52  result = new TEmulatedCollectionProxy(class_name,silent);
53  }
54  if ( result->IsValid() ) {
55  return result;
56  }
57  }
58  return 0;
59  }
60 }
61 
63 TCollectionProxyFactory::GenEmulatedProxy(const char* class_name, Bool_t silent)
64 {
65  // Generate emulated collection proxy for a given class.
66 
67  return GenEmulation(class_name, silent);
68 }
69 
72 {
73  // Generate emulated class streamer for a given collection class.
74 
76  s->AdoptStreamer(GenEmulation(class_name, silent));
77  return s;
78 }
79 
82 {
83  // Generate emulated member streamer for a given collection class.
85  s->AdoptStreamer(GenEmulation(class_name, silent));
86  return s;
87 }
88 
90 TCollectionProxyFactory::GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
91 {
92  // Generate proxy from static functions.
93  return new TGenCollectionProxy(info,cl);
94 }
95 
97 TCollectionProxyFactory::GenExplicitStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
98 {
99  // Generate streamer from static functions.
101  return ptr;
102 }
103 
105 TCollectionProxyFactory::GenExplicitClassStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
106 {
107  // Generate class streamer from static functions.
109  s->AdoptStreamer(GenExplicitStreamer(info,cl));
110  return s;
111 }
112 
114 TCollectionProxyFactory::GenExplicitMemberStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
115 {
116  // Generate member streamer from static functions.
118  s->AdoptStreamer(GenExplicitStreamer(info,cl));
119  return s;
120 }
121 
123  // Issue Error about invalid proxy.
124  Fatal("TCollectionStreamer>","No proxy available. Data streaming impossible.");
125 }
126 
128 {
129  // Initializing constructor.
130 }
131 
133 {
134  // Copy constructor.
135  if ( c.fStreamer ) {
136  fStreamer = dynamic_cast<TGenCollectionProxy*>(c.fStreamer->Generate());
137  R__ASSERT(fStreamer != 0);
138  return;
139  }
141 }
142 
144 {
145  // Standard destructor.
146  if ( fStreamer ) {
147  delete fStreamer;
148  }
149 }
150 
152 {
153  // Attach worker proxy.
154  if ( fStreamer ) {
155  delete fStreamer;
156  }
157  fStreamer = streamer;
158 }
159 
160 void TCollectionStreamer::Streamer(TBuffer &buff, void *pObj, int /* siz */, TClass* onFileClass )
161 {
162  // Streamer for I/O handling.
163  if ( fStreamer ) {
165  fStreamer->SetOnFileClass( onFileClass );
166  fStreamer->Streamer(buff);
167 
168  return;
169  }
171 }
c
#define c(i)
Definition: RSha256.hxx:119
TCollectionStreamer::InvalidProxyError
void InvalidProxyError()
Issue Error about invalid proxy.
Definition: TCollectionProxyFactory.cxx:122
TCollectionStreamer::AdoptStreamer
void AdoptStreamer(TGenCollectionProxy *streamer)
Attach worker proxy.
Definition: TCollectionProxyFactory.cxx:151
TEmulatedMapProxy
Definition: TEmulatedMapProxy.h:16
TCollectionProxyFactory::GenEmulatedClassStreamer
static TClassStreamer * GenEmulatedClassStreamer(const char *class_name, Bool_t silent)
Generate emulated class streamer for a given collection class.
Definition: TCollectionProxyFactory.cxx:71
TEmulatedCollectionProxy.h
ROOT::kNotSTL
@ kNotSTL
Definition: ESTLType.h:41
TCollectionStreamer
Definition: TCollectionProxyFactory.h:125
TCollectionMemberStreamer
Definition: TCollectionProxyFactory.h:205
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TCollectionProxyFactory::GenExplicitProxy
static Proxy_t * GenExplicitProxy(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate proxy from static functions.
Definition: TCollectionProxyFactory.cxx:90
TBuffer
Definition: TBuffer.h:43
TGenCollectionProxy.h
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TCollectionProxyFactory::GenExplicitStreamer
static TGenCollectionStreamer * GenExplicitStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate streamer from static functions.
Definition: TCollectionProxyFactory.cxx:97
bool
TGenCollectionProxy::SetOnFileClass
virtual void SetOnFileClass(TClass *cl)
Definition: TGenCollectionProxy.h:427
ROOT::kSTLmap
@ kSTLmap
Definition: ESTLType.h:45
TGenCollectionStreamer.h
ROOT::ESTLType
ESTLType
Definition: ESTLType.h:34
TEmulatedMapProxy.h
TCollectionProxyFactory::GenEmulatedProxy
static TVirtualCollectionProxy * GenEmulatedProxy(const char *class_name, Bool_t silent)
Generate emulated collection proxy for a given class.
Definition: TCollectionProxyFactory.cxx:63
TEmulatedCollectionProxy
Definition: TEmulatedCollectionProxy.h:18
Fatal
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition: TError.cxx:246
TCollectionProxyFactory.h
TCollectionStreamer::Streamer
void Streamer(TBuffer &refBuffer, void *obj, int siz, TClass *onFileClass)
Streamer for I/O handling.
Definition: TCollectionProxyFactory.cxx:160
ROOT::kSTLmultimap
@ kSTLmultimap
Definition: ESTLType.h:46
TCollectionStreamer::TCollectionStreamer
TCollectionStreamer()
Initializing constructor.
Definition: TCollectionProxyFactory.cxx:127
TCollectionProxyFactory::GenExplicitMemberStreamer
static TMemberStreamer * GenExplicitMemberStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate member streamer from static functions.
Definition: TCollectionProxyFactory.cxx:114
TClassEdit::GetSplit
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the split type.
Definition: TClassEdit.cxx:981
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
TClassEdit.h
TClass
Definition: TClass.h:80
TVirtualCollectionProxy::TPushPop
Definition: TVirtualCollectionProxy.h:59
TCollectionClassStreamer
Definition: TCollectionProxyFactory.h:157
TGenCollectionProxy
Definition: TGenCollectionProxy.h:29
TEmulatedCollectionProxy::IsValid
Bool_t IsValid() const
Definition: TEmulatedCollectionProxy.cxx:208
TClassStreamer
Definition: TClassStreamer.h:26
TCollectionStreamer::fStreamer
TGenCollectionProxy * fStreamer
Pointer to worker streamer.
Definition: TCollectionProxyFactory.h:130
TGenCollectionProxy::Streamer
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
Definition: TGenCollectionProxy.cxx:1380
TGenCollectionStreamer
Definition: TGenCollectionStreamer.h:17
TClassEdit::STLKind
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:511
TCollectionProxyFactory::GenEmulatedMemberStreamer
static TMemberStreamer * GenEmulatedMemberStreamer(const char *class_name, Bool_t silent)
Generate emulated member streamer for a given collection class.
Definition: TCollectionProxyFactory.cxx:81
TMemberStreamer
Definition: TMemberStreamer.h:26
TCollectionProxyFactory::GenExplicitClassStreamer
static TClassStreamer * GenExplicitClassStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate class streamer from static functions.
Definition: TCollectionProxyFactory.cxx:105
TCollectionStreamer::~TCollectionStreamer
virtual ~TCollectionStreamer()
Standard destructor.
Definition: TCollectionProxyFactory.cxx:143
TVirtualCollectionProxy
Definition: TVirtualCollectionProxy.h:38
TError.h