| 
    SNAP Library 2.0, Developer Reference
    2013-05-13 16:33:57
    
   SNAP, a general purpose, high performance system for analysis and manipulation of large networks 
   | 
  
  
  
 
#include <env.h>

Public Member Functions | |
| TEnv () | |
| TEnv (const TEnv &) | |
| TEnv (const int &_Args, char **_ArgV, const PNotify &_Notify=NULL) | |
| TEnv (const TStr &_ArgStr, const PNotify &_Notify=NULL) | |
| TEnv & | operator= (const TEnv &Env) | 
| int | GetArgs () const | 
| TStr | GetArg (const int &ArgN) const | 
| TStr | GetExeFNm () const | 
| TStr | GetExeFPath () const | 
| TStr | GetCmLn (const int &FromArgN=1) const | 
| bool | IsSilent () const | 
| int | GetPrefixArgN (const TStr &PrefixStr) const | 
| bool | IsArgPrefix (const TStr &PrefixStr) const | 
| TStr | GetArgPostfix (const TStr &PrefixStr) const | 
| void | PrepArgs (const TStr &_HdStr=TStr(), const int &_MnArgs=1, const bool &SilentP=false) | 
| TStr | GetHdStr () const | 
| int | GetMnArgs () const | 
| bool | IsEndOfRun () const | 
| bool | IsArgStr (const TStr &ArgStr) | 
| bool | IsArgStr (const TStr &ArgStr, const TStr &DNm) | 
| TStr | GetIfArgPrefixStr (const TStr &PrefixStr, const TStr &DfVal="", const TStr &DNm="") const | 
| TStrV | GetIfArgPrefixStrV (const TStr &PrefixStr, TStrV &DfValV, const TStr &DNm="") const | 
| TStrV | GetIfArgPrefixStrV (const TStr &PrefixStr, const TStr &DNm="") const | 
| TStrSet | GetIfArgPrefixStrSet (const TStr &PrefixStr, TStrV &DfValV, const TStr &DNm="") const | 
| TStrSet | GetIfArgPrefixStrSet (const TStr &PrefixStr, const TStr &DNm="") const | 
| bool | GetIfArgPrefixBool (const TStr &PrefixStr, const bool &DfVal=false, const TStr &DNm="") const | 
| int | GetIfArgPrefixInt (const TStr &PrefixStr, const int &DfVal=0, const TStr &DNm="") const | 
| TIntV | GetIfArgPrefixIntV (const TStr &PrefixStr, TIntV &DfValV, const TStr &DNm="") const | 
| TIntV | GetIfArgPrefixIntV (const TStr &PrefixStr, const TStr &DNm="") const | 
| double | GetIfArgPrefixFlt (const TStr &PrefixStr, const double &DfVal=0, const TStr &DNm="") const | 
| TStr | GetVarVal (const TStr &VarNm) const | 
| void | GetVarNmV (TStrV &VarNmV) | 
| void | GetVarNmValV (TStrV &NmValV) | 
Static Public Member Functions | |
| static void | PutVarVal (const TStr &VarNm, const TStr &VarVal) | 
Private Attributes | |
| TStrV | ArgV | 
| TStr | HdStr | 
| int | MnArgs | 
| bool | SilentP | 
| PNotify | Notify | 
| TEnv::TEnv | ( | ) |  [inline] | 
        
| TEnv::TEnv | ( | const TEnv & | ) | 
| TEnv::TEnv | ( | const int & | _Args, | 
| char ** | _ArgV, | ||
| const PNotify & | _Notify = NULL  | 
        ||
| ) | 
| TEnv::TEnv | ( | const TStr & | _ArgStr, | 
| const PNotify & | _Notify = NULL  | 
        ||
| ) | 
| TStr TEnv::GetArg | ( | const int & | ArgN | ) |  const [inline] | 
        
Definition at line 28 of file env.h.
References ArgV, GetArgs(), and IAssert.
Referenced by GetArgPostfix(), GetCmLn(), GetExeFNm(), GetIfArgPrefixStrV(), GetPrefixArgN(), IsArgStr(), and PrepArgs().


| TStr TEnv::GetArgPostfix | ( | const TStr & | PrefixStr | ) | const | 
Definition at line 40 of file env.cpp.
References GetArg(), GetPrefixArgN(), TStr::GetSubStr(), IAssert, and TStr::Len().
Referenced by GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), and GetIfArgPrefixStr().
                                                    {
  int ArgN=GetPrefixArgN(PrefixStr); IAssert(ArgN!=-1);
  TStr ArgStr=GetArg(ArgN);
  return ArgStr.GetSubStr(PrefixStr.Len(), ArgStr.Len());
}


