00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef __HELPER_H
00040 #define __HELPER_H
00041
00042 #include <string>
00043 #include <list>
00044 #include <cassert>
00045 #include <ctime>
00046 #include <ostream>
00047 #include <cstdio>
00048 #include <iomanip>
00049 #include <cassert>
00050 #include <ostream>
00051 #include <sstream>
00052 #include <iostream>
00053 #include <sys/types.h>
00054 #include <sys/stat.h>
00055 #include <sys/timeb.h>
00056
00057 #ifdef WIN32
00058 #define WIN32_LEAN_AND_MEAN
00059 #include <windows.h>
00060 #else
00061 #include <unistd.h>
00062 #include <stdlib.h>
00063 #endif
00064
00065 using std::list;
00066 using std::string;
00067 using std::setfill;
00068 using std::setw;
00069 using std::cout;
00070 using std::string;
00071 using std::ostream;
00072 using std::ostringstream;
00073
00074 namespace ariba {
00075 namespace utility {
00076
00077 namespace Helper {
00078
00079
00080
00081
00082
00084 string ultos(unsigned long val);
00085
00087 template<class T>
00088 string ptos(T pnt) {
00089 std::ostringstream oss;
00090 oss << "0x" << std::hex << pnt;
00091 return oss.str();
00092 }
00093
00095 string ltos(long val);
00096
00098 string ultohexs(unsigned long val, bool hexdelimiter = true);
00099
00101 string ltohexs(long val, bool hexdelimiter = true);
00102
00104 long stol(string str);
00105
00107 int stoi(string str);
00108
00110 double stod(string str);
00111
00113 unsigned int hstoui(string str);
00114
00116 string dtos(double val);
00117
00118
00119
00120
00121
00123 string trim(string str);
00124
00127 typedef list<string> STRING_LIST;
00128 typedef STRING_LIST::iterator STRING_LIST_ITERATOR;
00129 STRING_LIST split(string str, string delimiter);
00130
00132 string replace(string str, string find, string repl);
00133
00134
00135
00136
00137
00138 string getTime(time_t timeval = 0);
00139 string getDate(time_t timeval = 0);
00140 unsigned long getElapsedMillis();
00141 void sleep(unsigned int millis);
00142
00143
00144
00145
00146
00147 #ifdef WIN32
00148 const string LINE_BREAK = "\r\n";
00149 #else
00150 const string LINE_BREAK = "\n";
00151 #endif
00152
00153 };
00154
00155 inline void Helper::sleep(unsigned int millis) {
00156 #ifdef WIN32
00157 Sleep (millis);
00158 #else
00159
00160 unsigned long secondsSleep = millis / 1000;
00161 unsigned long millisSleep = millis % 1000;
00162
00163
00164
00165
00166
00167
00168
00169 if (secondsSleep > 0)
00170 sleep(secondsSleep);
00171
00172
00173
00174
00175
00176 if (millisSleep > 0) {
00177 assert (millisSleep < 1000);
00178 usleep(millisSleep * 1000);
00179 }
00180 #endif
00181 }
00182
00183 }}
00184
00185 #endif // __HELPER_H