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