SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
env.h
Go to the documentation of this file.
1 // Environment
3 class TEnv{
4 private:
5  //int Args;
6  //char** ArgV;
9  int MnArgs;
10  bool SilentP;
12 public:
13  TEnv(): /*Args(0), ArgV(NULL)*/ ArgV(), HdStr(), MnArgs(1), SilentP(false), Notify(){}
14  TEnv(const TEnv&);
15  TEnv(const int& _Args, char** _ArgV, const PNotify& _Notify=NULL);
16  //Args(_Args), ArgV(_ArgV), HdStr(), MnArgs(1), SilentP(false), Notify(_Notify){}
17  TEnv(const TStr& _ArgStr, const PNotify& _Notify=NULL);
18 
19  TEnv& operator=(const TEnv& Env){
20  /*Args=Env.Args;*/ ArgV=Env.ArgV; HdStr=Env.HdStr;
21  MnArgs=Env.MnArgs; SilentP=Env.SilentP; Notify=Env.Notify; return *this;}
22 
23  // basic arguments & command line
24  //int GetArgs() const {return Args;}
25  int GetArgs() const {return ArgV.Len();}
26  //TStr GetArg(const int& ArgN) const {
27  // IAssert((0<=ArgN)&&(ArgN<Args)); return TStr(ArgV[ArgN]);}
28  TStr GetArg(const int& ArgN) const {
29  IAssert((0<=ArgN)&&(ArgN<GetArgs())); return ArgV[ArgN];}
30  TStr GetExeFNm() const;
31  TStr GetExeFPath() const {return GetExeFNm().GetFPath();}
32  TStr GetCmLn(const int& FromArgN=1) const;
33  bool IsSilent() const {return SilentP;}
34 
35  // arguments prefix & postfix
36  int GetPrefixArgN(const TStr& PrefixStr) const;
37  bool IsArgPrefix(const TStr& PrefixStr) const {
38  return GetPrefixArgN(PrefixStr)!=-1;}
39  TStr GetArgPostfix(const TStr& PrefixStr) const;
40 
41  // top level arguments handling
42  void PrepArgs(
43  const TStr& _HdStr=TStr(), const int& _MnArgs=1, const bool& SilentP=false);
44  TStr GetHdStr() const {return HdStr;}
45  int GetMnArgs() const {return MnArgs;}
46  bool IsEndOfRun() const;
47 
48  // arguments value retrieval
49  bool IsArgStr(const TStr& ArgStr);
50  bool IsArgStr(const TStr& ArgStr, const TStr& DNm);
51  TStr GetIfArgPrefixStr(const TStr& PrefixStr, const TStr& DfVal="", const TStr& DNm="") const;
52  TStrV GetIfArgPrefixStrV(const TStr& PrefixStr, TStrV& DfValV, const TStr& DNm="") const;
53  TStrV GetIfArgPrefixStrV(const TStr& PrefixStr, const TStr& DNm="") const {
54  TStrV DfValV; return GetIfArgPrefixStrV(PrefixStr, DfValV, DNm);}
55  TStrSet GetIfArgPrefixStrSet(const TStr& PrefixStr, TStrV& DfValV, const TStr& DNm="") const {
56  return TStrSet(GetIfArgPrefixStrV(PrefixStr, DfValV, DNm));}
57  TStrSet GetIfArgPrefixStrSet(const TStr& PrefixStr, const TStr& DNm="") const {
58  return TStrSet(GetIfArgPrefixStrV(PrefixStr, DNm));}
59  bool GetIfArgPrefixBool(const TStr& PrefixStr, const bool& DfVal=false, const TStr& DNm="") const;
60  int GetIfArgPrefixInt(const TStr& PrefixStr, const int& DfVal=0, const TStr& DNm="") const;
61  TIntV GetIfArgPrefixIntV(const TStr& PrefixStr, TIntV& DfValV, const TStr& DNm="") const;
62  TIntV GetIfArgPrefixIntV(const TStr& PrefixStr, const TStr& DNm="") const {
63  TIntV DfValV; return GetIfArgPrefixIntV(PrefixStr, DfValV, DNm);}
64  double GetIfArgPrefixFlt(const TStr& PrefixStr, const double& DfVal=0, const TStr& DNm="") const;
65 
66  // environment variables
67  static void PutVarVal(const TStr& VarNm, const TStr& VarVal);
68  TStr GetVarVal(const TStr& VarNm) const;
69  void GetVarNmV(TStrV& VarNmV);
70  void GetVarNmValV(TStrV& NmValV);
71 };
72 
73 extern TEnv Env;
74 
int GetIfArgPrefixInt(const TStr &PrefixStr, const int &DfVal=0, const TStr &DNm="") const
Definition: env.cpp:209
#define IAssert(Cond)
Definition: bd.h:262
void GetVarNmV(TStrV &VarNmV)
Definition: env.cpp:272
TStr GetIfArgPrefixStr(const TStr &PrefixStr, const TStr &DfVal="", const TStr &DNm="") const
Definition: env.cpp:110
bool SilentP
Definition: env.h:10
TStrSet GetIfArgPrefixStrSet(const TStr &PrefixStr, const TStr &DNm="") const
Definition: env.h:57
TStrSet GetIfArgPrefixStrSet(const TStr &PrefixStr, TStrV &DfValV, const TStr &DNm="") const
Definition: env.h:55
TStr GetFPath() const
Definition: dt.cpp:1389
TIntV GetIfArgPrefixIntV(const TStr &PrefixStr, const TStr &DNm="") const
Definition: env.h:62
TEnv & operator=(const TEnv &Env)
Definition: env.h:19
TStrV GetIfArgPrefixStrV(const TStr &PrefixStr, const TStr &DNm="") const
Definition: env.h:53
TStr GetHdStr() const
Definition: env.h:44
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: env.h:3
bool IsEndOfRun() const
Definition: env.cpp:72
void GetVarNmValV(TStrV &NmValV)
Definition: env.cpp:281
TIntV GetIfArgPrefixIntV(const TStr &PrefixStr, TIntV &DfValV, const TStr &DNm="") const
Definition: env.cpp:231
int GetPrefixArgN(const TStr &PrefixStr) const
Definition: env.cpp:31
int GetMnArgs() const
Definition: env.h:45
TStr HdStr
Definition: env.h:8
TStr GetCmLn(const int &FromArgN=1) const
Definition: env.cpp:22
int MnArgs
Definition: env.h:9
TEnv Env
Definition: env.cpp:297
TStr GetExeFNm() const
Definition: env.cpp:14
TStrV GetIfArgPrefixStrV(const TStr &PrefixStr, TStrV &DfValV, const TStr &DNm="") const
Definition: env.cpp:136
bool IsArgStr(const TStr &ArgStr)
Definition: env.cpp:86
double GetIfArgPrefixFlt(const TStr &PrefixStr, const double &DfVal=0, const TStr &DNm="") const
Definition: env.cpp:250
bool IsSilent() const
Definition: env.h:33
THashSet< TStr > TStrSet
Definition: shash.h:1385
bool IsArgPrefix(const TStr &PrefixStr) const
Definition: env.h:37
void PrepArgs(const TStr &_HdStr=TStr(), const int &_MnArgs=1, const bool &SilentP=false)
Definition: env.cpp:46
bool GetIfArgPrefixBool(const TStr &PrefixStr, const bool &DfVal=false, const TStr &DNm="") const
Definition: env.cpp:178
TStr GetArgPostfix(const TStr &PrefixStr) const
Definition: env.cpp:40
TStr GetVarVal(const TStr &VarNm) const
Definition: env.cpp:293
TStrV ArgV
Definition: env.h:7
TEnv()
Definition: env.h:13
Definition: dt.h:412
PNotify Notify
Definition: env.h:11
static void PutVarVal(const TStr &VarNm, const TStr &VarVal)
Definition: env.cpp:288
int GetArgs() const
Definition: env.h:25
TStr GetExeFPath() const
Definition: env.h:31
TStr GetArg(const int &ArgN) const
Definition: env.h:28