-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathutil.hpp
More file actions
105 lines (79 loc) · 3.26 KB
/
util.hpp
File metadata and controls
105 lines (79 loc) · 3.26 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <string>
#include <string_view>
#define PPC_FUNC_NAME __func__
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4459)
#endif
#include <nlohmann/json.hpp> // NOLINT(misc-include-cleaner)
/// @brief JSON namespace used for settings and config parsing.
using NlohmannJsonParseError = nlohmann::json::parse_error; // NOLINT(misc-include-cleaner)
/// @brief JSON namespace used for settings and config typing.
using NlohmannJsonTypeError = nlohmann::json::type_error; // NOLINT(misc-include-cleaner)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#define ASSERT_ANY_THROW_NOLINT(stmt) ASSERT_ANY_THROW(stmt) // NOLINT
#define EXPECT_THROW_NOLINT(stmt, error) EXPECT_THROW(stmt, error) // NOLINT
#define TEST_NOLINT(test_suite_name, test_name) TEST(test_suite_name, test_name) // NOLINT
#define ASSERT_DEATH_IF_SUPPORTED_NOLINT(stmt, name) ASSERT_DEATH_IF_SUPPORTED(stmt, name) // NOLINT
#define TYPED_TEST_NOLINT(test_suite_name, test_name) TYPED_TEST(test_suite_name, test_name) // NOLINT
#define INSTANTIATE_TEST_SUITE_P_WITH_NAME(n, t, g, ng) INSTANTIATE_TEST_SUITE_P(n, t, g, ng) // NOLINT
#define INSTANTIATE_TEST_SUITE_P_NOLINT(n, t, g) INSTANTIATE_TEST_SUITE_P(n, t, g) // NOLINT
// INSTANTIATE_TEST_SUITE_P | n, t, g, ng == name, test_case_name, generator, name_generator
namespace ppc::util {
enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
int GetNumThreads();
template <typename T>
constexpr std::string_view GetNamespace() {
#if defined(__clang__) || defined(__GNUC__)
constexpr std::string_view kFunc = __PRETTY_FUNCTION__;
constexpr std::string_view kKey = "T = ";
auto start = kFunc.find(kKey);
if (start == std::string_view::npos) {
return {};
}
start += kKey.size();
auto end = kFunc.find_first_of(";]> ,", start);
if (end == std::string_view::npos) {
return {};
}
auto full_type = kFunc.substr(start, end - start);
auto ns_end = full_type.rfind("::");
if (ns_end == std::string_view::npos) {
return {};
}
return full_type.substr(0, ns_end);
#elif defined(_MSC_VER)
constexpr std::string_view kFunc = __FUNCSIG__;
constexpr std::string_view kKey = "GetNamespace<";
auto start = kFunc.find(kKey);
if (start == std::string_view::npos) return {};
start += kKey.size();
constexpr std::string_view prefixes[] = {"class ", "struct ", "enum ", "union "};
for (auto prefix : prefixes) {
if (kFunc.substr(start, prefix.size()) == prefix) {
start += prefix.size();
break;
}
}
auto end = kFunc.find('>', start);
if (end == std::string_view::npos) return {};
auto full_type = kFunc.substr(start, end - start);
auto ns_end = full_type.rfind("::");
if (ns_end == std::string_view::npos) return {};
return full_type.substr(0, ns_end);
#else
static_assert([] { return false; }(), "Unsupported compiler");
return {};
#endif
}
// NOLINTNEXTLINE(misc-include-cleaner)
inline std::shared_ptr<nlohmann::json> InitJSONPtr() { return std::make_shared<nlohmann::json>(); }
bool IsUnderMpirun();
} // namespace ppc::util