TCollectionProxyFactory.cxx

Go to the documentation of this file.
00001 // @(#)root/io:$Id: TCollectionProxyFactory.cxx 31746 2009-12-09 21:55:27Z pcanal $
00002 // Author: Markus Frank 28/10/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, 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 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TGenCollectionProxy
00015 //
00016 // Proxy around an arbitrary container, which implements basic
00017 // functionality and iteration. The purpose of this implementation
00018 // is to shield any generated dictionary implementation from the
00019 // underlying streamer/proxy implementation and only expose
00020 // the creation functions.
00021 //
00022 // In particular this is used to implement splitting and abstract
00023 // element access of any container. Access to compiled code is necessary
00024 // to implement the abstract iteration sequence and functionality like
00025 // size(), clear(), resize(). resize() may be a void operation.
00026 //
00027 //////////////////////////////////////////////////////////////////////////
00028 
00029 #include "TError.h"
00030 #include "TClassEdit.h"
00031 #include "TCollectionProxyFactory.h"
00032 #include "TGenCollectionProxy.h"
00033 #include "TGenCollectionStreamer.h"
00034 
00035 #include "TEmulatedMapProxy.h"
00036 #include "TEmulatedCollectionProxy.h"
00037 
00038 // Do not clutter global namespace with shit....
00039 namespace {
00040    static TClassEdit::ESTLType stl_type(const std::string& class_name)  {
00041       // return the STL type.
00042       int nested = 0;
00043       std::vector<std::string> inside;
00044       int num = TClassEdit::GetSplit(class_name.c_str(),inside,nested);
00045       if ( num > 1 )  {
00046          return (TClassEdit::ESTLType)TClassEdit::STLKind(inside[0].c_str());
00047       }
00048       return TClassEdit::kNotSTL;
00049    }
00050 
00051    static TEmulatedCollectionProxy* GenEmulation(const char* class_name)  {
00052       // Generate an emulated collection proxy.
00053 
00054       if ( class_name )  {
00055          std::string cl = class_name;
00056          if ( cl.find("stdext::hash_") != std::string::npos )
00057             cl.replace(3,10,"::");
00058          if ( cl.find("__gnu_cxx::hash_") != std::string::npos )
00059             cl.replace(0,16,"std::");
00060          TEmulatedCollectionProxy * result = 0;
00061          switch ( stl_type(cl) )  {
00062             case TClassEdit::kNotSTL:
00063                return 0;
00064             case TClassEdit::kMap:
00065             case TClassEdit::kMultiMap:
00066                result = new TEmulatedMapProxy(class_name);
00067                break;
00068             default:
00069                result = new TEmulatedCollectionProxy(class_name);
00070          }
00071          if ( result->IsValid() ) { 
00072             return result;
00073          }
00074       }
00075       return 0;
00076    }
00077 }
00078 
00079 TVirtualCollectionProxy*
00080 TCollectionProxyFactory::GenEmulatedProxy(const char* class_name)
00081 {
00082    // Generate emulated collection proxy for a given class.
00083 
00084    return GenEmulation(class_name);
00085 }
00086 
00087 TClassStreamer*
00088 TCollectionProxyFactory::GenEmulatedClassStreamer(const char* class_name)
00089 {
00090    // Generate emulated class streamer for a given collection class.
00091 
00092    TCollectionClassStreamer* s = new TCollectionClassStreamer();
00093    s->AdoptStreamer(GenEmulation(class_name));
00094    return s;
00095 }
00096 
00097 TMemberStreamer*
00098 TCollectionProxyFactory::GenEmulatedMemberStreamer(const char* class_name)
00099 {
00100    // Generate emulated member streamer for a given collection class.
00101    TCollectionMemberStreamer* s = new TCollectionMemberStreamer();
00102    s->AdoptStreamer(GenEmulation(class_name));
00103    return s;
00104 }
00105 
00106 TCollectionProxyFactory::Proxy_t*
00107 TCollectionProxyFactory::GenExplicitProxy( const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
00108 {
00109    // Generate proxy from static functions.
00110    return new TGenCollectionProxy(info,cl);
00111 }
00112 
00113 TGenCollectionStreamer*
00114 TCollectionProxyFactory::GenExplicitStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
00115 {
00116    // Generate streamer from static functions.
00117    TGenCollectionStreamer* ptr = new TGenCollectionStreamer(info,cl);
00118    return ptr;
00119 }
00120 
00121 TClassStreamer*
00122 TCollectionProxyFactory::GenExplicitClassStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl )
00123 {
00124    // Generate class streamer from static functions.
00125    TCollectionClassStreamer* s = new TCollectionClassStreamer();
00126    s->AdoptStreamer(GenExplicitStreamer(info,cl));
00127    return s;
00128 }
00129 
00130 TMemberStreamer*
00131 TCollectionProxyFactory::GenExplicitMemberStreamer( const ::ROOT::TCollectionProxyInfo &info, TClass *cl)
00132 {
00133    // Generate member streamer from static functions.
00134    TCollectionMemberStreamer* s = new TCollectionMemberStreamer();
00135    s->AdoptStreamer(GenExplicitStreamer(info,cl));
00136    return s;
00137 }
00138 
00139 void TCollectionStreamer::InvalidProxyError()   {
00140    // Issue Error about invalid proxy.
00141    Fatal("TCollectionStreamer>","No proxy available. Data streaming impossible.");
00142 }
00143 
00144 TCollectionStreamer::TCollectionStreamer() : fStreamer(0)
00145 {
00146    // Initializing constructor.
00147 }
00148 
00149 TCollectionStreamer::TCollectionStreamer(const TCollectionStreamer& c) : fStreamer(0)
00150 {
00151    // Copy constructor.
00152    if ( c.fStreamer )  {
00153       fStreamer = dynamic_cast<TGenCollectionProxy*>(c.fStreamer->Generate());
00154       R__ASSERT(fStreamer != 0);
00155       return;
00156    }
00157    InvalidProxyError();
00158 }
00159 
00160 TCollectionStreamer::~TCollectionStreamer()
00161 {
00162    // Standard destructor.
00163    if ( fStreamer )  {
00164       delete fStreamer;
00165    }
00166 }
00167 
00168 void TCollectionStreamer::AdoptStreamer(TGenCollectionProxy* streamer)
00169 {
00170    // Attach worker proxy.
00171    if ( fStreamer )  {
00172       delete fStreamer;
00173    }
00174    fStreamer = streamer;
00175 }
00176 
00177 void TCollectionStreamer::Streamer(TBuffer &buff, void *pObj, int /* siz */, TClass* onFileClass )
00178 {
00179    // Streamer for I/O handling.
00180    if ( fStreamer )  {
00181       TVirtualCollectionProxy::TPushPop env(fStreamer, pObj);
00182       fStreamer->SetOnFileClass( onFileClass );
00183       fStreamer->Streamer(buff);
00184 
00185       return;
00186    }
00187    InvalidProxyError();
00188 }

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