-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutil.h
65 lines (53 loc) · 1.7 KB
/
util.h
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
/*
Copyright (C) 2015 Matthew Lai
Giraffe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Giraffe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTIL_H
#define UTIL_H
#include <chrono>
#include <fstream>
#include <regex>
#include <sstream>
#ifdef __GNUC_MINOR__
#ifndef __llvm__
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION < 40900
#error GCC 4.9.0 is the minimum required to compile this code. \
Earlier versions have broken <regex> and WILL break this code!
#endif
#endif
#endif
inline double CurrentTime() { //returns current time
return static_cast<double>(
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count()) / 1000000.0;
}
inline bool PatternMatch(std::string str, std::string pattern_str)
{
std::regex pattern(pattern_str, std::regex_constants::extended);
return std::regex_match(str, pattern);
}
template <typename T>
inline std::string ToStr(const T &x)
{
std::stringstream ss;
ss << x;
return ss.str();
}
inline bool FileReadable(const std::string &filename)
{
std::ifstream infile(filename);
return infile.good();
}
#endif // UTIL_H