ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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].c_str());
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 }
virtual ~TCollectionStreamer()
Standard destructor.
static TMemberStreamer * GenEmulatedMemberStreamer(const char *class_name, Bool_t silent)
Generate emulated member streamer for a given collection class.
ESTLType
Definition: ESTLType.h:28
Class streamer object to implement TClassStreamer functionality for I/O emulation.
virtual TVirtualCollectionProxy * Generate() const
Virtual copy constructor.
Class streamer object to implement TMemberStreamer functionality for I/O emulation.
void Fatal(const char *location, const char *msgfmt,...)
return c
int GetSplit(const char *type, std::vector< std::string > &output, int &nestedLoc, EModType mode=TClassEdit::kNone)
Stores in output (after emptying it) the splited type.
Definition: TClassEdit.cxx:927
void AdoptStreamer(TGenCollectionProxy *streamer)
Attach worker proxy.
static TClassStreamer * GenEmulatedClassStreamer(const char *class_name, Bool_t silent)
Generate emulated class streamer for a given collection class.
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define R__ASSERT(e)
Definition: TError.h:98
bool Bool_t
Definition: RtypesCore.h:59
Streamer around an arbitrary STL like container, which implements basic container functionality...
static Proxy_t * GenExplicitProxy(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate proxy from static functions.
Streamer around a map container.
static TGenCollectionStreamer * GenExplicitStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate streamer from static functions.
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:467
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
static TMemberStreamer * GenExplicitMemberStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate member streamer from static functions.
Class streamer object to implement TClassStreamer functionality for I/O emulation.
TGenCollectionProxy * fStreamer
Pointer to worker streamer.
TCollectionStreamer()
Initializing constructor.
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
static TVirtualCollectionProxy * GenEmulatedProxy(const char *class_name, Bool_t silent)
Generate emulated collection proxy for a given class.
virtual void SetOnFileClass(TClass *cl)
Proxy around an arbitrary container, which implements basic functionality and iteration.
void InvalidProxyError()
Issue Error about invalid proxy.
double result[121]
void Streamer(TBuffer &refBuffer, void *obj, int siz, TClass *onFileClass)
Streamer for I/O handling.
static TClassStreamer * GenExplicitClassStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate class streamer from static functions.