SNAP Library , User Reference
2013-01-07 14:03:36
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) |
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 |
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] |
TStr TEnv::GetArgPostfix | ( | const TStr & | PrefixStr | ) | const |
int TEnv::GetArgs | ( | ) | const [inline] |
TStr TEnv::GetCmLn | ( | const int & | FromArgN = 1 | ) | const |
TStr TEnv::GetExeFNm | ( | ) | const |
TStr TEnv::GetExeFPath | ( | ) | const [inline] |
TStr TEnv::GetHdStr | ( | ) | const [inline] |
bool TEnv::GetIfArgPrefixBool | ( | const TStr & | PrefixStr, |
const bool & | DfVal = false , |
||
const TStr & | DNm = "" |
||
) | const |
Definition at line 163 of file env.cpp.
{ 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 235 of file env.cpp.
{ 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 194 of file env.cpp.
{ 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 216 of file env.cpp.
{ // 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.
{ TIntV DfValV; return GetIfArgPrefixIntV(PrefixStr, DfValV, DNm);}
TStr TEnv::GetIfArgPrefixStr | ( | const TStr & | PrefixStr, |
const TStr & | DfVal = "" , |
||
const TStr & | DNm = "" |
||
) | const |
Definition at line 95 of file env.cpp.
{ 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; } }
TStrV TEnv::GetIfArgPrefixStrV | ( | const TStr & | PrefixStr, |
TStrV & | DfValV, | ||
const TStr & | DNm = "" |
||
) | const |
Definition at line 121 of file env.cpp.
{ 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 54 of file env.h.
{ TStrV DfValV; return GetIfArgPrefixStrV(PrefixStr, DfValV, DNm);}
int TEnv::GetMnArgs | ( | ) | const [inline] |
int TEnv::GetPrefixArgN | ( | const TStr & | PrefixStr | ) | const |
void TEnv::GetVarNmV | ( | TStrV & | VarNmV | ) |
void TEnv::GetVarNmValV | ( | TStrV & | NmValV | ) |
TStr TEnv::GetVarVal | ( | const TStr & | VarNm | ) | const |
bool TEnv::IsArgPrefix | ( | const TStr & | PrefixStr | ) | const [inline] |
Definition at line 37 of file env.h.
{ return GetPrefixArgN(PrefixStr)!=-1;}
bool TEnv::IsArgStr | ( | const TStr & | ArgStr | ) |
bool TEnv::IsEndOfRun | ( | ) | const |
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.
{ // 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] |
TStrV TEnv::ArgV [private] |
TStr TEnv::HdStr [private] |
int TEnv::MnArgs [private] |
PNotify TEnv::Notify [private] |
bool TEnv::SilentP [private] |