ROOT logo
// @(#)root/base:$Id: TEnv.h 29398 2009-07-08 12:52:29Z rdm $
// Author: Fons Rademakers   22/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TEnv
#define ROOT_TEnv


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TEnv                                                                 //
//                                                                      //
// The TEnv class reads config files, by default named .rootrc. Three   //
// types of config files are read: global, user and local files. The    //
// global file is $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>)//
// the user file is $HOME/<name> and the local file is ./<name>.        //
// By setting the shell variable ROOTENV_NO_HOME=1 the reading of       //
// the $HOME/<name> resource file will be skipped. This might be useful //
// in case the home directory resides on an automounted remote file     //
// system and one wants to avoid this file system from being mounted.   //
//                                                                      //
// The format of the .rootrc file is similar to the .Xdefaults format:  //
//                                                                      //
//   [+]<SystemName>.<RootName|ProgName>.<name>[(type)]:  <value>       //
//                                                                      //
// Where <SystemName> is either Unix, WinNT, MacOS or Vms,              //
// <RootName> the name as given in the TApplication ctor (or "RootApp"  //
// in case no explicit TApplication derived object was created),        //
// <ProgName> the current program name and <name> the resource name,    //
// with optionally a type specification. <value> can be either a        //
// string, an integer, a float/double or a boolean with the values      //
// TRUE, FALSE, ON, OFF, YES, NO, OK, NOT. Booleans will be returned as //
// an integer 0 or 1. The options [+] allows the concatenation of       //
// values to the same resouce name.                                     //
//                                                                      //
// E.g.:                                                                //
//                                                                      //
//   Unix.Rint.Root.DynamicPath: .:$ROOTSYS/lib:~/lib                   //
//   myapp.Root.Debug:  FALSE                                           //
//   TH.Root.Debug: YES                                                 //
//   *.Root.MemStat: 1                                                  //
//                                                                      //
// <SystemName> and <ProgName> or <RootName> may be the wildcard "*".   //
// A # in the first column starts comment line.                         //
//                                                                      //
// For the currently defined resources (and their default values) see   //
// $ROOTSYS/etc/system.rootrc.                                          //
//                                                                      //
// Note that the .rootrc config files contain the config for all ROOT   //
// based applications.                                                  //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif

class THashList;
class TEnv;
class TEnvParser;
class TReadEnvParser;
class TWriteEnvParser;

enum EEnvLevel {
   kEnvGlobal,
   kEnvUser,
   kEnvLocal,
   kEnvChange,
   kEnvAll
};


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TEnvRec                                                              //
//                                                                      //
// Individual TEnv records.                                             //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TEnvRec : public TObject {

friend class  TEnv;
friend class  TEnvParser;
friend class  TReadEnvParser;
friend class  TWriteEnvParser;

private:
   TString     fName;       // env rec key name
   TString     fType;       // env rec type
   TString     fValue;      // env rec value
   EEnvLevel   fLevel;      // env rec level
   Bool_t      fModified;   // if env rec has been modified

   TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
   Int_t    Compare(const TObject *obj) const;
   void     ChangeValue(const char *v, const char *t, EEnvLevel l,
                        Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
   TString  ExpandValue(const char *v);

public:
   TEnvRec(): fName(), fType(), fValue(), fLevel(kEnvAll), fModified(kTRUE) { }
   const char *GetName() const { return fName; }
   const char *GetValue() const { return fValue; }
   const char *GetType() const { return fType; }
   EEnvLevel   GetLevel() const { return fLevel; }
   ULong_t     Hash() const { return fName.Hash(); }

   ClassDef(TEnvRec,2)  // Individual TEnv records
};

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TEnv                                                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

class TEnv : public TObject {

private:
   THashList        *fTable;     // hash table containing env records
   TString           fRcName;    // resource file base name
   Bool_t            fIgnoreDup; // ignore duplicates, don't issue warning

   TEnv(const TEnv&);            // not implemented
   TEnv& operator=(const TEnv&); // not implemented

   const char       *Getvalue(const char *name);

public:
   TEnv(const char *name="");
   virtual ~TEnv();

   THashList          *GetTable() const { return fTable; }
   Bool_t              Defined(const char *name)
                                    { return Getvalue(name) != 0; }

   virtual const char *GetRcName() const { return fRcName; }
   virtual void        SetRcName(const char *name) { fRcName = name; }

   virtual Int_t       GetValue(const char *name, Int_t dflt);
   virtual Double_t    GetValue(const char *name, Double_t dflt);
   virtual const char *GetValue(const char *name, const char *dflt);

   virtual void        SetValue(const char *name, const char *value,
                                EEnvLevel level = kEnvChange,
                                const char *type = 0);
   virtual void        SetValue(const char *name, EEnvLevel level = kEnvChange);
   virtual void        SetValue(const char *name, Int_t value);
   virtual void        SetValue(const char *name, Double_t value);