| int TEnv::GetArgs | ( | ) |  const [inline] | 
        
Definition at line 25 of file env.h.
References ArgV, and TVec< TVal, TSizeTy >::Len().
Referenced by GetArg(), GetCmLn(), GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), GetIfArgPrefixStr(), GetIfArgPrefixStrV(), GetPrefixArgN(), IsArgStr(), IsEndOfRun(), and PrepArgs().


| TStr TEnv::GetCmLn | ( | const int & | FromArgN = 1 | ) | const | 
| TStr TEnv::GetExeFNm | ( | ) | const | 
Definition at line 14 of file env.cpp.
References GetArg(), TStr::GetSubStr(), TStr::IsPrefix(), and TStr::Len().
Referenced by GetExeFPath().
                           {
  TStr ExeFNm=GetArg(0);
  if (ExeFNm.IsPrefix("//?")){ // observed on Win64 CGI
    ExeFNm=ExeFNm.GetSubStr(3, ExeFNm.Len());
  }
  return ExeFNm;
}


| TStr TEnv::GetExeFPath | ( | ) |  const [inline] | 
        
Definition at line 31 of file env.h.
References GetExeFNm(), and TStr::GetFPath().

| TStr TEnv::GetHdStr | ( | ) |  const [inline] | 
        
| bool TEnv::GetIfArgPrefixBool | ( | const TStr & | PrefixStr, | 
| const bool & | DfVal = false,  | 
        ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 178 of file env.cpp.
References TStr::CStr(), TStr::DelSubStr(), Env, GetArgPostfix(), GetArgs(), TBool::GetStr(), TBool::GetValFromStr(), TBool::GetYesNoStr(), IsArgPrefix(), TStr::LastCh(), TStr::Len(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
Referenced by PrepArgs().
                                                                  {
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s%s (default:'%s')\n",
       PrefixStr.CStr(), DNm.CStr(), TBool::GetStr(DfVal).CStr());}
    return DfVal;
  } else {
    // argument & value message
    bool Val;
    if ((PrefixStr.Len()>0)&&(PrefixStr.LastCh()==':')){
      if (Env.IsArgPrefix(PrefixStr)){
        // try to find one of boolean string value representations
        TStr ValStr=Env.GetArgPostfix(PrefixStr);
        Val=TBool::GetValFromStr(ValStr, DfVal);
      } else {
        // remove ':' and try to find option
        TStr RedPrefixStr=PrefixStr;
        RedPrefixStr.DelSubStr(PrefixStr.Len()-1, PrefixStr.Len()-1);
        if (Env.IsArgPrefix(RedPrefixStr)){Val=true;} else {Val=DfVal;}
      }
    } else {
      if (Env.IsArgPrefix(PrefixStr)){Val=true;} else {Val=DfVal;}
    }
    TStr MsgStr=DNm+" ("+PrefixStr+")="+TBool::GetYesNoStr(Val);
    if (!SilentP){TNotify::OnStatus(Notify, MsgStr);}
    return Val;
  }
}


