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#include "TObject.h"
16#include "TString.h"
17
18class THashList;
19class TEnv;
20class TEnvParser;
21class TReadEnvParser;
22class TWriteEnvParser;
23
31
32
33//////////////////////////////////////////////////////////////////////////
34// //
35// TEnvRec //
36// //
37// Individual TEnv records. //
38// //
39//////////////////////////////////////////////////////////////////////////
40
41class TEnvRec : public TObject {
42
43friend class TEnv;
44friend class TEnvParser;
45friend class TReadEnvParser;
46friend class TWriteEnvParser;
47
48private:
49 TString fName; // env rec key name
50 TString fType; // env rec type
51 TString fValue; // env rec value
52 EEnvLevel fLevel; // env rec level
53 Bool_t fModified; // if env rec has been modified
54
55 TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
56 Int_t Compare(const TObject *obj) const override;
57 void ChangeValue(const char *v, const char *t, EEnvLevel l,
58 Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
59 TString ExpandValue(const char *v);
60
61public:
63 ~TEnvRec();
64 const char *GetName() const override { return fName; }
65 const char *GetValue() const { return fValue; }
66 const char *GetType() const { return fType; }
67 EEnvLevel GetLevel() const { return fLevel; }
68 ULong_t Hash() const override { return fName.Hash(); }
69
70 ClassDefOverride(TEnvRec,2) // Individual TEnv records
71};
72
73//////////////////////////////////////////////////////////////////////////
74// //
75// TEnv //
76// //
77//////////////////////////////////////////////////////////////////////////
78
79class TEnv : public TObject {
80
81private:
82 THashList *fTable; // hash table containing env records
83 TString fRcName; // resource file base name
84 Bool_t fIgnoreDup; // ignore duplicates, don't issue warning
85
86 TEnv(const TEnv&) = delete;
87 TEnv& operator=(const TEnv&) = delete;
88
89 const char *Getvalue(const char *name) const;
90 const char *GetUserDirectory() const;
91
92public:
93 TEnv(const char *name="");
94 virtual ~TEnv();
95
96 THashList *GetTable() const { return fTable; }
97 Bool_t Defined(const char *name) const
98 { return Getvalue(name) != nullptr; }
99
100 virtual const char *GetRcName() const { return fRcName; }
101 virtual void SetRcName(const char *name) { fRcName = name; }
102
103 virtual Int_t GetValue(const char *name, Int_t dflt) const;
104 virtual Double_t GetValue(const char *name, Double_t dflt) const;
105 virtual const char *GetValue(const char *name, const char *dflt) const;
106
107 virtual void SetValue(const char *name, const char *value,
108 EEnvLevel level = kEnvChange,
109 const char *type = nullptr);
110 virtual void SetValue(const char *name, EEnvLevel level = kEnvChange);
111 virtual void SetValue(const char *name, Int_t value);
112 virtual void SetValue(const char *name, Double_t value);
113
114 virtual TEnvRec *Lookup(const char *n) const;
115 virtual Int_t ReadFile(const char *fname, EEnvLevel level);
116 virtual Int_t WriteFile(const char *fname, EEnvLevel level = kEnvAll);
117 virtual void Save();
118 virtual void SaveLevel(EEnvLevel level);
119 void Print(Option_t *option="") const override;
120 virtual void PrintEnv(EEnvLevel level = kEnvAll) const;
122
123 ClassDefOverride(TEnv,2) // Handle ROOT configuration resources
124};
125
127
128#endif
#define R__EXTERN
Definition DllImport.h:26
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
EEnvLevel
Definition TEnv.h:24
@ kEnvUser
Definition TEnv.h:26
@ kEnvChange
Definition TEnv.h:28
@ kEnvAll
Definition TEnv.h:29
@ kEnvGlobal
Definition TEnv.h:25
@ kEnvLocal
Definition TEnv.h:27
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:148
TEnv Parser.
Definition TEnv.cxx:110
Definition TEnv.h:41
TString fValue
Definition TEnv.h:51
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:297
const char * GetType() const
Definition TEnv.h:66
EEnvLevel fLevel
Definition TEnv.h:52
EEnvLevel GetLevel() const
Definition TEnv.h:67
TEnvRec()
Definition TEnv.h:62
const char * GetValue() const
Definition TEnv.h:65
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
Definition TEnv.cxx:338
ULong_t Hash() const override
Return hash value for this object.
Definition TEnv.h:68
TString fName
Definition TEnv.h:49
TString fType
Definition TEnv.h:50
Bool_t fModified
Definition TEnv.h:53
const char * GetName() const override
Returns name of object.
Definition TEnv.h:64
~TEnvRec()
TNamed destructor.
Definition TEnv.cxx:288
Int_t Compare(const TObject *obj) const override
Comparison function for resources.
Definition TEnv.cxx:329
The TEnv class reads config files, by default named .rootrc.
Definition TEnv.h:79
THashList * fTable
Definition TEnv.h:82
void Print(Option_t *option="") const override
Print all resources or the global, user or local resources separately.
Definition TEnv.cxx:576
const char * GetUserDirectory() const
Returns the home directory or, if set, the value of the environment variable ROOTENV_USER_PATH.
Definition TEnv.cxx:395
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
Definition TEnv.cxx:594
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
THashList * GetTable() const
Definition TEnv.h:96
TString fRcName
Definition TEnv.h:83
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
Definition TEnv.cxx:637
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition TEnv.cxx:809
virtual void SetRcName(const char *name)
Definition TEnv.h:101
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition TEnv.cxx:612
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:752
virtual TEnvRec * Lookup(const char *n) const
Loop over all resource records and return the one with name.
Definition TEnv.cxx:567
virtual void Save()
Write the resource files for each level.
Definition TEnv.cxx:669
Bool_t Defined(const char *name) const
Definition TEnv.h:97
Bool_t fIgnoreDup
Definition TEnv.h:84
virtual const char * GetRcName() const
Definition TEnv.h:100
const char * Getvalue(const char *name) const
Returns the character value for a named resource.
Definition TEnv.cxx:461
TEnv & operator=(const TEnv &)=delete
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
Definition TEnv.cxx:684
virtual ~TEnv()
Delete the resource table.
Definition TEnv.cxx:450
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:42
Basic string class.
Definition TString.h:138
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition TString.cxx:684
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4