   virtual TEnvRec    *Lookup(const char *n);
   virtual Int_t       ReadFile(const char *fname, EEnvLevel level);
   virtual Int_t       WriteFile(const char *fname, EEnvLevel level = kEnvAll);
   virtual void        Save();
   virtual void        SaveLevel(EEnvLevel level);
   virtual void        Print(Option_t *option="") const;
   virtual void        PrintEnv(EEnvLevel level = kEnvAll) const;
   Bool_t              IgnoreDuplicates(Bool_t ignore);

   ClassDef(TEnv,2)  // Handle ROOT configuration resources
};

R__EXTERN TEnv *gEnv;

#endif
 TEnv.h:1
 TEnv.h:2
 TEnv.h:3
 TEnv.h:4
 TEnv.h:5
 TEnv.h:6
 TEnv.h:7
 TEnv.h:8
 TEnv.h:9
 TEnv.h:10
 TEnv.h:11
 TEnv.h:12
 TEnv.h:13
 TEnv.h:14
 TEnv.h:15
 TEnv.h:16
 TEnv.h:17
 TEnv.h:18
 TEnv.h:19
 TEnv.h:20
 TEnv.h:21
 TEnv.h:22
 TEnv.h:23
 TEnv.h:24
 TEnv.h:25
 TEnv.h:26
 TEnv.h:27
 TEnv.h:28
 TEnv.h:29
 TEnv.h:30
 TEnv.h:31
 TEnv.h:32
 TEnv.h:33
 TEnv.h:34
 TEnv.h:35
 TEnv.h:36
 TEnv.h:37
 TEnv.h:38
 TEnv.h:39
 TEnv.h:40
 TEnv.h:41
 TEnv.h:42
 TEnv.h:43
 TEnv.h:44
 TEnv.h:45
 TEnv.h:46
 TEnv.h:47
 TEnv.h:48
 TEnv.h:49
 TEnv.h:50
 TEnv.h:51
 TEnv.h:52
 TEnv.h:53
 TEnv.h:54
 TEnv.h:55
 TEnv.h:56
 TEnv.h:57
 TEnv.h:58
 TEnv.h:59
 TEnv.h:60
 TEnv.h:61
 TEnv.h:62
 TEnv.h:63
 TEnv.h:64
 TEnv.h:65
 TEnv.h:66
 TEnv.h:67
 TEnv.h:68
 TEnv.h:69
 TEnv.h:70
 TEnv.h:71
 TEnv.h:72
 TEnv.h:73
 TEnv.h:74
 TEnv.h:75
 TEnv.h:76
 TEnv.h:77
 TEnv.h:78
 TEnv.h:79
 TEnv.h:80
 TEnv.h:81
 TEnv.h:82
 TEnv.h:83
 TEnv.h:84
 TEnv.h:85
 TEnv.h:86
 TEnv.h:87
 TEnv.h:88
 TEnv.h:89
 TEnv.h:90
 TEnv.h:91
 TEnv.h:92
 TEnv.h:93
 TEnv.h:94
 TEnv.h:95
 TEnv.h:96
 TEnv.h:97
 TEnv.h:98
 TEnv.h:99
 TEnv.h:100
 TEnv.h:101
 TEnv.h:102
 TEnv.h:103
 TEnv.h:104
 TEnv.h:105
 TEnv.h:106
 TEnv.h:107
 TEnv.h:108
 TEnv.h:109
 TEnv.h:110
 TEnv.h:111
 TEnv.h:112
 TEnv.h:113
 TEnv.h:114
 TEnv.h:115
 TEnv.h:116
 TEnv.h:117
 TEnv.h:118
 TEnv.h:119
 TEnv.h:120
 TEnv.h:121
 TEnv.h:122
 TEnv.h:123
 TEnv.h:124
 TEnv.h:125
 TEnv.h:126
 TEnv.h:127
 TEnv.h:128
 TEnv.h:129
 TEnv.h:130
 TEnv.h:131
 TEnv.h:132
 TEnv.h:133
 TEnv.h:134
 TEnv.h:135
 TEnv.h:136
 TEnv.h:137
 TEnv.h:138
 TEnv.h:139
 TEnv.h:140
 TEnv.h:141
 TEnv.h:142
 TEnv.h:143
 TEnv.h:144
 TEnv.h:145
 TEnv.h:146
 TEnv.h:147
 TEnv.h:148
 TEnv.h:149
 TEnv.h:150
 TEnv.h:151
 TEnv.h:152
 TEnv.h:153
 TEnv.h:154
 TEnv.h:155
 TEnv.h:156
 TEnv.h:157
 TEnv.h:158
 TEnv.h:159
 TEnv.h:160
 TEnv.h:161
 TEnv.h:162
 TEnv.h:163
 TEnv.h:164
 TEnv.h:165
 TEnv.h:166
 TEnv.h:167
 TEnv.h:168
 TEnv.h:169
 TEnv.h:170
 TEnv.h:171
 TEnv.h:172
 TEnv.h:173
 TEnv.h:174
 TEnv.h:175
 TEnv.h:176