Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TCollectionProxyFactory.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Markus Frank 28/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 #ifndef ROOT_TCollectionProxyFactory
12 #define ROOT_TCollectionProxyFactory
13 
14 //////////////////////////////////////////////////////////////////////////
15 // //
16 // Small helper to save proxy environment in the event of
17 // recursive calls.
18 //
19 //////////////////////////////////////////////////////////////////////////
20 
21 #include <vector>
22 
23 #include "TCollectionProxyInfo.h"
24 
25 #include "TClassStreamer.h"
26 
27 #include "TMemberStreamer.h"
28 
29 #include "TGenCollectionProxy.h"
30 
31 // Forward declarations
32 class TBuffer;
33 class TGenCollectionProxy;
34 class TGenCollectionStreamer;
35 class TVirtualCollectionProxy;
36 class TEmulatedCollectionProxy;
37 
38 #if defined(_WIN32)
39  #if _MSC_VER<1300
40  #define TYPENAME
41  #define R__VCXX6
42  #else
43  #define TYPENAME typename
44  #endif
45 #else
46  #define TYPENAME typename
47 #endif
48 
49 
50 /** \class TCollectionProxyFactory TCollectionProxyFactory.h
51  TCollectionProxyFactory
52  Interface to collection proxy and streamer generator.
53  Proxy around an arbitrary container, which implements basic
54  functionality and iteration. The purpose of this implementation
55  is to shield any generated dictionary implementation from the
56  underlying streamer/proxy implementation and only expose
57  the creation functions.
58 
59  In particular this is used to implement splitting and abstract
60  element access of any container. Access to compiled code is necessary
61  to implement the abstract iteration sequence and functionality like
62  size(), clear(), resize(). resize() may be a void operation.
63 
64  \author M.Frank
65  \version 1.0
66 */
67 class TCollectionProxyFactory {
68 public:
69 
70  typedef TVirtualCollectionProxy Proxy_t;
71 #ifdef R__HPUX
72  typedef const std::type_info& Info_t;
73 #else
74  typedef const std::type_info& Info_t;
75 #endif
76 
77  /// Generate emulated collection proxy for a given class
78  static TVirtualCollectionProxy* GenEmulatedProxy(const char* class_name, Bool_t silent);
79 
80  /// Generate emulated class streamer for a given collection class
81  static TClassStreamer* GenEmulatedClassStreamer(const char* class_name, Bool_t silent);
82 
83  /// Generate emulated member streamer for a given collection class
84  static TMemberStreamer* GenEmulatedMemberStreamer(const char* class_name, Bool_t silent);
85 
86 
87  /// Generate proxy from static functions
88  static Proxy_t* GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
89 
90  /// Generate proxy from template
91  template <class T> static Proxy_t* GenProxy(const T &arg, TClass *cl) {
92  return GenExplicitProxy( ::ROOT::TCollectionProxyInfo::Get(arg), cl );
93  }
94 
95  /// Generate streamer from static functions
96  static TGenCollectionStreamer*
97  GenExplicitStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
98 
99  /// Generate class streamer from static functions
100  static TClassStreamer*
101  GenExplicitClassStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
102 
103  /// Generate class streamer from template
104  template <class T> static TClassStreamer* GenClassStreamer(const T &arg, TClass *cl) {
105  return GenExplicitClassStreamer(::ROOT::TCollectionProxyInfo::Get(arg), cl);
106  }
107 
108  /// Generate member streamer from static functions
109  static TMemberStreamer*
110  GenExplicitMemberStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl);
111 
112  /// Generate member streamer from template
113  template <class T> static TMemberStreamer* GenMemberStreamer(const T &arg, TClass *cl) {
114  return GenExplicitMemberStreamer(::ROOT::TCollectionProxyInfo::Get(arg), cl);
115  }
116 };
117 
118 /**
119  \class TCollectionStreamer TCollectionProxyFactory.h
120  \ingroup IO
121 
122  Class streamer object to implement TClassStreamer functionality for I/O emulation.
123 
124  @author M.Frank
125  @version 1.0
126 */
127 class TCollectionStreamer {
128 private:
129  TCollectionStreamer& operator=(const TCollectionStreamer&); // not implemented
130 
131 protected:
132  TGenCollectionProxy* fStreamer; ///< Pointer to worker streamer
133 
134  /// Issue Error about invalid proxy
135  void InvalidProxyError();
136 
137 public:
138  /// Initializing constructor
139  TCollectionStreamer();
140  /// Copy constructor
141  TCollectionStreamer(const TCollectionStreamer& c);
142  /// Standard destructor
143  virtual ~TCollectionStreamer();
144  /// Attach worker proxy
145  void AdoptStreamer(TGenCollectionProxy* streamer);
146  /// Streamer for I/O handling
147  void Streamer(TBuffer &refBuffer, void *obj, int siz, TClass *onFileClass );
148 };
149 
150 /**
151  \class TCollectionClassStreamer TCollectionProxyFactory.h
152  \ingroup IO
153 
154  Class streamer object to implement TClassStreamer functionality
155  for I/O emulation.
156  \author M.Frank
157  \version 1.0
158 */
159 class TCollectionClassStreamer : public TClassStreamer, public TCollectionStreamer {
160  protected:
161  TCollectionClassStreamer &operator=(const TCollectionClassStreamer &rhs); // Not implemented.
162  /// Copy constructor
163  TCollectionClassStreamer(const TCollectionClassStreamer& c)
164  : TClassStreamer(c), TCollectionStreamer(c) { }
165 
166 public:
167  /// Initializing constructor
168  TCollectionClassStreamer() : TClassStreamer(0) { }
169  /// Standard destructor
170  virtual ~TCollectionClassStreamer() { }
171  /// Streamer for I/O handling
172  virtual void operator()(TBuffer &buff, void *obj ) { Streamer(buff,obj,0,fOnFileClass); }
173 
174  virtual void Stream(TBuffer &b, void *obj, const TClass *onfileClass)
175  {
176  if (b.IsReading()) {
177  TGenCollectionProxy *proxy = TCollectionStreamer::fStreamer;
178  if (onfileClass==0 || onfileClass == proxy->GetCollectionClass()) {
179  proxy->ReadBuffer(b,obj);
180  } else {
181  proxy->ReadBuffer(b,obj,onfileClass);
182  }
183  } else {
184  // fStreamer->WriteBuffer(b,objp,onfileClass);
185  Streamer(b,obj,0,(TClass*)onfileClass);
186  }
187  }
188 
189  /// Virtual copy constructor.
190  virtual TClassStreamer *Generate() const {
191  return new TCollectionClassStreamer(*this);
192  }
193 
194  TGenCollectionProxy *GetXYZ() { return TCollectionStreamer::fStreamer; }
195 
196 };
197 
198 /**
199  \class TCollectionMemberStreamer TCollectionProxyFactory.h
200  \ingroup IO
201 
202  Class streamer object to implement TMemberStreamer functionality
203  for I/O emulation.
204  \author M.Frank
205  \version 1.0
206  */
207 class TCollectionMemberStreamer : public TMemberStreamer, public TCollectionStreamer {
208 private:
209  TCollectionMemberStreamer &operator=(const TCollectionMemberStreamer &rhs); // Not implemented.
210 public:
211  /// Initializing constructor
212  TCollectionMemberStreamer() : TMemberStreamer(0) { }
213  /// Copy constructor
214  TCollectionMemberStreamer(const TCollectionMemberStreamer& c)
215  : TMemberStreamer(c), TCollectionStreamer(c) { }
216  /// Standard destructor
217  virtual ~TCollectionMemberStreamer() { }
218  /// Streamer for I/O handling
219  virtual void operator()(TBuffer &buff,void *obj,Int_t siz=0)
220  { Streamer(buff, obj, siz, 0); /* FIXME */ }
221 };
222 
223 #endif