SNAP Library, Developer Reference
2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
|
00001 #ifdef GLib_WIN 00002 00003 // Com 00004 class TCom{ 00005 public: 00006 TCom(){ 00007 /*EAssertR(::CoInitialize(NULL)==S_OK, "COM initialization failed.");*/} 00008 ~TCom(){/*CoUninitialize();*/} 00009 }; 00010 00012 // System-Processes 00013 class TSysProc{ 00014 public: 00015 static void Sleep(const uint& MSecs); 00016 static TStr GetExeFNm(); 00017 static void SetLowPriority(); 00018 static bool ExeProc(const TStr& ExeFNm, TStr& ParamStr); 00019 }; 00020 00022 // System-Memory-Status 00023 ClassTP(TSysMemStat, PSysMemStat)//{ 00024 private: 00025 MEMORYSTATUSEX MemStat; 00026 public: 00027 TSysMemStat(){Refresh();} 00028 ~TSysMemStat(){} 00029 TSysMemStat(TSIn&){Fail;} 00030 static TPt<TSysMemStat> Load(TSIn&){Fail; return NULL;} 00031 void Save(TSOut&){Fail;} 00032 00033 TSysMemStat& operator=(const TSysMemStat&){Fail; return *this;} 00034 00035 void Refresh(){ 00036 MemStat.dwLength=sizeof(MEMORYSTATUSEX); 00037 GlobalMemoryStatusEx(&MemStat);} 00038 00039 uint64 GetLoad(){ // percent of memory in use 00040 return uint64(MemStat.dwMemoryLoad);} 00041 uint64 GetTotalPhys(){ // bytes of physical memory 00042 return uint64(MemStat.ullTotalPhys);} 00043 uint64 GetAvailPhys(){ // free physical memory bytes 00044 return uint64(MemStat.ullAvailPhys);} 00045 uint64 GetTotalPageFile(){ // bytes of paging file 00046 return uint64(MemStat.ullTotalPageFile);} 00047 uint64 GetAvailPageFile(){ // free bytes of paging file 00048 return uint64(MemStat.ullAvailPageFile);} 00049 uint64 GetTotalVirtual(){ // user bytes of address space 00050 return uint64(MemStat.ullTotalVirtual);} 00051 uint64 GetAvailVirtual(){ // free user bytes 00052 return uint64(MemStat.ullAvailVirtual);} 00053 00054 TStr GetLoadStr(); 00055 TStr GetUsageStr(); 00056 TStr GetInfoStr(); 00057 TStr GetStr(); 00058 00059 static bool Is32Bit(){return sizeof(char*)==4;} 00060 static bool Is64Bit(){return sizeof(char*)==8;} 00061 }; 00062 00064 // System-Console 00065 ClassTP(TSysConsole, PSysConsole)//{ 00066 private: 00067 bool Ok; 00068 HANDLE hStdOut; 00069 public: 00070 TSysConsole(); 00071 static PSysConsole New(){return PSysConsole(new TSysConsole());} 00072 ~TSysConsole(); 00073 TSysConsole(TSIn&){Fail;} 00074 static PSysConsole Load(TSIn&){Fail; return NULL;} 00075 void Save(TSOut&){Fail;} 00076 00077 TSysConsole& operator=(const TSysConsole&){Fail; return *this;} 00078 00079 void Put(const TStr& Str); 00080 void PutLn(const TStr& Str){ 00081 Put(Str); Put("\r\n");} 00082 00083 static void OpenFile(const TStr& FNm){ 00084 ShellExecute(0, "open", FNm.CStr(), "", "", SW_SHOWNORMAL);} 00085 }; 00086 00088 // System-Console-Notifier 00089 class TSysConsoleNotify: public TNotify{ 00090 private: 00091 PSysConsole SysConsole; 00092 public: 00093 TSysConsoleNotify(const PSysConsole& _SysConsole): 00094 SysConsole(_SysConsole){} 00095 static PNotify New(const PSysConsole& _SysConsole){ 00096 return PNotify(new TSysConsoleNotify(_SysConsole));} 00097 00098 void OnNotify(const TNotifyType& Type, const TStr& MsgStr); 00099 void OnStatus(const TStr& MsgStr); 00100 }; 00101 00103 // System-Messages 00104 class TSysMsg{ 00105 public: 00106 static void Loop(); 00107 static void Quit(); 00108 }; 00109 00111 // System-Time 00112 class TSysTm{ 00113 public: 00114 static TTm GetCurUniTm(); 00115 static TTm GetCurLocTm(); 00116 static uint64 GetCurUniMSecs(); 00117 static uint64 GetCurLocMSecs(); 00118 static uint64 GetMSecsFromTm(const TTm& Tm); 00119 static TTm GetTmFromMSecs(const uint64& MSecs); 00120 static uint GetMSecsFromOsStart(); 00121 00122 static TTm GetLocTmFromUniTm(const TTm& Tm); 00123 static TTm GetUniTmFromLocTm(const TTm& Tm); 00124 00125 static uint64 GetProcessMSecs(); 00126 static uint64 GetThreadMSecs(); 00127 00128 static uint64 GetPerfTimerFq(); 00129 static uint64 GetPerfTimerTicks(); 00130 }; 00131 00133 // System-Strings 00134 class TSysStr{ 00135 public: 00136 static TStr GetCmLn(); 00137 static TStr GetMsgStr(const DWORD& MsgCd); 00138 static TStr GetLastMsgStr(){return GetMsgStr(GetLastError());} 00139 static char* GetLastMsgCStr(); 00140 00141 static BSTR NewBStr(const TStr& Str){ 00142 return SysAllocStringByteLen(Str.CStr(), Str.Len());} 00143 static TStr DelBStr(BSTR& BStr){ 00144 TStr Str=(char*)BStr; SysFreeString(BStr); BStr=NULL; return Str;} 00145 }; 00146 00148 // Registry-Key 00149 ClassTP(TRegKey, PRegKey)//{ 00150 private: 00151 bool Ok; 00152 HKEY hKey; 00153 void UndefCopyAssgin(TRegKey); 00154 private: 00155 TRegKey(): Ok(false), hKey(0){} 00156 TRegKey(const bool& _Ok, const HKEY& _hKey): Ok(_Ok), hKey(_hKey){} 00157 ~TRegKey(){if (Ok){RegCloseKey(hKey);}} 00158 00159 HKEY GetHandle() const {return hKey;} 00160 public: 00161 static PRegKey GetKey(const PRegKey& Key, const TStr& SubKeyNm); 00162 static TStr GetVal(const PRegKey& Key, const TStr& SubKeyNm, const TStr& ValNm); 00163 static PRegKey GetClassesRootKey(){return new TRegKey(true, HKEY_CLASSES_ROOT);} 00164 static PRegKey GetCurrentUserKey(){return new TRegKey(true, HKEY_CURRENT_USER);} 00165 static PRegKey GetLocalMachineKey(){return new TRegKey(true, HKEY_LOCAL_MACHINE);} 00166 static PRegKey GetUsersKey(){return new TRegKey(true, HKEY_USERS);} 00167 00168 bool IsOk() const {return Ok;} 00169 void GetKeyNmV(TStrV& KeyNmV) const; 00170 void GetValV(TStrKdV& ValNmStrKdV) const; 00171 }; 00172 00174 // Program StdIn and StdOut redirection using pipes 00175 class TStdIOPipe { 00176 private: 00177 HANDLE ChildStdinRd, ChildStdinWrDup; 00178 HANDLE ChildStdoutWr, ChildStdoutRdDup; 00179 void CreateProc(const TStr& Cmd); 00180 private: 00181 UndefDefaultCopyAssign(TStdIOPipe); 00182 public: 00183 TStdIOPipe(const TStr& CmdToExe); 00184 ~TStdIOPipe(); 00185 00186 int Write(const char* Bf) { return Write(Bf, (int) strlen(Bf)); } 00187 int Write(const char* Bf, const int& BfLen); 00188 int Read(char *Bf, const int& BfMxLen); 00189 }; 00190 00192 // GUID 00193 class TGuid { 00194 public: 00195 static TStr GenGuid(); 00196 }; 00197 00198 #elif defined(GLib_UNIX) 00199 00201 // Compatibility functions 00202 00203 int GetModuleFileName(void *hModule, char *Bf, int MxBfL); 00204 int GetCurrentDirectory(const int MxBfL, char *Bf); 00205 int CreateDirectory(const char *FNm, void *useless); 00206 int RemoveDirectory(const char *FNm); 00207 uint64 Epoch2Ft(time_t Epoch); 00208 time_t Ft2Epoch(uint64 Ft); 00209 00211 // System-Processes 00212 class TSysProc{ 00213 public: 00214 static int Sleep(const uint& MSecs); 00215 static TStr GetExeFNm(); 00216 static void SetLowPriority(); 00217 static bool ExeProc(const TStr& ExeFNm, TStr& ParamStr); 00218 }; 00219 00221 // System-Messages 00222 class TSysMsg{ 00223 public: 00224 static void Loop(); 00225 static void Quit(); 00226 }; 00227 00229 // System-Time 00230 class TSysTm{ 00231 public: 00232 static TTm GetCurUniTm(); 00233 static TTm GetCurLocTm(); 00234 static uint64 GetCurUniMSecs(); 00235 static uint64 GetCurLocMSecs(); 00236 static uint64 GetMSecsFromTm(const TTm& Tm); 00237 static TTm GetTmFromMSecs(const uint64& MSecs); 00238 static uint GetMSecsFromOsStart(); 00239 00240 static TTm GetLocTmFromUniTm(const TTm& Tm); 00241 static TTm GetUniTmFromLocTm(const TTm& Tm); 00242 00243 static uint64 GetProcessMSecs(); 00244 static uint64 GetThreadMSecs(); 00245 00246 static uint64 GetPerfTimerFq(); 00247 static uint64 GetPerfTimerTicks(); 00248 }; 00249 00251 // Program StdIn and StdOut redirection using pipes 00252 // J: not yet ported to Linux 00253 class TStdIOPipe { 00254 private: 00255 int ChildStdinRd, ChildStdinWrDup; 00256 int ChildStdoutWr, ChildStdoutRdDup; 00257 void CreateProc(const TStr& Cmd); 00258 private: 00259 UndefDefaultCopyAssign(TStdIOPipe); 00260 public: 00261 TStdIOPipe(const TStr& CmdToExe); 00262 ~TStdIOPipe(); 00263 00264 int Write(const char* Bf) { return Write(Bf, (int) strlen(Bf)); } 00265 int Write(const char* Bf, const int& BfLen); 00266 int Read(char *Bf, const int& BfMxLen); 00267 }; 00268 00269 00271 // GUID 00272 class TGuid { 00273 public: 00274 static TStr GenGuid(); 00275 }; 00276 00277 00278 #endif