Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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// //
49// <SystemName> and <ProgName> or <RootName> may be the wildcard "*". //
50// A # in the first column starts comment line. //
51// //
52// For the currently defined resources (and their default values) see //
53// $ROOTSYS/etc/system.rootrc. //
54// //
55// Note that the .rootrc config files contain the config for all ROOT //
56// based applications. //
57// //
58//////////////////////////////////////////////////////////////////////////
59
60#include "TObject.h"
61#include "TString.h"
62
63class THashList;
64class TEnv;
65class TEnvParser;
66class TReadEnvParser;
67class TWriteEnvParser;
68
75};
76
77
78//////////////////////////////////////////////////////////////////////////
79// //
80// TEnvRec //
81// //
82// Individual TEnv records. //
83// //
84//////////////////////////////////////////////////////////////////////////
85
86class TEnvRec : public TObject {
87
88friend class TEnv;
89friend class TEnvParser;
90friend class TReadEnvParser;
91friend class TWriteEnvParser;
92
93private:
94 TString fName; // env rec key name
95 TString fType; // env rec type
96 TString fValue; // env rec value
97 EEnvLevel fLevel; // env rec level
98 Bool_t fModified; // if env rec has been modified
99
100 TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
101 Int_t Compare(const TObject *obj) const;
102 void ChangeValue(const char *v, const char *t, EEnvLevel l,
103 Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
104 TString ExpandValue(const char *v);
105
106public:
108 ~TEnvRec();
109 const char *GetName() const { return fName; }
110 const char *GetValue() const { return fValue; }
111 const char *GetType() const { return fType; }
112 EEnvLevel GetLevel() const { return fLevel; }
113 ULong_t Hash() const { return fName.Hash(); }
114
115 ClassDef(TEnvRec,2) // Individual TEnv records
116};
117
118//////////////////////////////////////////////////////////////////////////
119// //
120// TEnv //
121// //
122//////////////////////////////////////////////////////////////////////////
123
124class TEnv : public TObject {
125
126private:
127 THashList *fTable; // hash table containing env records
128 TString fRcName; // resource file base name
129 Bool_t fIgnoreDup; // ignore duplicates, don't issue warning
130
131 TEnv(const TEnv&) = delete;
132 TEnv& operator=(const TEnv&) = delete;
133
134 const char *Getvalue(const char *name) const;
135
136public:
137 TEnv(const char *name="");
138 virtual ~TEnv();
139
140 THashList *GetTable() const { return fTable; }
141 Bool_t Defined(const char *name) const
142 { return Getvalue(name) != nullptr; }
143
144 virtual const char *GetRcName() const { return fRcName; }
145 virtual void SetRcName(const char *name) { fRcName = name; }
146
147 virtual Int_t GetValue(const char *name, Int_t dflt) const;
148 virtual Double_t GetValue(const char *name, Double_t dflt) const;
149 virtual const char *GetValue(const char *name, const char *dflt) const;
150
151 virtual void SetValue(const char *name, const char *value,
152 EEnvLevel level = kEnvChange,
153 const char *type = nullptr);
154 virtual void SetValue(const char *name, EEnvLevel level = kEnvChange);
155 virtual void SetValue(const char *name, Int_t value);
156 virtual void SetValue(const char *name, Double_t value);
157
158 virtual TEnvRec *Lookup(const char *n) const;
159 virtual Int_t ReadFile(const char *fname, EEnvLevel level);
160 virtual Int_t WriteFile(const char *fname, EEnvLevel level = kEnvAll);
161 virtual void Save();
162 virtual void SaveLevel(EEnvLevel level);
163 virtual void Print(Option_t *option="") const;
164 virtual void PrintEnv(EEnvLevel level = kEnvAll) const;
166
167 ClassDef(TEnv,2) // Handle ROOT configuration resources
168};
169
171
172#endif
#define R__EXTERN
Definition DllImport.h:27
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
EEnvLevel
Definition TEnv.h:69
@ kEnvUser
Definition TEnv.h:71
@ kEnvChange
Definition TEnv.h:73
@ kEnvAll
Definition TEnv.h:74
@ kEnvGlobal
Definition TEnv.h:70
@ kEnvLocal
Definition TEnv.h:72
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
TEnv Parser.
Definition TEnv.cxx:106
Definition TEnv.h:86
TString fValue
Definition TEnv.h:96
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:293
const char * GetType() const
Definition TEnv.h:111
EEnvLevel fLevel
Definition TEnv.h:97
EEnvLevel GetLevel() const
Definition TEnv.h:112
TEnvRec()
Definition TEnv.h:107
const char * GetValue() const
Definition TEnv.h:110
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
Definition TEnv.cxx:334
const char * GetName() const
Returns name of object.
Definition TEnv.h:109
ULong_t Hash() const
Return hash value for this object.
Definition TEnv.h:113
TString fName
Definition TEnv.h:94
Int_t Compare(const TObject *obj) const
Comparison function for resources.
Definition TEnv.cxx:325
TString fType
Definition TEnv.h:95
Bool_t fModified
Definition TEnv.h:98
~TEnvRec()
TNamed destructor.
Definition TEnv.cxx:284
The TEnv class reads config files, by default named .rootrc.
Definition TEnv.h:124
THashList * fTable
Definition TEnv.h:127
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
Definition TEnv.cxx:574
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
THashList * GetTable() const
Definition TEnv.h:140
TString fRcName
Definition TEnv.h:128
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
Definition TEnv.cxx:617
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition TEnv.cxx:793
virtual void SetRcName(const char *name)
Definition TEnv.h:145
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition TEnv.cxx:592
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
Definition TEnv.cxx:736
virtual TEnvRec * Lookup(const char *n) const
Loop over all resource records and return the one with name.
Definition TEnv.cxx:547
virtual void Save()
Write the resource files for each level.
Definition TEnv.cxx:649
Bool_t Defined(const char *name) const
Definition TEnv.h:141
Bool_t fIgnoreDup
Definition TEnv.h:129
virtual const char * GetRcName() const
Definition TEnv.h:144
const char * Getvalue(const char *name) const
Returns the character value for a named resource.
Definition TEnv.cxx:441
TEnv & operator=(const TEnv &)=delete
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
Definition TEnv.cxx:556
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
Definition TEnv.cxx:664
virtual ~TEnv()
Delete the resource table.
Definition TEnv.cxx:430
TEnv(const TEnv &)=delete
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:136
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition TString.cxx:662
const Int_t n
Definition legend1.C:16
auto * l
Definition textangle.C:4