TEnv.h

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TEnv.h 29398 2009-07-08 12:52:29Z rdm $
00002 // Author: Fons Rademakers   22/09/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TEnv
00013 #define ROOT_TEnv
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TEnv                                                                 //
00019 //                                                                      //
00020 // The TEnv class reads config files, by default named .rootrc. Three   //
00021 // types of config files are read: global, user and local files. The    //
00022 // global file is $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>)//
00023 // the user file is $HOME/<name> and the local file is ./<name>.        //
00024 // By setting the shell variable ROOTENV_NO_HOME=1 the reading of       //
00025 // the $HOME/<name> resource file will be skipped. This might be useful //
00026 // in case the home directory resides on an automounted remote file     //
00027 // system and one wants to avoid this file system from being mounted.   //
00028 //                                                                      //
00029 // The format of the .rootrc file is similar to the .Xdefaults format:  //
00030 //                                                                      //
00031 //   [+]<SystemName>.<RootName|ProgName>.<name>[(type)]:  <value>       //
00032 //                                                                      //
00033 // Where <SystemName> is either Unix, WinNT, MacOS or Vms,              //
00034 // <RootName> the name as given in the TApplication ctor (or "RootApp"  //
00035 // in case no explicit TApplication derived object was created),        //
00036 // <ProgName> the current program name and <name> the resource name,    //
00037 // with optionally a type specification. <value> can be either a        //
00038 // string, an integer, a float/double or a boolean with the values      //
00039 // TRUE, FALSE, ON, OFF, YES, NO, OK, NOT. Booleans will be returned as //
00040 // an integer 0 or 1. The options [+] allows the concatenation of       //
00041 // values to the same resouce name.                                     //
00042 //                                                                      //
00043 // E.g.:                                                                //
00044 //                                                                      //
00045 //   Unix.Rint.Root.DynamicPath: .:$ROOTSYS/lib:~/lib                   //
00046 //   myapp.Root.Debug:  FALSE                                           //
00047 //   TH.Root.Debug: YES                                                 //
00048 //   *.Root.MemStat: 1                                                  //
00049 //                                                                      //
00050 // <SystemName> and <ProgName> or <RootName> may be the wildcard "*".   //
00051 // A # in the first column starts comment line.                         //
00052 //                                                                      //
00053 // For the currently defined resources (and their default values) see   //
00054 // $ROOTSYS/etc/system.rootrc.                                          //
00055 //                                                                      //
00056 // Note that the .rootrc config files contain the config for all ROOT   //
00057 // based applications.                                                  //
00058 //                                                                      //
00059 //////////////////////////////////////////////////////////////////////////
00060 
00061 #ifndef ROOT_TObject
00062 #include "TObject.h"
00063 #endif
00064 #ifndef ROOT_TString
00065 #include "TString.h"
00066 #endif
00067 
00068 class THashList;
00069 class TEnv;
00070 class TEnvParser;
00071 class TReadEnvParser;
00072 class TWriteEnvParser;
00073 
00074 enum EEnvLevel {
00075    kEnvGlobal,
00076    kEnvUser,
00077    kEnvLocal,
00078    kEnvChange,
00079    kEnvAll
00080 };
00081 
00082 
00083 //////////////////////////////////////////////////////////////////////////
00084 //                                                                      //
00085 // TEnvRec                                                              //
00086 //                                                                      //
00087 // Individual TEnv records.                                             //
00088 //                                                                      //
00089 //////////////////////////////////////////////////////////////////////////
00090 
00091 class TEnvRec : public TObject {
00092 
00093 friend class  TEnv;
00094 friend class  TEnvParser;
00095 friend class  TReadEnvParser;
00096 friend class  TWriteEnvParser;
00097 
00098 private:
00099    TString     fName;       // env rec key name
00100    TString     fType;       // env rec type
00101    TString     fValue;      // env rec value
00102    EEnvLevel   fLevel;      // env rec level
00103    Bool_t      fModified;   // if env rec has been modified
00104 
00105    TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
00106    Int_t    Compare(const TObject *obj) const;
00107    void     ChangeValue(const char *v, const char *t, EEnvLevel l,
00108                         Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
00109    TString  ExpandValue(const char *v);
00110 
00111 public:
00112    TEnvRec(): fName(), fType(), fValue(), fLevel(kEnvAll), fModified(kTRUE) { }
00113    const char *GetName() const { return fName; }
00114    const char *GetValue() const { return fValue; }
00115    const char *GetType() const { return fType; }
00116    EEnvLevel   GetLevel() const { return fLevel; }
00117    ULong_t     Hash() const { return fName.Hash(); }
00118 
00119    ClassDef(TEnvRec,2)  // Individual TEnv records
00120 };
00121 
00122 //////////////////////////////////////////////////////////////////////////
00123 //                                                                      //
00124 // TEnv                                                                 //
00125 //                                                                      //
00126 //////////////////////////////////////////////////////////////////////////
00127 
00128 class TEnv : public TObject {
00129 
00130 private:
00131    THashList        *fTable;     // hash table containing env records
00132    TString           fRcName;    // resource file base name
00133    Bool_t            fIgnoreDup; // ignore duplicates, don't issue warning
00134 
00135    TEnv(const TEnv&);            // not implemented
00136    TEnv& operator=(const TEnv&); // not implemented
00137 
00138    const char       *Getvalue(const char *name);
00139 
00140 public:
00141    TEnv(const char *name="");
00142    virtual ~TEnv();
00143 
00144    THashList          *GetTable() const { return fTable; }
00145    Bool_t              Defined(const char *name)
00146                                     { return Getvalue(name) != 0; }
00147 
00148    virtual const char *GetRcName() const { return fRcName; }
00149    virtual void        SetRcName(const char *name) { fRcName = name; }
00150 
00151    virtual Int_t       GetValue(const char *name, Int_t dflt);
00152    virtual Double_t    GetValue(const char *name, Double_t dflt);
00153    virtual const char *GetValue(const char *name, const char *dflt);
00154 
00155    virtual void        SetValue(const char *name, const char *value,
00156                                 EEnvLevel level = kEnvChange,
00157                                 const char *type = 0);
00158    virtual void        SetValue(const char *name, EEnvLevel level = kEnvChange);
00159    virtual void        SetValue(const char *name, Int_t value);
00160    virtual void        SetValue(const char *name, Double_t value);
00161 
00162    virtual TEnvRec    *Lookup(const char *n);
00163    virtual Int_t       ReadFile(const char *fname, EEnvLevel level);
00164    virtual Int_t       WriteFile(const char *fname, EEnvLevel level = kEnvAll);
00165    virtual void        Save();
00166    virtual void        SaveLevel(EEnvLevel level);
00167    virtual void        Print(Option_t *option="") const;
00168    virtual void        PrintEnv(EEnvLevel level = kEnvAll) const;
00169    Bool_t              IgnoreDuplicates(Bool_t ignore);
00170 
00171    ClassDef(TEnv,2)  // Handle ROOT configuration resources
00172 };
00173 
00174 R__EXTERN TEnv *gEnv;
00175 
00176 #endif

Generated on Tue Jul 5 14:10:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1