Ignore:
Timestamp:
08/31/07 14:11:36 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r8642 r8724  
    868868}
    869869
     870// --------------------------------------------------------------------------
     871//
     872// Check if the given resource is defined. If there is a postfix, prefix
     873// the postfix with a dot. Calls IsEnvDefined(env, name, print)
     874//
    870875Bool_t MParContainer::IsEnvDefined(const TEnv &env, TString prefix, TString postfix, Bool_t print) const
    871876{
     
    876881}
    877882
     883// --------------------------------------------------------------------------
     884//
     885// If print==kTRUE print information about what's going on. This is necessary
     886// to debug parsing of resource files. Check if a resource "name" is defined
     887// and return kFALSE/kTRUE depending on the result.
     888//
    878889Bool_t MParContainer::IsEnvDefined(const TEnv &env, TString name, Bool_t print) const
    879890{
     
    881892        *fLog << all << GetDescriptor() << " - " << name << "... " << flush;
    882893
    883     if (!((TEnv&)env).Defined(name))
     894    if (!const_cast<TEnv&>(env).Defined(name))
    884895    {
    885896        if (print)
     
    894905}
    895906
     907// --------------------------------------------------------------------------
     908//
     909// Return the resource prefix+"."+postfix from env or deftl if not available.
     910// If prefix IsNull search for postfix only.
     911//
    896912Int_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, Int_t dflt) const
    897913{
    898     return GetEnvValue(env, prefix+"."+postfix, dflt);
    899 }
    900 
     914    return GetEnvValue(env, prefix.IsNull()?postfix:(prefix+"."+postfix), dflt);
     915}
     916
     917// --------------------------------------------------------------------------
     918//
     919// Return the resource prefix+"."+postfix from env or deftl if not available.
     920// If prefix IsNull search for postfix only.
     921//
    901922Double_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, Double_t dflt) const
    902923{
    903     return GetEnvValue(env, prefix+"."+postfix, dflt);
    904 }
    905 
     924    return GetEnvValue(env, prefix.IsNull()?postfix:(prefix+"."+postfix), dflt);
     925}
     926
     927// --------------------------------------------------------------------------
     928//
     929// Return the resource prefix+"."+postfix from env or deftl if not available.
     930// If prefix IsNull search for postfix only.
     931//
    906932const char *MParContainer::GetEnvValue(const TEnv &env, TString prefix, TString postfix, const char *dflt) const
    907933{
    908     return GetEnvValue(env, prefix+"."+postfix, dflt);
    909 }
    910 
     934    return GetEnvValue(env, prefix.IsNull()?postfix:(prefix+"."+postfix), dflt);
     935}
     936
     937// --------------------------------------------------------------------------
     938//
     939// Return the resource prefix from env or deftl if not available.
     940//
    911941Int_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, Int_t dflt) const
    912942{
    913     return ((TEnv&)env).GetValue(prefix, dflt);
    914 }
    915 
     943    return const_cast<TEnv&>(env).GetValue(prefix, dflt);
     944}
     945
     946// --------------------------------------------------------------------------
     947//
     948// Return the resource prefix from env or deftl if not available.
     949//
    916950Double_t MParContainer::GetEnvValue(const TEnv &env, TString prefix, Double_t dflt) const
    917951{
    918     return ((TEnv&)env).GetValue(prefix, dflt);
    919 }
    920 
     952    return const_cast<TEnv&>(env).GetValue(prefix, dflt);
     953}
     954
     955// --------------------------------------------------------------------------
     956//
     957// Return the resource prefix from env or deftl if not available.
     958//
    921959const char *MParContainer::GetEnvValue(const TEnv &env, TString prefix, const char *dflt) const
    922960{
    923     return ((TEnv&)env).GetValue(prefix, dflt);
     961    return const_cast<TEnv&>(env).GetValue(prefix, dflt);
     962}
     963
     964// --------------------------------------------------------------------------
     965//
     966// Check for the resource prefix+"."+postfix. If it is not available or
     967// prefix IsNull check for the more common resource postfix. If none
     968// is found return the default.
     969//
     970template <class T>
     971T MParContainer::GetEnvValue2Imp(const TEnv &env, const TString &prefix, const TString &postfix, T dftl, Bool_t print) const
     972{
     973    // Check for a dedicated resource (prefix.postfix) first
     974    if (!prefix.IsNull())
     975    {
     976        if (IsEnvDefined(env, prefix, postfix, print))
     977            return GetEnvValue(env, prefix, postfix, dftl);
     978    }
     979
     980    // check for a general resource (postfix)
     981    if (IsEnvDefined(env, postfix, print))
     982        return GetEnvValue(env, postfix, dftl);
     983
     984    // return default
     985    return dftl;
     986}
     987
     988// --------------------------------------------------------------------------
     989//
     990// see template GetEnvValue2Imp
     991//
     992const char *MParContainer::GetEnvValue2(const TEnv &env, const TString &prefix, const TString &postfix, const char *dftl, Bool_t print) const
     993{
     994    return GetEnvValue2Imp(env, prefix, postfix, dftl, print);
     995}
     996
     997// --------------------------------------------------------------------------
     998//
     999// see template GetEnvValue2Imp
     1000//
     1001Int_t MParContainer::GetEnvValue2(const TEnv &env, const TString &prefix, const TString &postfix, Int_t dftl, Bool_t print) const
     1002{
     1003    return GetEnvValue2Imp(env, prefix, postfix, dftl, print);
     1004}
     1005
     1006// --------------------------------------------------------------------------
     1007//
     1008// see template GetEnvValue2Imp
     1009//
     1010Double_t MParContainer::GetEnvValue2(const TEnv &env, const TString &prefix, const TString &postfix, Double_t dftl, Bool_t print) const
     1011{
     1012    return GetEnvValue2Imp(env, prefix, postfix, dftl, print);
    9241013}
    9251014
Note: See TracChangeset for help on using the changeset viewer.