]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #ifndef BENCHMARK_STRING_UTIL_H_ |
2 | #define BENCHMARK_STRING_UTIL_H_ | |
3 | ||
4 | #include <sstream> | |
5 | #include <string> | |
6 | #include <utility> | |
7 | #include "internal_macros.h" | |
8 | ||
9 | namespace benchmark { | |
10 | ||
11 | void AppendHumanReadable(int n, std::string* str); | |
12 | ||
13 | std::string HumanReadableNumber(double n, double one_k = 1024.0); | |
14 | ||
15 | #if defined(__MINGW32__) | |
16 | __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2))) | |
17 | #elif defined(__GNUC__) | |
18 | __attribute__((format(printf, 1, 2))) | |
19 | #endif | |
20 | std::string | |
21 | StrFormat(const char* format, ...); | |
22 | ||
23 | inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { | |
24 | return out; | |
25 | } | |
26 | ||
27 | template <class First, class... Rest> | |
28 | inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) { | |
29 | out << std::forward<First>(f); | |
30 | return StrCatImp(out, std::forward<Rest>(rest)...); | |
31 | } | |
32 | ||
33 | template <class... Args> | |
34 | inline std::string StrCat(Args&&... args) { | |
35 | std::ostringstream ss; | |
36 | StrCatImp(ss, std::forward<Args>(args)...); | |
37 | return ss.str(); | |
38 | } | |
39 | ||
40 | #ifdef BENCHMARK_STL_ANDROID_GNUSTL | |
41 | /* | |
42 | * GNU STL in Android NDK lacks support for some C++11 functions, including | |
43 | * stoul, stoi, stod. We reimplement them here using C functions strtoul, | |
44 | * strtol, strtod. Note that reimplemented functions are in benchmark:: | |
45 | * namespace, not std:: namespace. | |
46 | */ | |
47 | unsigned long stoul(const std::string& str, size_t* pos = nullptr, | |
48 | int base = 10); | |
49 | int stoi(const std::string& str, size_t* pos = nullptr, int base = 10); | |
50 | double stod(const std::string& str, size_t* pos = nullptr); | |
51 | #else | |
52 | using std::stoul; | |
53 | using std::stoi; | |
54 | using std::stod; | |
55 | #endif | |
56 | ||
57 | } // end namespace benchmark | |
58 | ||
59 | #endif // BENCHMARK_STRING_UTIL_H_ |