10 #ifndef CORAL_UTIL_HPP 11 #define CORAL_UTIL_HPP 18 #include "coral/config.h" 19 #include "boost/filesystem/path.hpp" 20 #include "boost/noncopyable.hpp" 62 int ArrayStringCmp(
const char* array,
size_t length,
const char* stringz);
97 template<
typename T1,
typename T2>
101 variable = replacement;
141 template<
typename F,
typename... Args>
146 tmp(std::forward<Args>(args)...);
150 template<
typename Action>
151 class ScopeGuard : boost::noncopyable
154 explicit ScopeGuard(Action action) : m_active(
true), m_action(action) { }
156 ScopeGuard(ScopeGuard&& other)
161 ScopeGuard& operator=(ScopeGuard&& other)
167 ~ScopeGuard() {
if (m_active) m_action(); }
188 template<
typename Action>
189 ScopeGuard<Action>
OnScopeExit(Action action) {
return ScopeGuard<Action>(action); }
212 #endif // header guard void EncodeUint64(std::uint64_t source, char target[8])
Encodes a 64-bit unsigned integer using little-endian byte order.
void SpawnProcess(const std::string &program, const std::vector< std::string > &args)
Starts a new process.
void EncodeUint16(std::uint16_t source, char target[2])
Encodes a 16-bit unsigned integer using little-endian byte order.
std::string RandomUUID()
Returns a string that contains a random UUID.
std::string Timestamp()
Returns the current UTC time in the ISO 8601 "basic" format.
void LastCall(F &f)
Calls the given function(-like object), but only after swapping it with a default-constructed one...
Definition: util.hpp:134
boost::filesystem::path ThisExePath()
Returns the path of the current executable.
std::uint64_t DecodeUint64(const char source[8])
Decodes a 64-bit unsigned integer using little-endian byte order.
ScopeGuard< Action > OnScopeExit(Action action)
Scope guard.
Definition: util.hpp:189
Definition: variable_io.hpp:28
T1 MoveAndReplace(T1 &variable, const T2 &replacement)
Moves a value, replacing it with another one.
Definition: util.hpp:98
std::uint16_t DecodeUint16(const char source[2])
Decodes a 16-bit unsigned integer using little-endian byte order.
std::string RandomString(size_t size, const char *charSet)
Creates a random string.
std::uint32_t DecodeUint32(const char source[4])
Decodes a 32-bit unsigned integer using little-endian byte order.
void EncodeUint32(std::uint32_t source, char target[4])
Encodes a 32-bit unsigned integer using little-endian byte order.
int ArrayStringCmp(const char *array, size_t length, const char *stringz)
Given a character array and its length, compares it lexicographically to a zero-terminated string...