| double TEnv::GetIfArgPrefixFlt | ( | const TStr & | PrefixStr, | 
| const double & | DfVal = 0,  | 
        ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 250 of file env.cpp.
References TStr::CStr(), Env, GetArgPostfix(), GetArgs(), TStr::GetFlt(), TFlt::GetStr(), IsArgPrefix(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
                                                                    {
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s%s (default:%g)\n", PrefixStr.CStr(), DNm.CStr(), DfVal);}
    return DfVal;
  } else {
    // argument & value message
    double Val;
    if (Env.IsArgPrefix(PrefixStr)){
      TStr ValStr=Env.GetArgPostfix(PrefixStr);
      Val=ValStr.GetFlt(DfVal);
    } else {
      Val=DfVal;
    }
    TStr MsgStr=DNm+" ("+PrefixStr+")="+TFlt::GetStr(Val);
    if (!SilentP){TNotify::OnStatus(Notify, MsgStr);}
    return Val;
  }
}

| int TEnv::GetIfArgPrefixInt | ( | const TStr & | PrefixStr, | 
| const int & | DfVal = 0,  | 
        ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 209 of file env.cpp.
References TStr::CStr(), Env, GetArgPostfix(), GetArgs(), TStr::GetInt(), TInt::GetStr(), IsArgPrefix(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
                                                                 {
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s%s (default:%d)\n", PrefixStr.CStr(), DNm.CStr(), DfVal);}
    return DfVal;
  } else {
    // argument & value message
    int Val;
    if (Env.IsArgPrefix(PrefixStr)){
      TStr ValStr=Env.GetArgPostfix(PrefixStr);
      Val=ValStr.GetInt(DfVal);
    } else {
      Val=DfVal;
    }
    TStr MsgStr=DNm+" ("+PrefixStr+")="+TInt::GetStr(Val);
    if (!SilentP){TNotify::OnStatus(Notify, MsgStr);}
    return Val;
  }
}

| TIntV TEnv::GetIfArgPrefixIntV | ( | const TStr & | PrefixStr, | 
| TIntV & | DfValV, | ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 231 of file env.cpp.
References TVec< TVal, TSizeTy >::Add(), GetIfArgPrefixStrV(), TInt::GetStr(), and TVec< TVal, TSizeTy >::Len().
Referenced by GetIfArgPrefixIntV().
                                                              {
  // convert default-integer-values to default-string-values
  TStrV DfValStrV;
  for (int ValN=0; ValN<DfValV.Len(); ValN++){
    DfValStrV.Add(TInt::GetStr(DfValV[ValN]));}
  // get string-values
  TStrV ValStrV=GetIfArgPrefixStrV(PrefixStr, DfValStrV, DNm);
  // convert string-values to integer-values
  TIntV ValV;
  for (int ValN=0; ValN<ValStrV.Len(); ValN++){
    int Val;
    if (ValStrV[ValN].IsInt(Val)){
      ValV.Add(Val);}
  }
  // return value-vector
  return ValV;
}


| TIntV TEnv::GetIfArgPrefixIntV | ( | const TStr & | PrefixStr, | 
| const TStr & | DNm = ""  | 
        ||
| ) |  const [inline] | 
        
Definition at line 62 of file env.h.
References GetIfArgPrefixIntV().
                                                                            {
    TIntV DfValV; return GetIfArgPrefixIntV(PrefixStr, DfValV, DNm);}

| TStr TEnv::GetIfArgPrefixStr | ( | const TStr & | PrefixStr, | 
| const TStr & | DfVal = "",  | 
        ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 110 of file env.cpp.
References TStr::CStr(), Env, GetArgPostfix(), GetArgs(), TStr::GetSubStr(), IsArgPrefix(), TStr::LastCh(), TStr::Len(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
                                                                  {
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s%s (default:'%s')\n", PrefixStr.CStr(), DNm.CStr(), DfVal.CStr());}
    return DfVal;
  } else {
    // argument & value message
    TStr Val;
    if (Env.IsArgPrefix(PrefixStr)){
      Val=Env.GetArgPostfix(PrefixStr);
      if (Val.Len()>1){
        if ((Val[0]=='\"')&&(Val.LastCh()=='\"')){
          Val=Val.GetSubStr(1, Val.Len()-2);
        }
      }
    } else {
      Val=DfVal;
    }
    TStr MsgStr=DNm+" ("+PrefixStr+")="+Val;
    if (!SilentP){TNotify::OnStatus(Notify, MsgStr);}
    return Val;
  }
}

| TStrSet TEnv::GetIfArgPrefixStrSet | ( | const TStr & | PrefixStr, | 
| TStrV & | DfValV, | ||
| const TStr & | DNm = ""  | 
        ||
| ) |  const [inline] | 
        
Definition at line 55 of file env.h.
References GetIfArgPrefixStrV().
                                                                                               {
    return TStrSet(GetIfArgPrefixStrV(PrefixStr, DfValV, DNm));}

| TStrSet TEnv::GetIfArgPrefixStrSet | ( | const TStr & | PrefixStr, | 
| const TStr & | DNm = ""  | 
        ||
| ) |  const [inline] | 
        
Definition at line 57 of file env.h.
References GetIfArgPrefixStrV().
                                                                                {
    return TStrSet(GetIfArgPrefixStrV(PrefixStr, DNm));}

| TStrV TEnv::GetIfArgPrefixStrV | ( | const TStr & | PrefixStr, | 
| TStrV & | DfValV, | ||
| const TStr & | DNm = ""  | 
        ||
| ) | const | 
Definition at line 136 of file env.cpp.
References TVec< TVal, TSizeTy >::Add(), TStr::CStr(), TVec< TVal, TSizeTy >::Empty(), Env, GetArg(), GetArgs(), TStr::GetSubStr(), TVec< TVal, TSizeTy >::Last(), TStr::Len(), TVec< TVal, TSizeTy >::Len(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
Referenced by GetIfArgPrefixIntV(), GetIfArgPrefixStrSet(), and GetIfArgPrefixStrV().
                                                              {
  TStrV ArgValV;
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s%s (default:", PrefixStr.CStr(), DNm.CStr());
      for (int DfValN=0; DfValN<DfValV.Len(); DfValN++){
        if (DfValN>0){printf(", ");}
        printf("'%s'", DfValV[DfValN].CStr());
      }
      printf(")\n");
    }
    return ArgValV;
  } else {
    // argument & value message
    TStr ArgValVChA;
    for (int ArgN=0; ArgN<GetArgs(); ArgN++){
      // get argument string
      TStr ArgStr=GetArg(ArgN);
      if (ArgStr.GetSubStr(0, PrefixStr.Len()-1)==PrefixStr){
        // extract & add argument value
        TStr ArgVal=ArgStr.GetSubStr(PrefixStr.Len(), ArgStr.Len());
        ArgValV.Add(ArgVal);
        // add to message string
        if (ArgValV.Len()>1){ArgValVChA+=", ";}
        ArgValVChA+=ArgValV.Last();
      }
    }
    if (ArgValV.Empty()){ArgValV=DfValV;}
    // output argument values
    TChA MsgChA;
    MsgChA+=DNm; MsgChA+=" ("; MsgChA+=PrefixStr; MsgChA+=")=";
    for (int ArgValN=0; ArgValN<ArgValV.Len(); ArgValN++){
      if (ArgValN>0){MsgChA+=", ";}
      MsgChA+="'"; MsgChA+=ArgValV[ArgValN]; MsgChA+="'";
    }
    if (!SilentP){TNotify::OnStatus(Notify, MsgChA);}
    return ArgValV;
  }
}


| TStrV TEnv::GetIfArgPrefixStrV | ( | const TStr & | PrefixStr, | 
| const TStr & | DNm = ""  | 
        ||
| ) |  const [inline] | 
        
Definition at line 53 of file env.h.
References GetIfArgPrefixStrV().
                                                                            {
    TStrV DfValV; return GetIfArgPrefixStrV(PrefixStr, DfValV, DNm);}

| int TEnv::GetMnArgs | ( | ) |  const [inline] | 
        
| int TEnv::GetPrefixArgN | ( | const TStr & | PrefixStr | ) | const | 
Definition at line 31 of file env.cpp.
References GetArg(), GetArgs(), and TStr::Len().
Referenced by GetArgPostfix(), and IsArgPrefix().
                                                   {
  int ArgN=0;
  while (ArgN<GetArgs()){
    if (GetArg(ArgN).GetSubStr(0, PrefixStr.Len()-1)==PrefixStr){return ArgN;}
    ArgN++;
  }
  return -1;
}


| void TEnv::GetVarNmV | ( | TStrV & | VarNmV | ) | 
Definition at line 272 of file env.cpp.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), and TStr::SplitOnCh().
                                 {
  VarNmV.Clr(); int VarN=0;
  while (_environ[VarN]!=NULL){
    TStr VarNmVal=_environ[VarN++];
    TStr VarNm; TStr VarVal; VarNmVal.SplitOnCh(VarNm, '=', VarVal);
    VarNmV.Add(VarNm);
  }
}

| void TEnv::GetVarNmValV | ( | TStrV & | NmValV | ) | 
Definition at line 281 of file env.cpp.
References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Clr().
                                       {
  VarNmValV.Clr(); int VarN=0;
  while (_environ[VarN]!=NULL){
    VarNmValV.Add(_environ[VarN++]);
  }
}

| TStr TEnv::GetVarVal | ( | const TStr & | VarNm | ) | const | 
Definition at line 293 of file env.cpp.
References TStr::CStr().

| bool TEnv::IsArgPrefix | ( | const TStr & | PrefixStr | ) |  const [inline] | 
        
Definition at line 37 of file env.h.
References GetPrefixArgN().
Referenced by GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), and GetIfArgPrefixStr().
                                                {
    return GetPrefixArgN(PrefixStr)!=-1;}


| bool TEnv::IsArgStr | ( | const TStr & | ArgStr | ) | 
| bool TEnv::IsArgStr | ( | const TStr & | ArgStr, | 
| const TStr & | DNm | ||
| ) | 
Definition at line 95 of file env.cpp.
References TStr::CStr(), Env, GetArgs(), IsArgStr(), MnArgs, Notify, TNotify::OnStatus(), and SilentP.
                                                       {
  if (Env.GetArgs()<=MnArgs){
    // 'usage' argument message
    if (!SilentP){
      printf("   %s %s \n", ArgStr.CStr(), DNm.CStr());}
    return false;
  } else {
    // argument & value message
    bool Val=Env.IsArgStr(ArgStr);
    TStr MsgStr=DNm+" ("+ArgStr+(Val?")=YES":")=NO");
    if (!SilentP){TNotify::OnStatus(Notify, MsgStr);}
    return Val;
  }
}

| bool TEnv::IsEndOfRun | ( | ) | const | 
Definition at line 72 of file env.cpp.
References TStr::Empty(), Env, GetArgs(), HdStr, TStr::Len(), MnArgs, and SilentP.
                            {
  if (!SilentP){
    // print line in length of header-line
    if (HdStr.Empty()){
      printf("========================================\n");
    } else {
      for (int ChN=0; ChN<HdStr.Len(); ChN++){printf("=");}
      printf("\n");
    }
  }
  // return
  return Env.GetArgs()<=MnArgs;
}

| bool TEnv::IsSilent | ( | ) |  const [inline] | 
        
| void TEnv::PrepArgs | ( | const TStr & | _HdStr = TStr(),  | 
        
| const int & | _MnArgs = 1,  | 
        ||
| const bool & | SilentP = false  | 
        ||
| ) | 
Definition at line 46 of file env.cpp.
References TStr::CStr(), TStr::Empty(), Env, GetArg(), GetArgs(), TStr::GetFBase(), GetIfArgPrefixBool(), HdStr, TStr::Len(), MnArgs, and SilentP.
                                                                               {
  // put environment state
  HdStr=_HdStr;
  MnArgs=_MnArgs;
  // silence
  SilentP=true;
  SilentP=Env.GetIfArgPrefixBool("-silent:", false, "Silence");
  // start header
  if (!SilentP){
    // print header
    if (!HdStr.Empty()){
      // print header-string
      TStr DateStr=__DATE__;
      printf("%s [%s]\n", HdStr.CStr(), DateStr.CStr());
      // print header-line
      for (int ChN=0; ChN<HdStr.Len()+DateStr.Len()+3; ChN++){printf("=");}
      printf("\n");
    }
    // print start of 'usage' message if not enough arguments
    if (Env.GetArgs()<=MnArgs){
      TStr ExeFNm=Env.GetArg(0).GetFBase();
      printf("usage: %s\n", ExeFNm.CStr());
    }
  }
}

| void TEnv::PutVarVal | ( | const TStr & | VarNm, | 
| const TStr & | VarVal | ||
| ) |  [static] | 
        
Definition at line 288 of file env.cpp.
References TStr::CStr(), TStr::Fmt(), and IAssert.
                                                          {
  const int RetVal = putenv(TStr::Fmt("%s=%s", VarNm.CStr(), VarVal.CStr()).CStr());
  IAssert(RetVal==0);
}

TStrV TEnv::ArgV [private] | 
        
TStr TEnv::HdStr [private] | 
        
Definition at line 8 of file env.h.
Referenced by GetHdStr(), IsEndOfRun(), operator=(), and PrepArgs().
int TEnv::MnArgs [private] | 
        
Definition at line 9 of file env.h.
Referenced by GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), GetIfArgPrefixStr(), GetIfArgPrefixStrV(), GetMnArgs(), IsArgStr(), IsEndOfRun(), operator=(), and PrepArgs().
PNotify TEnv::Notify [private] | 
        
Definition at line 11 of file env.h.
Referenced by GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), GetIfArgPrefixStr(), GetIfArgPrefixStrV(), IsArgStr(), and operator=().
bool TEnv::SilentP [private] | 
        
Definition at line 10 of file env.h.
Referenced by GetIfArgPrefixBool(), GetIfArgPrefixFlt(), GetIfArgPrefixInt(), GetIfArgPrefixStr(), GetIfArgPrefixStrV(), IsArgStr(), IsEndOfRun(), IsSilent(), operator=(), and PrepArgs().