-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.hpp
71 lines (54 loc) · 1.38 KB
/
util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef XCS_UTIL_HPP
#define XCS_UTIL_HPP
#include <memory>
#include <map>
#include <vector>
#include <ctime>
#include <sys/times.h>
#include <iomanip>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
std::shared_ptr<std::vector<std::shared_ptr<std::map<std::string, double>>>> getData(const std::string& filePath="000001.XSHE.csv");
void error(std::string name, std::string method, std::string message, unsigned int exit_code);
std::string trim(std::string const& source, char const* delims = " \t\r\n");
std::string long2binary(const unsigned long, unsigned long);
unsigned long binary2long(const std::string &binary);
void set_flag(std::string set, bool& var);
class timer {
private:
unsigned long ti; //! init time
unsigned long tf; //! stop time
public:
timer() {
struct tms reading;
times(&reading);
ti = reading.tms_utime;
};
~timer() {};
void start()
{
struct tms reading;
times(&reading);
ti = reading.tms_utime;
}
double time() const
{
struct tms reading;
times(&reading);
return double(reading.tms_utime - ti)/sysconf(_SC_CLK_TCK);
}
void stop()
{
struct tms reading;
times(&reading);
tf = reading.tms_utime;
}
double elapsed() const
{
return double(tf - ti)/sysconf(_SC_CLK_TCK);
}
unsigned long initial() const { return ti; };
unsigned long final() const { return tf; };
};
#endif // !XCS_UTIL_HPP