// @(#)root/meta:$Id$
// Author: Axel Naumann 2014-04-28

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


#ifndef ROOT_TProtoClass
#define ROOT_TProtoClass

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif

class TClass;
class TList;
class TRealData;

#include "TDataMember.h"

#include <vector>

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TProtoClass                                                          //
//                                                                      //
// Stores enough information to create a TClass from a dictionary       //
// without interpreter information.                                     //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TProtoClass: public TNamed {
public:
   struct TProtoRealData  {
      Long_t fOffset; // data member offset
      Int_t fDMIndex;  // index of data member in vector of data members
      Int_t fLevel;  // member level (0 : belong to this class, 1 is a data member of a data member object, etc...)
      Int_t fClassIndex; // index of class belonging to in list of dep classes
      char  fStatusFlag;  // status of the real data member (if bit 0 set is an object, if bit 1 set is transient if bit 2 set is a pointer)

      enum  { 
         kIsObject    = BIT(0),   // member is object
         kIsTransient = BIT(1), // data member is transient 
         kIsPointer   = BIT(2),    // data member is a pointer 
         kBitMask     = 0x000000ff
      };

   public:
      bool IsAClass() const { return fClassIndex >= 0; }
      TProtoRealData() : fOffset(0), fDMIndex(-1), fLevel(0), fClassIndex(-1), fStatusFlag(0) {} 
      TProtoRealData(const TRealData *rd);
      virtual ~TProtoRealData();
      TRealData *CreateRealData(TClass *currentClass, TClass *parent, TRealData * parentData, int prevLevel) const;

      Bool_t TestFlag(UInt_t f) const { return (Bool_t) ((fStatusFlag & f) != 0); } 
      void SetFlag(UInt_t f, Bool_t on = kTRUE) { 
         if (on) 
            fStatusFlag |= f & kBitMask; 
         else
            fStatusFlag &= ~(f & kBitMask);  
      } 
     
      ClassDef(TProtoRealData, 3);//Persistent version of TRealData
   };

private:
   TList   *fBase;     // List of base classes
   //TList   *fData;     //! List of data members
   TList   *fEnums;    // List of enums in this scope
   std::vector<TProtoRealData>   fPRealData;// List of TProtoRealData
   std::vector<TDataMember *>       fData;   // collection of data members
   std::vector<TString>    fDepClasses;  // list of dependent classes 
   Int_t    fSizeof;   // Size of the class
   Int_t    fCanSplit; // Whether this class can be split
   Int_t    fStreamerType; // Which streaming method to use
   Long_t   fProperty; // Class properties, see EProperties
   Long_t   fClassProperty; // Class C++ properties, see EClassProperties
   Long_t   fOffsetStreamer; // Offset to streamer function

   TProtoClass(const TProtoClass &) = delete;
   TProtoClass &operator=(const TProtoClass &) = delete;

   const char * GetClassName(Int_t index) const { return (index >= 0) ? fDepClasses[index].Data() : 0; }

   // compute index of data member in the list
   static Int_t DataMemberIndex(TClass * cl, const char * name);  
   // find data member  given an index
   static TDataMember * FindDataMember(TClass * cl,  Int_t index);  

public:
   TProtoClass():
      fBase(0), fEnums(0), fSizeof(0), fCanSplit(0),
      fStreamerType(0), fProperty(0), fClassProperty(0),
      fOffsetStreamer(0) {
   }

   TProtoClass(TProtoClass *pc);
   TProtoClass(TClass *cl);
   virtual ~TProtoClass();

   Bool_t FillTClass(TClass *pcl);
   const TList *GetListOfEnums() {
      return fEnums;
   };
   void Delete(Option_t *opt = "");

   int GetSize() { return fSizeof; }
   TList * GetBaseList() { return fBase; }
   //TList * GetDataList() { return fData; }
   TList * GetEnumList() { return fEnums; }
   std::vector<TProtoRealData> & GetPRDList() { return fPRealData; }
   std::vector<TDataMember *> & GetData() { return fData; }
   std::vector<TString> & GetDepClasses() { return fDepClasses; }


   ClassDef(TProtoClass, 2); //Persistent TClass
};

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