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"
17
18#include "TEmulatedMapProxy.h"
20
21// Do not clutter global namespace with shit....
22namespace {
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:
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
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
90TCollectionProxyFactory::GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
91{
92 // Generate proxy from static functions.
93 return new TGenCollectionProxy(info,cl);
94}
95
97TCollectionProxyFactory::GenExplicitStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
98{
99 // Generate streamer from static functions.
101 return ptr;
102}
103
105TCollectionProxyFactory::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
114TCollectionProxyFactory::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
160void 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}
#define c(i)
Definition: RSha256.hxx:101
bool Bool_t
Definition: RtypesCore.h:61
#define R__ASSERT(e)
Definition: TError.h:96
void Fatal(const char *location, const char *msgfmt,...)
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Class streamer object to implement TClassStreamer functionality for I/O emulation.
Class streamer object to implement TMemberStreamer functionality for I/O emulation.
static TVirtualCollectionProxy * GenEmulatedProxy(const char *class_name, Bool_t silent)
Generate emulated collection proxy for a given class.
static TClassStreamer * GenEmulatedClassStreamer(const char *class_name, Bool_t silent)
Generate emulated class streamer for a given collection class.
static Proxy_t * GenExplicitProxy(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate proxy from static functions.
static TMemberStreamer * GenEmulatedMemberStreamer(const char *class_name, Bool_t silent)
Generate emulated member streamer for a given collection class.
static TClassStreamer * GenExplicitClassStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate class streamer from static functions.
static TMemberStreamer * GenExplicitMemberStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate member streamer from static functions.
static TGenCollectionStreamer * GenExplicitStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
Generate streamer from static functions.
Class streamer object to implement TClassStreamer functionality for I/O emulation.
TGenCollectionProxy * fStreamer
Pointer to worker streamer.
void InvalidProxyError()
Issue Error about invalid proxy.
virtual ~TCollectionStreamer()
Standard destructor.
void AdoptStreamer(TGenCollectionProxy *streamer)
Attach worker proxy.
TCollectionStreamer()
Initializing constructor.
void Streamer(TBuffer &refBuffer, void *obj, int siz, TClass *onFileClass)
Streamer for I/O handling.
Streamer around an arbitrary STL like container, which implements basic container functionality.
Streamer around a map container.
Proxy around an arbitrary container, which implements basic functionality and iteration.
virtual void Streamer(TBuffer &refBuffer)
Streamer Function.
virtual void SetOnFileClass(TClass *cl)
ESTLType
Definition: ESTLType.h:28
@ kSTLmap
Definition: ESTLType.h:33
@ kNotSTL
Definition: ESTLType.h:29
@ kSTLmultimap
Definition: ESTLType.h:34
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
Definition: TClassEdit.cxx:511
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.
static constexpr double s