Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TInterpreter.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Fons Rademakers 01/03/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 TInterpreter
13 This class defines an abstract interface to a generic command line
14 interpreter.
15 */
16 
17 #include "TInterpreter.h"
18 
19 #include "TROOT.h"
20 #include "TError.h"
21 #include "TGlobal.h"
22 
23 
24 TInterpreter* gCling = nullptr; // returns pointer to global TCling object
25 static TInterpreter *gInterpreterLocal = nullptr; // The real holder of the pointer.
26 
27 
28 namespace {
29 static struct AddPseudoGlobals {
30 AddPseudoGlobals() {
31 
32  // use special functor to extract pointer on gInterpreterLocal variable
33  TGlobalMappedFunction::MakeFunctor("gInterpreter", "TInterpreter*", TInterpreter::Instance, [] {
34  TInterpreter::Instance();
35  return (void *) &gInterpreterLocal;
36  });
37 
38 }
39 } gAddPseudoGlobals;
40 }
41 
42 
43 ClassImp(TInterpreter);
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// TInterpreter ctor only called by derived classes.
47 
48 TInterpreter::TInterpreter(const char *name, const char *title)
49  : TNamed(name, title)
50 {
51  gInterpreterLocal = this;
52  gCling = this;
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// returns gInterpreter global
57 
58 TInterpreter *TInterpreter::Instance()
59 {
60  if (gInterpreterLocal == 0) {
61  static TROOT *getROOT = ROOT::GetROOT(); // Make sure gInterpreterLocal is set
62  if (!getROOT) {
63  ::Fatal("TInterpreter::Instance","TROOT object is required before accessing a TInterpreter");
64  }
65  }
66  return gInterpreterLocal;
67 }