Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TDictionary.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Fons Rademakers 20/06/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 
12 /** \class TDictionary
13 
14 This class defines an abstract interface that must be implemented
15 by all classes that contain dictionary information.
16 
17 The dictionary is defined by the following classes:
18 ~~~ {.cpp}
19 TDataType (typedef definitions)
20 TGlobal (global variables)
21 TGlobalFunc (global functions)
22 TClass (classes)
23  TBaseClass (base classes)
24  TDataMember (class datamembers)
25  TMethod (class methods)
26  TMethodArg (method arguments)
27 ~~~
28 All the above classes implement the TDictionary abstract interface.
29 Note: the indentation shows aggregation not inheritance.
30 ~~~ {.cpp}
31 TMethodCall (method call environment)
32 ~~~
33 \image html base_tdictionary.png
34 */
35 
36 #include "TDictionary.h"
37 #include "TClass.h"
38 #include "TClassEdit.h"
39 #include "TDataType.h"
40 #include "TDictAttributeMap.h"
41 #include "TInterpreter.h"
42 #include "TROOT.h"
43 
44 
45 ClassImp(TDictionary);
46 
47 TDictionary::TDictionary(const TDictionary& dict):
48  TNamed(dict),
49  fAttributeMap(dict.fAttributeMap ?
50  ((TDictAttributeMap*)dict.fAttributeMap->Clone()) : 0 ),
51  fUpdatingTransactionCount(0)
52 {
53  // Copy constructor, cloning fAttributeMap.
54 }
55 
56 TDictionary::~TDictionary()
57 {
58  // Destruct a TDictionary, delete the attribute map.
59  delete fAttributeMap;
60 }
61 
62 TDictionary &TDictionary::operator=(const TDictionary& dict)
63 {
64  // Assignment op, cloning fAttributeMap.
65  TNamed::operator=(dict);
66 
67  delete fAttributeMap;
68  fAttributeMap = 0;
69  if (dict.fAttributeMap)
70  fAttributeMap = ((TDictAttributeMap*)dict.fAttributeMap->Clone());
71 
72  return *this;
73 }
74 
75 void TDictionary::CreateAttributeMap()
76 {
77  //Create a TDictAttributeMap for a TClass to be able to add attribute pairs
78  //key-value to the TClass.
79 
80  if (!fAttributeMap)
81  fAttributeMap = new TDictAttributeMap;
82 }
83 
84 TDictionary* TDictionary::GetDictionary(const char* name)
85 {
86  // Retrieve the type (class, fundamental type, typedef etc)
87  // named "name". Returned object is either a TClass or TDataType.
88  // Returns 0 if the type is unknown.
89 
90  TDictionary* ret = (TDictionary*)gROOT->GetListOfTypes()->FindObject(name);
91  if (ret) return ret;
92 
93  return TClass::GetClass(name, true);
94 }
95 
96 TDictionary* TDictionary::GetDictionary(const std::type_info &typeinfo)
97 {
98  // Retrieve the type (class, fundamental type, typedef etc)
99  // with typeid typeinfo. Returned object is either a TClass or TDataType.
100  // Returns 0 if the type is unknown.
101 
102  EDataType datatype = TDataType::GetType(typeinfo);
103  TDictionary* ret = TDataType::GetDataType(datatype);
104  if (ret) return ret;
105 
106  return TClass::GetClass(typeinfo, true);
107 }
108 
109 Bool_t TDictionary::UpdateInterpreterStateMarker()
110 {
111  // Return true if there were any transactions that could have changed the
112  // state of the object.
113  ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
114  if (currentTransaction == fUpdatingTransactionCount) {
115  return false;
116  }
117  fUpdatingTransactionCount = currentTransaction;
118  return true;
119 }