Logo ROOT   6.12/07
Reference Guide
TEnv.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 22/09/95
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 #ifndef ROOT_TEnv
13 #define ROOT_TEnv
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TEnv //
19 // //
20 // The TEnv class reads config files, by default named .rootrc. Three //
21 // types of config files are read: global, user and local files. The //
22 // global file is $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>)//
23 // the user file is $HOME/<name> and the local file is ./<name>. //
24 // By setting the shell variable ROOTENV_NO_HOME=1 the reading of //
25 // the $HOME/<name> resource file will be skipped. This might be useful //
26 // in case the home directory resides on an automounted remote file //
27 // system and one wants to avoid this file system from being mounted. //
28 // //
29 // The format of the .rootrc file is similar to the .Xdefaults format: //
30 // //
31 // [+]<SystemName>.<RootName|ProgName>.<name>[(type)]: <value> //
32 // //
33 // Where <SystemName> is either Unix, WinNT, MacOS or Vms, //
34 // <RootName> the name as given in the TApplication ctor (or "RootApp" //
35 // in case no explicit TApplication derived object was created), //
36 // <ProgName> the current program name and <name> the resource name, //
37 // with optionally a type specification. <value> can be either a //
38 // string, an integer, a float/double or a boolean with the values //
39 // TRUE, FALSE, ON, OFF, YES, NO, OK, NOT. Booleans will be returned as //
40 // an integer 0 or 1. The options [+] allows the concatenation of //
41 // values to the same resouce name. //
42 // //
43 // E.g.: //
44 // //
45 // Unix.Rint.Root.DynamicPath: .:$ROOTSYS/lib:~/lib //
46 // myapp.Root.Debug: FALSE //
47 // TH.Root.Debug: YES //
48 // *.Root.MemStat: 1 //
49 // //
50 // <SystemName> and <ProgName> or <RootName> may be the wildcard "*". //
51 // A # in the first column starts comment line. //
52 // //
53 // For the currently defined resources (and their default values) see //
54 // $ROOTSYS/etc/system.rootrc. //
55 // //
56 // Note that the .rootrc config files contain the config for all ROOT //
57 // based applications. //
58 // //
59 //////////////////////////////////////////////////////////////////////////
60 
61 #include "TObject.h"
62 #include "TString.h"
63 
64 class THashList;
65 class TEnv;
66 class TEnvParser;
67 class TReadEnvParser;
68 class TWriteEnvParser;
69 
70 enum EEnvLevel {
76 };
77 
78 
79 //////////////////////////////////////////////////////////////////////////
80 // //
81 // TEnvRec //
82 // //
83 // Individual TEnv records. //
84 // //
85 //////////////////////////////////////////////////////////////////////////
86 
87 class TEnvRec : public TObject {
88 
89 friend class TEnv;
90 friend class TEnvParser;
91 friend class TReadEnvParser;
92 friend class TWriteEnvParser;
93 
94 private:
95  TString fName; // env rec key name
96  TString fType; // env rec type
97  TString fValue; // env rec value
98  EEnvLevel fLevel; // env rec level
99  Bool_t fModified; // if env rec has been modified
100 
101  TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
102  Int_t Compare(const TObject *obj) const;
103  void ChangeValue(const char *v, const char *t, EEnvLevel l,
104  Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
105  TString ExpandValue(const char *v);
106 
107 public:
108  TEnvRec(): fName(), fType(), fValue(), fLevel(kEnvAll), fModified(kTRUE) { }
109  ~TEnvRec();
110  const char *GetName() const { return fName; }
111  const char *GetValue() const { return fValue; }
112  const char *GetType() const { return fType; }
113  EEnvLevel GetLevel() const { return fLevel; }
114  ULong_t Hash() const { return fName.Hash(); }
115 
116  ClassDef(TEnvRec,2) // Individual TEnv records
117 };
118 
119 //////////////////////////////////////////////////////////////////////////
120 // //
121 // TEnv //
122 // //
123 //////////////////////////////////////////////////////////////////////////
124 
125 class TEnv : public TObject {
126 
127 private:
128  THashList *fTable; // hash table containing env records
129  TString fRcName; // resource file base name
130  Bool_t fIgnoreDup; // ignore duplicates, don't issue warning
131 
132  TEnv(const TEnv&); // not implemented
133  TEnv& operator=(const TEnv&); // not implemented
134 
135  const char *Getvalue(const char *name) const;
136 
137 public:
138  TEnv(const char *name="");
139  virtual ~TEnv();
140 
141  THashList *GetTable() const { return fTable; }
142  Bool_t Defined(const char *name) const
143  { return Getvalue(name) != 0; }
144 
145  virtual const char *GetRcName() const { return fRcName; }
146  virtual void SetRcName(const char *name) { fRcName = name; }
147 
148  virtual Int_t GetValue(const char *name, Int_t dflt) const;
149  virtual Double_t GetValue(const char *name, Double_t dflt) const;
150  virtual const char *GetValue(const char *name, const char *dflt) const;
151 
152  virtual void SetValue(const char *name, const char *value,
153  EEnvLevel level = kEnvChange,
154  const char *type = 0);
155  virtual void SetValue(const char *name, EEnvLevel level = kEnvChange);
156  virtual void SetValue(const char *name, Int_t value);
157  virtual void SetValue(const char *name, Double_t value);
158 
159  virtual TEnvRec *Lookup(const char *n) const;
160  virtual Int_t ReadFile(const char *fname, EEnvLevel level);
161  virtual Int_t WriteFile(const char *fname, EEnvLevel level = kEnvAll);
162  virtual void Save();
163  virtual void SaveLevel(EEnvLevel level);
164  virtual void Print(Option_t *option="") const;
165  virtual void PrintEnv(EEnvLevel level = kEnvAll) const;
166  Bool_t IgnoreDuplicates(Bool_t ignore);
167 
168  ClassDef(TEnv,2) // Handle ROOT configuration resources
169 };
170 
172 
173 #endif
Bool_t fIgnoreDup
Definition: TEnv.h:130
virtual void SetRcName(const char *name)
Definition: TEnv.h:146
virtual const char * GetRcName() const
Definition: TEnv.h:145
TEnvRec()
Definition: TEnv.h:108
Definition: TEnv.h:72
ULong_t Hash() const
Return hash value for this object.
Definition: TEnv.h:114
const char Option_t
Definition: RtypesCore.h:62
The TEnv class reads config files, by default named .rootrc.
Definition: TEnv.h:125
Basic string class.
Definition: TString.h:125
void ChangeValue(const char *v, const char *t, EEnvLevel l, Bool_t append=kFALSE, Bool_t ignoredup=kFALSE)
Change the value of a resource.
Definition: TEnv.cxx:292
const char * GetValue() const
Definition: TEnv.h:111
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:616
friend class TEnvParser
Definition: TEnv.h:90
#define ClassDef(name, id)
Definition: Rtypes.h:320
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
TString fName
Definition: TEnv.h:95
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:271
Bool_t fModified
Definition: TEnv.h:99
EEnvLevel
Definition: TEnv.h:70
EEnvLevel GetLevel() const
Definition: TEnv.h:113
~TEnvRec()
TNamed destructor.
Definition: TEnv.cxx:283
Definition: TEnv.h:87
Bool_t Defined(const char *name) const
Definition: TEnv.h:142
SVector< double, 2 > v
Definition: Dict.h:5
friend class TWriteEnvParser
Definition: TEnv.h:92
THashList * GetTable() const
Definition: TEnv.h:141
const char * GetName() const
Returns name of object.
Definition: TEnv.h:110
Definition: TEnv.h:73
const Bool_t kFALSE
Definition: RtypesCore.h:88
Definition: TEnv.h:75
Int_t Compare(const TObject *obj) const
Comparison function for resources.
Definition: TEnv.cxx:324
THashList * fTable
Definition: TEnv.h:128
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
Definition: TEnv.cxx:333
double Double_t
Definition: RtypesCore.h:55
const char * GetType() const
Definition: TEnv.h:112
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
unsigned long ULong_t
Definition: RtypesCore.h:51
friend class TReadEnvParser
Definition: TEnv.h:91
TString fType
Definition: TEnv.h:96
friend class TEnv
Definition: TEnv.h:89
Mother of all ROOT objects.
Definition: TObject.h:37
#define R__EXTERN
Definition: DllImport.h:27
RooCmdArg Save(Bool_t flag=kTRUE)
auto * l
Definition: textangle.C:4
TString fValue
Definition: TEnv.h:97
EEnvLevel fLevel
Definition: TEnv.h:98
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
TString fRcName
Definition: TEnv.h:129