ROOT logo
// @(#)root/cont:$Id: TVirtualCollectionProxy.h 22613 2008-03-12 09:37:19Z brun $
// Author: Philippe Canal 20/08/2003

/*************************************************************************
 * Copyright (C) 1995-2003, Rene Brun, Fons Rademakers and al.           *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef Root_TVirtualCollectionProxy
#define Root_TVirtualCollectionProxy

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TVirtualCollectionProxy                                              //
//                                                                      //
// Virtual interface of a proxy object for a collection class           //
// In particular this is used to implement splitting, emulation,        //
// and TTreeFormula access to STL containers.                           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TClassRef.h"
#include "TDataType.h"

class TClass;

class TVirtualCollectionProxy {
private:
   TVirtualCollectionProxy(const TVirtualCollectionProxy&); // Not implemented
   TVirtualCollectionProxy& operator=(const TVirtualCollectionProxy&); // Not implemented

protected:
   TClassRef fClass;
   virtual void SetValueClass(TClass *newcl) = 0;
   friend class TClass;

public:
   class TPushPop {
      // Helper class that insures that push and pop are done when entering
      // and leaving a C++ context (even in the presence of exceptions)
   public:
      TVirtualCollectionProxy *fProxy;
      inline TPushPop(TVirtualCollectionProxy *proxy, 
         void *objectstart) : fProxy(proxy) { fProxy->PushProxy(objectstart); }
      inline ~TPushPop() { fProxy->PopProxy(); }
   private:
      TPushPop(const TPushPop&); // Not implemented
      TPushPop& operator=(const TPushPop&); // Not implemented
   };

   TVirtualCollectionProxy() : fClass() {};
   TVirtualCollectionProxy(TClass *cl) : fClass(cl) {};
  
   virtual TVirtualCollectionProxy* Generate() const = 0; // Returns an object of the actual CollectionProxy class
   virtual ~TVirtualCollectionProxy() {};
   virtual TClass   *GetCollectionClass() { return fClass; } // Return a pointer to the TClass representing the container

   virtual void     *New() const {                // Return a new container object
     return fClass.GetClass()==0 ? 0 : fClass->New();
   }
   virtual void     *New(void *arena) const {     // Execute the container constructor
     return fClass.GetClass()==0 ? 0 : fClass->New(arena);
   }

   virtual void     *NewArray(Int_t nElements) const {                // Return a new container object
     return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements);
   }
   virtual void     *NewArray(Int_t nElements, void *arena) const {     // Execute the container constructor
     return fClass.GetClass()==0 ? 0 : fClass->NewArray(nElements, arena);
   }

   virtual void      Destructor(void *p, Bool_t dtorOnly = kFALSE) { // Execute the container destructor
     TClass* cl = fClass.GetClass();
     if (cl) cl->Destructor(p, dtorOnly);
   }

   virtual void      DeleteArray(void *p, Bool_t dtorOnly = kFALSE) { // Execute the container array destructor
     TClass* cl = fClass.GetClass();
     if (cl) cl->DeleteArray(p, dtorOnly);
   }

   virtual UInt_t    Sizeof() const = 0; // Return the sizeof the collection object.

   virtual void      PushProxy(void *objectstart) = 0; // Set the address of the container being proxied and keep track of the previous one.
   virtual void      PopProxy() = 0;                   // Reset the address of the container being proxied to the previous container

   virtual Bool_t    HasPointers() const = 0; // Return true if the content is of type 'pointer to'

   virtual TClass   *GetValueClass() = 0;     // Return a pointer to the TClass representing the content.
   virtual EDataType GetType() = 0;           // If the content is a simple numerical value, return its type (see TDataType)
   virtual void     *At(UInt_t idx) = 0;                       // Return the address of the value at index 'idx'
   virtual void      Clear(const char *opt = "") = 0;          // Clear the container
   virtual UInt_t    Size() const = 0;                         // Return the current size of the container
   virtual void*     Allocate(UInt_t n, Bool_t forceDelete) = 0;
   virtual void      Commit(void*) = 0;
           char     *operator[](UInt_t idx) const { return (char*)(const_cast<TVirtualCollectionProxy*>(this))->At(idx); }
};

#endif
 TVirtualCollectionProxy.h:1
 TVirtualCollectionProxy.h:2
 TVirtualCollectionProxy.h:3
 TVirtualCollectionProxy.h:4
 TVirtualCollectionProxy.h:5
 TVirtualCollectionProxy.h:6
 TVirtualCollectionProxy.h:7
 TVirtualCollectionProxy.h:8
 TVirtualCollectionProxy.h:9
 TVirtualCollectionProxy.h:10
 TVirtualCollectionProxy.h:11
 TVirtualCollectionProxy.h:12
 TVirtualCollectionProxy.h:13
 TVirtualCollectionProxy.h:14
 TVirtualCollectionProxy.h:15
 TVirtualCollectionProxy.h:16
 TVirtualCollectionProxy.h:17
 TVirtualCollectionProxy.h:18
 TVirtualCollectionProxy.h:19
 TVirtualCollectionProxy.h:20
 TVirtualCollectionProxy.h:21
 TVirtualCollectionProxy.h:22
 TVirtualCollectionProxy.h:23
 TVirtualCollectionProxy.h:24
 TVirtualCollectionProxy.h:25
 TVirtualCollectionProxy.h:26
 TVirtualCollectionProxy.h:27
 TVirtualCollectionProxy.h:28
 TVirtualCollectionProxy.h:29
 TVirtualCollectionProxy.h:30
 TVirtualCollectionProxy.h:31
 TVirtualCollectionProxy.h:32
 TVirtualCollectionProxy.h:33
 TVirtualCollectionProxy.h:34
 TVirtualCollectionProxy.h:35
 TVirtualCollectionProxy.h:36
 TVirtualCollectionProxy.h:37
 TVirtualCollectionProxy.h:38
 TVirtualCollectionProxy.h:39
 TVirtualCollectionProxy.h:40
 TVirtualCollectionProxy.h:41
 TVirtualCollectionProxy.h:42
 TVirtualCollectionProxy.h:43
 TVirtualCollectionProxy.h:44
 TVirtualCollectionProxy.h:45
 TVirtualCollectionProxy.h:46
 TVirtualCollectionProxy.h:47
 TVirtualCollectionProxy.h:48
 TVirtualCollectionProxy.h:49
 TVirtualCollectionProxy.h:50
 TVirtualCollectionProxy.h:51
 TVirtualCollectionProxy.h:52
 TVirtualCollectionProxy.h:53
 TVirtualCollectionProxy.h:54
 TVirtualCollectionProxy.h:55
 TVirtualCollectionProxy.h:56
 TVirtualCollectionProxy.h:57
 TVirtualCollectionProxy.h:58
 TVirtualCollectionProxy.h:59
 TVirtualCollectionProxy.h:60
 TVirtualCollectionProxy.h:61
 TVirtualCollectionProxy.h:62
 TVirtualCollectionProxy.h:63
 TVirtualCollectionProxy.h:64
 TVirtualCollectionProxy.h:65
 TVirtualCollectionProxy.h:66
 TVirtualCollectionProxy.h:67
 TVirtualCollectionProxy.h:68
 TVirtualCollectionProxy.h:69
 TVirtualCollectionProxy.h:70
 TVirtualCollectionProxy.h:71
 TVirtualCollectionProxy.h:72
 TVirtualCollectionProxy.h:73
 TVirtualCollectionProxy.h:74
 TVirtualCollectionProxy.h:75
 TVirtualCollectionProxy.h:76
 TVirtualCollectionProxy.h:77
 TVirtualCollectionProxy.h:78
 TVirtualCollectionProxy.h:79
 TVirtualCollectionProxy.h:80
 TVirtualCollectionProxy.h:81
 TVirtualCollectionProxy.h:82
 TVirtualCollectionProxy.h:83
 TVirtualCollectionProxy.h:84
 TVirtualCollectionProxy.h:85
 TVirtualCollectionProxy.h:86
 TVirtualCollectionProxy.h:87
 TVirtualCollectionProxy.h:88
 TVirtualCollectionProxy.h:89
 TVirtualCollectionProxy.h:90
 TVirtualCollectionProxy.h:91
 TVirtualCollectionProxy.h:92
 TVirtualCollectionProxy.h:93
 TVirtualCollectionProxy.h:94
 TVirtualCollectionProxy.h:95
 TVirtualCollectionProxy.h:96
 TVirtualCollectionProxy.h:97
 TVirtualCollectionProxy.h:98
 TVirtualCollectionProxy.h:99
 TVirtualCollectionProxy.h:100
 TVirtualCollectionProxy.h:101
 TVirtualCollectionProxy.h:102