forked from learning-process/parallel_programming_course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.hpp
More file actions
93 lines (77 loc) · 2.4 KB
/
util.hpp
File metadata and controls
93 lines (77 loc) · 2.4 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
#pragma once
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <string>
#include <typeinfo>
#ifdef __GNUG__
# include <cxxabi.h>
#endif
#include "nlohmann/json_fwd.hpp"
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4459)
#endif
#include <nlohmann/json.hpp>
/// @brief JSON namespace used for settings and config parsing.
using NlohmannJsonParseError = nlohmann::json::parse_error;
/// @brief JSON namespace used for settings and config typing.
using NlohmannJsonTypeError = nlohmann::json::type_error;
#ifdef _MSC_VER
# pragma warning(pop)
#endif
namespace ppc::util {
/// @brief Utility class for tracking destructor failure across tests.
/// @details Provides thread-safe methods to set, unset, and check the failure flag.
class DestructorFailureFlag {
public:
/// @brief Marks that a destructor failure has occurred.
static void Set() {
failure_flag.store(true);
}
/// @brief Clears the destructor failure flag.
static void Unset() {
failure_flag.store(false);
}
/// @brief Checks if a destructor failure was recorded.
/// @return True if failure occurred, false otherwise.
static bool Get() {
return failure_flag.load();
}
private:
inline static std::atomic<bool> failure_flag{false};
};
enum class GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
std::string GetAbsoluteTaskPath(const std::string& id_path, const std::string& relative_path);
int GetNumThreads();
int GetNumProc();
double GetTaskMaxTime();
double GetPerfMaxTime();
template <typename T>
std::string GetNamespace() {
std::string name = typeid(T).name();
#ifdef __GNUC__
int status = 0;
std::unique_ptr<char, void (*)(void*)> demangled{abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status),
std::free};
name = (status == 0) ? demangled.get() : name;
#endif
#ifdef _MSC_VER
const std::string prefixes[] = {"class ", "struct ", "enum ", "union "};
for (const auto& prefix : prefixes) {
if (name.starts_with(prefix)) {
name = name.substr(prefix.size());
break;
}
}
name.erase(0, name.find_first_not_of(' '));
#endif
auto pos = name.rfind("::");
return (pos != std::string::npos) ? name.substr(0, pos) : std::string{};
}
inline std::shared_ptr<nlohmann::json> InitJSONPtr() {
return std::make_shared<nlohmann::json>();
}
bool IsUnderMpirun();
} // namespace ppc::util