13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Weffc++"
24#pragma GCC diagnostic pop
29#if defined(CHRONO_MISSING)
30 gettimeofday(&execution_start, NULL);
32 execution_start = std::chrono::high_resolution_clock::now();
39#if defined(CHRONO_MISSING)
40 gettimeofday(&execution_end, NULL);
42 execution_end = std::chrono::high_resolution_clock::now();
51#if defined(BELOFTE_NOUNICODE)
64#if defined(CHRONO_MISSING)
65 return (execution_end.tv_sec * 1000000LL + execution_end.tv_usec) -
66 (execution_start.tv_sec * 1000000LL + execution_start.tv_usec);
68 return std::chrono::duration_cast<std::chrono::microseconds>(execution_end - execution_start).count();
71#if defined(CHRONO_MISSING)
72 struct timeval now_end;
73 gettimeofday(&now_end, NULL);
74 return (now_end.tv_sec * 1000000LL + now_end.tv_usec) -
75 (execution_start.tv_sec * 1000000LL + execution_start.tv_usec);
77 std::chrono::high_resolution_clock::time_point now_end;
78 now_end = std::chrono::high_resolution_clock::now();
79 return std::chrono::duration_cast<std::chrono::microseconds>(now_end - execution_start).count();
86#if defined(CHRONO_MISSING)
87 return (execution_end.tv_sec * 1000LL + execution_end.tv_usec / 1000LL) -
88 (execution_start.tv_sec * 1000LL + execution_start.tv_usec / 1000LL);
90 return std::chrono::duration_cast<std::chrono::milliseconds>(execution_end - execution_start).count();
93#if defined(CHRONO_MISSING)
94 struct timeval now_end;
95 gettimeofday(&now_end, NULL);
96 return (now_end.tv_sec * 1000LL + now_end.tv_usec / 1000LL) -
97 (execution_start.tv_sec * 1000LL + execution_start.tv_usec / 1000LL);
99 std::chrono::high_resolution_clock::time_point now_end;
100 now_end = std::chrono::high_resolution_clock::now();
101 return std::chrono::duration_cast<std::chrono::milliseconds>(now_end - execution_start).count();
108#if defined(CHRONO_MISSING)
109 return (execution_end.tv_sec + execution_end.tv_usec / 1000000LL) -
110 (execution_start.tv_sec + execution_start.tv_usec / 1000000LL);
112 return std::chrono::duration_cast<std::chrono::seconds>(execution_end - execution_start).count();
115#if defined(CHRONO_MISSING)
116 struct timeval now_end;
117 gettimeofday(&now_end, NULL);
118 return (now_end.tv_sec + now_end.tv_usec / 1000000LL) -
119 (execution_start.tv_sec + execution_start.tv_usec / 1000000LL);
121 std::chrono::high_resolution_clock::time_point now_end;
122 now_end = std::chrono::high_resolution_clock::now();
123 return std::chrono::duration_cast<std::chrono::seconds>(now_end - execution_start).count();
136 size_t delimPos = src.find(delim);
137 while (delimPos != std::string::npos) {
138 v.emplace_back(src.substr(0, delimPos));
139 src = src.substr(delimPos + delim.length());
140 delimPos = src.find(delim);
142 std::string s =
alltrim(src, delim);
143 if (s !=
"") v.emplace_back(s);
153 std::string
const& delim)
157 size_t delimPos = src.find(delim);
158 if (delimPos != std::string::npos) {
159 first = src.substr(0, delimPos);
160 second = src.substr(delimPos + delim.length());
164 return std::make_pair(first, second);
173 std::ostringstream ss;
180 std::ostringstream ss;
187 std::ostringstream ss;
198 while (s.find(delim) == 0) s.erase(0, 1);
199 size_t len = s.size();
200 while (!s.empty() && (s.rfind(delim) == --len)) s.erase(len, len + 1);
207 return !s.empty() && std::find_if(s.begin(), s.end(),
208 [](
unsigned char c) { return !std::isdigit(c); }) == s.end();
216#if defined(BELOFTE_NORANDOM)
219 if (
App().getConfig(
"random", 0)) {
220 return std::rand() % nCeil;
229#if defined(BELOFTE_NORANDOM)
230 return (nStart + nMax) / 2;
232 if (
App().getConfig(
"random", 0)) {
233 return nStart + std::rand() % (nMax + 1 - nStart);
235 return (nStart + nMax) / 2;
245 std::string rcname(basename);
247 std::size_t found = rcname.rfind(std::string(
".exe"));
248 if (found != std::string::npos)
249 rcname = rcname.erase(found, std::string::npos);
250 return rcname +
".rc";
260 std::string
const& find)
262 for (
unsigned int i = 0; i < param.size(); ++i) {
263 if (param[i] == find)
return static_cast<int> (i);
269 std::string
const& find,
unsigned long const nOffSet)
271 for (
unsigned int i = 0; i < param.size(); ++i) {
272 if (param[i] == find) {
273 if (i < param.size() + nOffSet)
return atoi(param[i + nOffSet].c_str());
281 time_t now = time(
nullptr);
284 tstruct = *localtime(&now);
285 strftime(buf,
sizeof (buf),
"%Y.%m.%d", &tstruct);
291 long nSeconds = nTime / 1000;
292 int ms = nTime % 1000;
293 std::stringstream sTime;
295 sTime << belofte::to_string(static_cast<int32_t>(nSeconds));
297 if (nSeconds >= 86400) {
298 sTime << belofte::to_string(static_cast<int32_t>(nSeconds / 86400)) <<
"d ";
301 if (nSeconds >= 3600) {
302 sTime << belofte::to_string(static_cast<int32_t>(nSeconds / 3600)) <<
":";
304 }
else if (nTime > 86400000) {
307 if (nSeconds >= 60) {
308 sTime << std::setw(2) << std::setfill(
'0')
314 sTime << std::setw(2) << std::setfill('0') << belofte::to_string(static_cast<int32_t>(nSeconds));
317 sTime <<
"." << std::setw(3) << std::setfill(
'0')
This is the main include file, needs to be included before any other include.
long long getDurationSec() const
std::string getDuration() const
TimedExecution()
implementation of timing functions
long long getDurationMilliSec() const
long long getDurationMicroSec() const
int getRandomRange(int const nStart, int const nMax)
int positionParamValue(stringList const ¶m, std::string const &find, unsigned long const nOffSet=0)
std::string alltrim(std::string s, std::string const &delim=" ")
trim left and right spaces or delim from string
std::pair< std::string, std::string > decompose(std::string const &src, std::string const &delim)
Split delimited long string into a pair based on delimiter e.g.
std::string to_string(int16_t value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
stringList const stringSplit(std::string src, std::string const &delim)
Split delimited long string into a vector.
std::vector< std::string > stringList
std::string currentDate()
std::string prettyTime(long const t)
std::string getRCname(std::string const &basename)
convert executable name into name.rc, possibly dropping .exe suffix
bool is_number(std::string const &s)
int getRandomInt(int const nCeil)
return random in between 0 and nCeil - 1
int positionParamIndex(stringList const ¶m, std::string const &find)
find position in which param has been found