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 <iomanip>
00048 #include <cassert>
00049 #include <ostream>
00050 #include <sstream>
00051 #include <iostream>
00052 #include <sys/types.h>
00053 #include <sys/stat.h>
00054 #include <sys/timeb.h>
00055 #include <boost/lexical_cast.hpp>
00056 #include <boost/algorithm/string/replace.hpp>
00057
00058 #ifdef WIN32
00059 #define WIN32_LEAN_AND_MEAN
00060 #include <windows.h>
00061 #else
00062 #include <unistd.h>
00063 #include <stdlib.h>
00064 #endif
00065
00066 using std::list;
00067 using std::string;
00068 using std::setfill;
00069 using std::setw;
00070 using std::cout;
00071 using std::string;
00072 using std::ostream;
00073 using std::ostringstream;
00074
00075 namespace ariba {
00076 namespace utility {
00077
00078 namespace Helper {
00079
00080
00081
00082
00083
00085 string ultos(unsigned long val);
00086
00088 template<class T>
00089 string ptos(T pnt) {
00090 std::ostringstream oss;
00091 oss << "0x" << std::hex << pnt;
00092 return oss.str();
00093 }
00094
00096 string ltos(long val);
00097
00099 string ultohexs(unsigned long val, bool hexdelimiter = true);
00100
00102 string ltohexs(long val, bool hexdelimiter = true);
00103
00105 long stol(string str);
00106
00108 int stoi(string str);
00109
00111 double stod(string str);
00112
00114 unsigned int hstoui(string str);
00115
00117 string dtos(double val);
00118
00119
00120
00121
00122
00124 string trim(string str);
00125
00128 typedef list<string> STRING_LIST;
00129 typedef STRING_LIST::iterator STRING_LIST_ITERATOR;
00130 STRING_LIST split(string str, string delimiter);
00131
00133 string replace(string str, string find, string repl);
00134
00135
00136
00137
00138
00139 string getTime(time_t timeval = 0);
00140 string getDate(time_t timeval = 0);
00141 unsigned long getElapsedMillis();
00142 void sleep(unsigned int millis);
00143
00144
00145
00146
00147
00148 #ifdef WIN32
00149 const string LINE_BREAK = "\r\n";
00150 #else
00151 const string LINE_BREAK = "\n";
00152 #endif
00153
00154 };
00155
00156 inline void Helper::sleep(unsigned int millis) {
00157 #ifdef WIN32
00158 Sleep (millis);
00159 #else
00160
00161 unsigned long secondsSleep = millis / 1000;
00162 unsigned long millisSleep = millis % 1000;
00163
00164
00165
00166
00167
00168
00169
00170 if (secondsSleep > 0)
00171 sleep(secondsSleep);
00172
00173
00174
00175
00176
00177 if (millisSleep > 0) {
00178 assert (millisSleep < 1000);
00179 usleep(millisSleep * 1000);
00180 }
00181 #endif
00182 }
00183
00184 }}
00185
00186 #endif // __HELPER_H