TCollectionProxyFactory.h

Go to the documentation of this file.
00001 // @(#)root/io:$Id: TCollectionProxyFactory.h 36061 2010-10-04 16:05:51Z pcanal $
00002 // Author: Markus Frank  28/10/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 #ifndef ROOT_TCollectionProxyFactory
00012 #define ROOT_TCollectionProxyFactory
00013 
00014 //////////////////////////////////////////////////////////////////////////
00015 //                                                                      //
00016 //  Small helper to save proxy environment in the event of
00017 //  recursive calls.
00018 //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include <typeinfo>
00022 #include <vector>
00023 
00024 #ifndef ROOT_TCollectionProxyInfo
00025 #include "TCollectionProxyInfo.h"
00026 #endif
00027 
00028 #ifndef ROOT_TClassStreamer
00029 #include "TClassStreamer.h"
00030 #endif
00031 
00032 #ifndef ROOT_TMemberStreamer
00033 #include "TMemberStreamer.h"
00034 #endif
00035 
00036 #ifndef ROOT_TGenCollectionProxy
00037 #include "TGenCollectionProxy.h"
00038 #endif
00039 
00040 // Forward declarations
00041 class TBuffer;
00042 class TGenCollectionProxy;
00043 class TGenCollectionStreamer;
00044 class TVirtualCollectionProxy;
00045 class TEmulatedCollectionProxy;
00046 
00047 #if defined(_WIN32)
00048    #if _MSC_VER<1300
00049       #define TYPENAME
00050       #define R__VCXX6
00051    #else
00052       #define TYPENAME typename
00053    #endif
00054 #else
00055    #define TYPENAME typename
00056 #endif
00057 
00058 
00059 /** @class TCollectionProxyFactory TCollectionProxyFactory.h cont/TCollectionProxyFactory.h
00060   *
00061   * TCollectionProxyFactory
00062   * Interface to collection proxy and streamer generator.
00063   *
00064   * Proxy around an arbitrary container, which implements basic
00065   * functionality and iteration. The purpose of this implementation
00066   * is to shield any generated dictionary implementation from the
00067   * underlying streamer/proxy implementation and only expose
00068   * the creation functions.
00069   *
00070   * In particular this is used to implement splitting and abstract
00071   * element access of any container. Access to compiled code is necessary
00072   * to implement the abstract iteration sequence and functionality like
00073   * size(), clear(), resize(). resize() may be a void operation.
00074   *
00075   * @author  M.Frank
00076   * @version 1.0
00077   */
00078 class TCollectionProxyFactory  {
00079 public:
00080 
00081    typedef TVirtualCollectionProxy Proxy_t;
00082 #ifdef R__HPUX
00083    typedef const type_info&      Info_t;
00084 #else
00085    typedef const std::type_info& Info_t;
00086 #endif
00087 
00088 
00089 
00090 
00091    /// Generate emulated collection proxy for a given class
00092    static TVirtualCollectionProxy* GenEmulatedProxy(const char* class_name);
00093 
00094    /// Generate emulated class streamer for a given collection class
00095    static TClassStreamer* GenEmulatedClassStreamer(const char* class_name);
00096 
00097    /// Generate emulated member streamer for a given collection class
00098    static TMemberStreamer* GenEmulatedMemberStreamer(const char* class_name);
00099 
00100 
00101    /// Generate proxy from static functions
00102    static Proxy_t* GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
00103 
00104    /// Generate proxy from template
00105    template <class T> static Proxy_t* GenProxy(const T &arg, TClass *cl)  {
00106       return GenExplicitProxy( ::ROOT::TCollectionProxyInfo::Get(arg), cl );
00107    }
00108 
00109    /// Generate streamer from static functions
00110    static TGenCollectionStreamer*
00111       GenExplicitStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
00112 
00113    /// Generate class streamer from static functions
00114    static TClassStreamer*
00115       GenExplicitClassStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl );
00116 
00117    /// Generate class streamer from template
00118    template <class T> static TClassStreamer* GenClassStreamer(const T &arg, TClass *cl)  {
00119       return GenExplicitClassStreamer(::ROOT::TCollectionProxyInfo::Get(arg), cl);
00120    }
00121 
00122    /// Generate member streamer from static functions
00123    static TMemberStreamer*
00124       GenExplicitMemberStreamer(const ::ROOT::TCollectionProxyInfo &info, TClass *cl);
00125 
00126    /// Generate member streamer from template
00127    template <class T> static TMemberStreamer* GenMemberStreamer(const T &arg, TClass *cl)  {
00128       return GenExplicitMemberStreamer(::ROOT::TCollectionProxyInfo::Get(arg), cl);
00129    }
00130 };
00131 
00132 /** @class TCollectionStreamer TCollectionProxyFactory.h cont/TCollectionProxyFactory.h
00133  *
00134  * TEmulatedClassStreamer
00135  *
00136  * Class streamer object to implement TClassStreamr functionality
00137  * for I/O emulation.
00138  *
00139  * @author  M.Frank
00140  * @version 1.0
00141  */
00142 class TCollectionStreamer   {
00143 private:
00144    TCollectionStreamer& operator=(const TCollectionStreamer&);   // not implemented
00145 
00146 protected:
00147    TGenCollectionProxy* fStreamer;   /// Pointer to worker streamer
00148 
00149    /// Issue Error about invalid proxy
00150    void InvalidProxyError();
00151 
00152 public:
00153    /// Initializing constructor
00154    TCollectionStreamer();
00155    /// Copy constructor
00156    TCollectionStreamer(const TCollectionStreamer& c);
00157    /// Standard destructor
00158    virtual ~TCollectionStreamer();
00159    /// Attach worker proxy
00160    void AdoptStreamer(TGenCollectionProxy* streamer);
00161    /// Streamer for I/O handling
00162    void Streamer(TBuffer &refBuffer, void *obj, int siz, TClass *onFileClass );
00163 };
00164 
00165 /** @class TEmulatedClassStreamer TCollectionProxy.h cont/TCollectionProxy.h
00166   *
00167   * TEmulatedClassStreamer
00168   *
00169   * Class streamer object to implement TClassStreamr functionality
00170   * for I/O emulation.
00171   *
00172   * @author  M.Frank
00173   * @version 1.0
00174   */
00175 class TCollectionClassStreamer : public TClassStreamer, public TCollectionStreamer {
00176 public:
00177    /// Initializing constructor
00178    TCollectionClassStreamer() : TClassStreamer(0)     {                        }
00179    /// Copy constructor
00180    TCollectionClassStreamer(const TCollectionClassStreamer& c)
00181       : TClassStreamer(c), TCollectionStreamer(c)      {                        }
00182    /// Standard destructor
00183    virtual ~TCollectionClassStreamer()                {                        }
00184    /// Streamer for I/O handling
00185    virtual void operator()(TBuffer &buff, void *obj ) { Streamer(buff,obj,0,fOnFileClass); }
00186 
00187    virtual void Stream(TBuffer &b, void *obj, const TClass *onfileClass)
00188    {
00189       if (b.IsReading()) {
00190          TGenCollectionProxy *proxy = TCollectionStreamer::fStreamer;
00191          if (onfileClass==0 || onfileClass == proxy->GetCollectionClass()) {
00192             proxy->ReadBuffer(b,obj);
00193          } else {
00194             proxy->ReadBuffer(b,obj,onfileClass);
00195          }
00196       } else {
00197          // fStreamer->WriteBuffer(b,objp,onfileClass);
00198          Streamer(b,obj,0,(TClass*)onfileClass);
00199       }
00200    }
00201    
00202    /// Virtual copy constructor.
00203    virtual TClassStreamer *Generate() const {
00204       return new TCollectionClassStreamer(*this);
00205    }
00206 
00207    TGenCollectionProxy *GetXYZ() { return TCollectionStreamer::fStreamer; }
00208 
00209 };
00210 
00211 /** @class TCollectionMemberStreamer TCollectionProxyFactory.h cont/TCollectionProxyFactory.h
00212   *
00213   * TCollectionMemberStreamer
00214   *
00215   * Class streamer object to implement TMemberStreamer functionality
00216   * for I/O emulation.
00217   *
00218   * @author  M.Frank
00219   * @version 1.0
00220   */
00221 class TCollectionMemberStreamer : public TMemberStreamer, public TCollectionStreamer {
00222 public:
00223    /// Initializing constructor
00224    TCollectionMemberStreamer() : TMemberStreamer(0) { }
00225    /// Copy constructor
00226    TCollectionMemberStreamer(const TCollectionMemberStreamer& c)
00227       : TMemberStreamer(c), TCollectionStreamer(c)   { }
00228    /// Standard destructor
00229    virtual ~TCollectionMemberStreamer()             { }
00230    /// Streamer for I/O handling
00231    virtual void operator()(TBuffer &buff,void *obj,Int_t siz=0)
00232    { Streamer(buff, obj, siz, 0); /* FIXME */ }   
00233 };
00234 
00235 #endif

Generated on Tue Jul 5 14:26:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1