mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-01-06 00:30:18 +01:00
add more utilities
This commit is contained in:
parent
86e2d8b129
commit
d7f486fdc9
|
|
@ -4,6 +4,7 @@ find_package(Git)
|
|||
|
||||
|
||||
add_library(${PROJECT_NAME} OBJECT
|
||||
src/die.cpp
|
||||
src/hexdump.cpp
|
||||
src/mem.cpp
|
||||
src/Version.cpp
|
||||
|
|
|
|||
13
rx/include/rx/atScopeExit.hpp
Normal file
13
rx/include/rx/atScopeExit.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace rx {
|
||||
template <typename T> class atScopeExit {
|
||||
T _object;
|
||||
|
||||
public:
|
||||
atScopeExit(T &&object) : _object(std::forward<T>(object)) {}
|
||||
~atScopeExit() { _object(); }
|
||||
};
|
||||
} // namespace rx
|
||||
7
rx/include/rx/die.hpp
Normal file
7
rx/include/rx/die.hpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
namespace rx {
|
||||
[[noreturn, gnu::format(printf, 1, 2)]] void die(const char *message, ...);
|
||||
[[gnu::format(printf, 2, 3)]] void dieIf(bool condition, const char *message,
|
||||
...);
|
||||
} // namespace rx
|
||||
26
rx/src/die.cpp
Normal file
26
rx/src/die.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include "die.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
void rx::die(const char *message, ...) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
std::vfprintf(stderr, message, args);
|
||||
std::fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void rx::dieIf(bool condition, const char *message, ...) {
|
||||
if (condition) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
std::vfprintf(stderr, message, args);
|
||||
std::fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue