00001 // @(#)root/meta:$Id: TFunction.cxx 24077 2008-05-31 19:39:09Z brun $ 00002 // Author: Fons Rademakers 07/02/97 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 // Global functions class (global functions are obtaine from CINT). // 00015 // This class describes one single global function. // 00016 // The TROOT class contains a list of all currently defined global // 00017 // functions (accessible via TROOT::GetListOfGlobalFunctions()). // 00018 // // 00019 ////////////////////////////////////////////////////////////////////////// 00020 00021 #include "TFunction.h" 00022 #include "TMethodArg.h" 00023 #include "TROOT.h" 00024 #include "TInterpreter.h" 00025 #include "Strlen.h" 00026 00027 00028 ClassImp(TFunction) 00029 00030 //______________________________________________________________________________ 00031 TFunction::TFunction(MethodInfo_t *info) : TDictionary() 00032 { 00033 // Default TFunction ctor. TFunctions are constructed in TROOT via 00034 // a call to TCint::UpdateListOfGlobalFunctions(). 00035 00036 fInfo = info; 00037 fMethodArgs = 0; 00038 if (fInfo) { 00039 SetName(gCint->MethodInfo_Name(fInfo)); 00040 SetTitle(gCint->MethodInfo_Title(fInfo)); 00041 fMangledName = gCint->MethodInfo_GetMangledName(fInfo); 00042 } 00043 } 00044 00045 //______________________________________________________________________________ 00046 TFunction::TFunction(const TFunction &orig) : TDictionary(orig) 00047 { 00048 // Copy operator. 00049 00050 if (orig.fInfo) { 00051 fInfo = gCint->MethodInfo_FactoryCopy(orig.fInfo); 00052 fMangledName = gCint->MethodInfo_GetMangledName(fInfo); 00053 } else 00054 fInfo = 0; 00055 fMethodArgs = 0; 00056 } 00057 00058 //______________________________________________________________________________ 00059 TFunction& TFunction::operator=(const TFunction &rhs) 00060 { 00061 // Assignment operator. 00062 00063 if (this != &rhs) { 00064 gCint->MethodInfo_Delete(fInfo); 00065 if (fMethodArgs) fMethodArgs->Delete(); 00066 delete fMethodArgs; 00067 if (rhs.fInfo) { 00068 fInfo = gCint->MethodInfo_FactoryCopy(rhs.fInfo); 00069 SetName(gCint->MethodInfo_Name(fInfo)); 00070 SetTitle(gCint->MethodInfo_Title(fInfo)); 00071 fMangledName = gCint->MethodInfo_GetMangledName(fInfo); 00072 } else 00073 fInfo = 0; 00074 fMethodArgs = 0; 00075 } 00076 return *this; 00077 } 00078 00079 //______________________________________________________________________________ 00080 TFunction::~TFunction() 00081 { 00082 // TFunction dtor deletes adopted CINT MethodInfo. 00083 00084 gCint->MethodInfo_Delete(fInfo); 00085 00086 if (fMethodArgs) fMethodArgs->Delete(); 00087 delete fMethodArgs; 00088 } 00089 00090 //______________________________________________________________________________ 00091 TObject *TFunction::Clone(const char *newname) const 00092 { 00093 // Clone method. 00094 00095 TNamed *newobj = new TFunction(*this); 00096 if (newname && strlen(newname)) newobj->SetName(newname); 00097 return newobj; 00098 } 00099 00100 //______________________________________________________________________________ 00101 void TFunction::CreateSignature() 00102 { 00103 // Using the CINT method arg information to create a complete signature string. 00104 00105 gCint->MethodInfo_CreateSignature(fInfo, fSignature); 00106 } 00107 00108 //______________________________________________________________________________ 00109 const char *TFunction::GetSignature() 00110 { 00111 // Return signature of function. 00112 00113 if (fInfo && fSignature.IsNull()) 00114 CreateSignature(); 00115 00116 return fSignature.Data(); 00117 } 00118 00119 //______________________________________________________________________________ 00120 TList *TFunction::GetListOfMethodArgs() 00121 { 00122 // Return list containing the TMethodArgs of a TFunction. 00123 00124 if (!fMethodArgs) { 00125 if (!gInterpreter) 00126 Fatal("GetListOfMethodArgs", "gInterpreter not initialized"); 00127 00128 gInterpreter->CreateListOfMethodArgs(this); 00129 } 00130 return fMethodArgs; 00131 } 00132 00133 //______________________________________________________________________________ 00134 const char *TFunction::GetReturnTypeName() const 00135 { 00136 // Get full type description of function return type, e,g.: "class TDirectory*". 00137 00138 if (gCint->MethodInfo_Type(fInfo) == 0) return "Unknown"; 00139 return gCint->MethodInfo_TypeName(fInfo); 00140 } 00141 00142 //______________________________________________________________________________ 00143 Int_t TFunction::GetNargs() const 00144 { 00145 // Number of function arguments. 00146 00147 return gCint->MethodInfo_NArg(fInfo); 00148 } 00149 00150 //______________________________________________________________________________ 00151 Int_t TFunction::GetNargsOpt() const 00152 { 00153 // Number of function optional (default) arguments. 00154 00155 return gCint->MethodInfo_NDefaultArg(fInfo); 00156 } 00157 00158 //______________________________________________________________________________ 00159 Long_t TFunction::Property() const 00160 { 00161 // Get property description word. For meaning of bits see EProperty. 00162 00163 return gCint->MethodInfo_Property(fInfo); 00164 } 00165 00166 //______________________________________________________________________________ 00167 void *TFunction::InterfaceMethod() const 00168 { 00169 // Return pointer to the interface method. Using this pointer we 00170 // can find which TFunction belongs to a CINT MethodInfo object. 00171 // Both need to have the same InterfaceMethod pointer. 00172 00173 return gCint->MethodInfo_InterfaceMethod(fInfo); 00174 } 00175 00176 //______________________________________________________________________________ 00177 const char *TFunction::GetMangledName() const 00178 { 00179 // Returns the mangled name as defined by CINT, or 0 in case of error. 00180 00181 // This function is being used by TROOT to determine the full identity of 00182 // of the function. It has to work even if the function has been 00183 // unloaded by cint (in which case fInfo is actually hold reference to 00184 // memory that is (likely) not valid anymore. So we cache the information. 00185 // Maybe we should also cache the rest of the informations .. but this might 00186 // be too much duplication of information. 00187 if (fInfo) 00188 return fMangledName; 00189 else 00190 return 0; 00191 } 00192 00193 //______________________________________________________________________________ 00194 const char *TFunction::GetPrototype() const 00195 { 00196 // Returns the prototype of a function as defined by CINT, or 0 in 00197 // case of error. 00198 00199 if (fInfo) 00200 return gCint->MethodInfo_GetPrototype(fInfo); 00201 else 00202 return 0; 00203 }