Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TFunctionTemplate.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Philippe Canal November 2013.
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 TFunctionTemplate
13 Dictionary for function template
14 This class describes one single function template.
15 */
16 
17 #include "TFunctionTemplate.h"
18 #include "TInterpreter.h"
19 #include "TClass.h"
20 #include "TROOT.h"
21 
22 ClassImp(TFunctionTemplate);
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Default TFunctionTemplate ctor.
26 
27 TFunctionTemplate::TFunctionTemplate(FuncTempInfo_t *info, TClass *cl) : TDictionary(),
28  fInfo(info), fClass(cl)
29 {
30  if (fInfo) {
31  gCling->FuncTempInfo_Name(fInfo,fName);
32  gCling->FuncTempInfo_Title(fInfo,fTitle);
33  }
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Copy operator.
38 
39 TFunctionTemplate::TFunctionTemplate(const TFunctionTemplate &orig) : TDictionary(orig)
40 {
41  if (orig.fInfo) {
42  fInfo = gCling->FuncTempInfo_FactoryCopy(orig.fInfo);
43  } else
44  fInfo = 0;
45  fClass = orig.fClass;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Assignment operator.
50 
51 TFunctionTemplate& TFunctionTemplate::operator=(const TFunctionTemplate &rhs)
52 {
53  if (this != &rhs) {
54  gCling->FuncTempInfo_Delete(fInfo);
55  if (rhs.fInfo) {
56  fInfo = gCling->FuncTempInfo_FactoryCopy(rhs.fInfo);
57  gCling->FuncTempInfo_Name(fInfo,fName);
58  gCling->FuncTempInfo_Title(fInfo,fTitle);
59  } else
60  fInfo = 0;
61  }
62  return *this;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// TFunctionTemplate dtor deletes adopted CINT FuncTempInfo.
67 
68 TFunctionTemplate::~TFunctionTemplate()
69 {
70  gCling->FuncTempInfo_Delete(fInfo);
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Clone method.
75 
76 TObject *TFunctionTemplate::Clone(const char *newname) const
77 {
78  TNamed *newobj = new TFunctionTemplate(*this);
79  if (newname && strlen(newname)) newobj->SetName(newname);
80  return newobj;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Return true if this function template object is pointing to a currently
85 /// loaded function. If a function is unloaded after the TFunction
86 /// is created, the TFunction will be set to be invalid.
87 
88 Bool_t TFunctionTemplate::IsValid()
89 {
90  // Register the transaction when checking the validity of the object.
91  if (!fInfo && UpdateInterpreterStateMarker()) {
92  // Only for global functions. For data member functions TMethod does it.
93  DeclId_t newId = gInterpreter->GetFunction(0, fName);
94  if (newId) {
95  FuncTempInfo_t *info = gInterpreter->FuncTempInfo_Factory(newId);
96  Update(info);
97  }
98  return newId != 0;
99  }
100  return fInfo != 0;
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Number of function arguments.
105 
106 UInt_t TFunctionTemplate::GetTemplateNargs() const
107 {
108  return fInfo ? gCling->FuncTempInfo_TemplateNargs(fInfo) : 0;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Number of function optional (default) arguments.
113 
114 UInt_t TFunctionTemplate::GetTemplateMinReqArgs() const
115 {
116  // FIXME: when unload this is an over-estimate.
117  return fInfo ? gCling->FuncTempInfo_TemplateMinReqArgs(fInfo) : 0;
118 }
119 
120 ////////////////////////////////////////////////////////////////////////////////
121 /// Get property description word. For meaning of bits see EProperty.
122 
123 Long_t TFunctionTemplate::Property() const
124 {
125  return fInfo ? gCling->FuncTempInfo_Property(fInfo) : 0;
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Get the properties not already defined in Property.See TDictionary's EFunctionProperty.
130 
131 Long_t TFunctionTemplate::ExtraProperty() const
132 {
133  return fInfo ? gCling->FuncTempInfo_ExtraProperty(fInfo) : 0;
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 
138 TDictionary::DeclId_t TFunctionTemplate::GetDeclId() const
139 {
140  return gInterpreter->GetDeclId(fInfo);
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Update the TFunctionTemplate to reflect the new info.
145 ///
146 /// This can be used to implement unloading (info == 0) and then reloading
147 /// (info being the 'new' decl address).
148 
149 Bool_t TFunctionTemplate::Update(FuncTempInfo_t *info)
150 {
151  if (info == 0) {
152  if (fInfo) gCling->FuncTempInfo_Delete(fInfo);
153  fInfo = 0;
154  return kTRUE;
155  } else {
156  if (fInfo) gCling->FuncTempInfo_Delete(fInfo);
157  fInfo = info;
158  gCling->FuncTempInfo_Title(fInfo,fTitle);
159  return kTRUE;
160  }
161 }
162