utils#
-
namespace heph#
-
namespace utils#
-
namespace string#
Functions
-
std::string_view truncate(std::string_view str, std::string_view start_token, std::string_view end_token = std::string_view(""), bool include_end_token = true)#
Truncates a string by returning the segment between the first start token and the first end token strings, including the start token and the end token. If
- Parameters:
include_end_token – is false, the end token will not be included in the result. For example, the following code will return ‘to/some/file’
constexpr auto str = "/path/to/some/file.txt"; constexpr auto start_token = "to"; constexpr auto end_token = ".txt"; constexpr auto truncated = truncate(str, start_token, end_token, false); std::cout << truncated << '\n'; // $ to/some/file
-
std::string_view truncate(std::string_view str, std::string_view start_token, std::string_view end_token = std::string_view(""), bool include_end_token = true)#
-
namespace string#
-
namespace utils#
-
namespace heph
-
namespace utils
-
namespace timing#
-
class MockClock#
Public Types
Public Functions
-
~MockClock() = default#
- MockClock &=delete operator= (const MockClock &)
- MockClock &=delete operator= (MockClock &&)
Public Static Attributes
-
static bool is_steady = true#
Public Static Functions
-
static inline time_point now()#
-
static inline void reset()#
-
static inline void setCurrentTime(time_point new_time)#
-
~MockClock() = default#
-
class MockClock#
-
namespace timing#
-
namespace utils
-
namespace heph
-
namespace heph
-
namespace utils
-
class TerminationBlocker#
- #include “hephaestus/utils/signal_handler.h”
Use this class to block until a signal is received.
NOTE: can be extended to call a generic callback when a signal is received. Usage:
int main() { // Do something TerminationBlocker::waitForInterrupt(); } // Or while (!TerminationBlocker::stopRequested()) { // Do something }
Public Static Functions
-
static bool stopRequested()#
Return true if a signal has been received, false otherwise.
-
static void waitForInterrupt()#
Blocks until a signal has been received.
-
static bool stopRequested()#
-
class TerminationBlocker#
-
namespace utils
-
namespace heph
-
namespace utils
-
namespace utils
-
namespace heph
-
namespace utils
-
namespace filesystem#
-
class ScopedPath#
- #include “hephaestus/utils/filesystem/scoped_path.h”
This class allows to create a file that is removed when the class goes out of scope (RAII). This is very useful in tests to avoid having dangling files.
Public Functions
-
~ScopedPath()#
-
ScopedPath(const ScopedPath&) = delete#
-
ScopedPath(ScopedPath&&) = default#
- ScopedPath &=delete operator= (const ScopedPath &)
- ScopedPath &=default operator= (ScopedPath &&)
-
~ScopedPath()#
-
class ScopedPath#
-
namespace filesystem#
-
namespace utils
-
namespace heph
-
namespace utils
-
class StackTrace#
- #include “hephaestus/utils/stack_trace.h”
Class to print a stack trace on crash. Usage: int main() { heph::utils::StackTrace stack_trace; … }.
-
class StackTrace#
-
namespace utils
-
namespace heph
-
namespace utils
-
namespace timing
-
class StopWatch#
- #include “hephaestus/utils/timing/stop_watch.h”
StopWatch provides functionalities to measure elapsed time in different intervals.
start stop start stop | lapse | lapse | | lapse | | elapsed | |___________________| |___________| accumulatedLapsDuration
Public Types
Public Functions
-
explicit StopWatch(NowFunctionPtr now_fn = &ClockT::now)#
-
void start()#
Start new lap. Does nothing if already ticking.
-
template<typename TargetDurationT = StopWatch::DurationT>
TargetDurationT stop()# Stop current lap and pause accumulating time.
-
template<typename TargetDurationT = StopWatch::DurationT>
TargetDurationT lapse()#
-
template<typename TargetDurationT = StopWatch::DurationT>
TargetDurationT elapsed() const# - Returns:
Elapsed time since the last start() cast to the desired duration.
-
void reset()#
Stop and reset accumulated information.
-
DurationT accumulatedLapsDuration() const#
- Returns:
Time accumulated across all laps since last reset().
-
explicit StopWatch(NowFunctionPtr now_fn = &ClockT::now)#
-
class StopWatch#
-
namespace timing
-
namespace utils
-
namespace heph
-
namespace utils
-
namespace timing
-
class WatchdogTimer#
-
Public Functions
-
void start(std::chrono::milliseconds period, Callback &&callback)#
Start the watchdog timer with the specified period and callback. Once the timer starts it will loop indefinitely, calling the callback ever
period
milliseconds.
-
void stop()#
Stop the timer.
-
void pat()#
Pat the watchdog. If called the timer will not call the callback for the next period. This can be used to implement a dead-man switch.
-
void start(std::chrono::milliseconds period, Callback &&callback)#
-
class WatchdogTimer#
-
namespace timing
-
namespace utils
-
namespace heph
Functions
-
template<typename ...Args>
void panic(internal::StringLiteralWithLocation<Args...> message, Args&&... args)# User function to panic. Internally this throws a Panic exception.
Note: If macro
DISABLE_EXCEPTIONS
is defined, this function terminates printing the message. In this case, the whole code should be considered noexcept.- Parameters:
message – A message describing the error and what caused it
location – Location in the source where the error was triggered at
-
template<typename ...Args>
void panicIf(bool condition, internal::StringLiteralWithLocation<Args...> message, Args&&... args)# User function to panic on condition lazily formatting the message. The whole code should be considered noexcept. Will use CHECK if DISABLE_EXCEPTIONS = ON.
- Parameters:
condition – Condition whether to panic
message – A message describing the error and what caused it
location – Location in the source where the error was triggered at
-
template<typename ...Args>
-
namespace heph
Functions
-
template<typename R, typename ...Args>
class UniqueFunction<R(Args...)># Public Functions
-
inline UniqueFunction() noexcept#
-
inline ~UniqueFunction() noexcept#
-
UniqueFunction(const UniqueFunction &other) noexcept = delete#
-
inline UniqueFunction(UniqueFunction &&other) noexcept#
- UniqueFunction &=delete operator= (const UniqueFunction &other) noexcept
-
inline UniqueFunction &operator=(UniqueFunction &&other) noexcept#
-
template<detail::invocable<R, Args...> F>
inline UniqueFunction &operator=(F &&f) noexcept#
-
inline UniqueFunction &operator=(std::nullptr_t) noexcept#
-
inline explicit operator bool() const noexcept#
-
inline UniqueFunction() noexcept#
-
template<typename R, typename ...Args>
-
namespace heph
-
namespace utils
-
namespace filesystem
Functions
-
std::optional<std::string> readFile(const std::filesystem::path &path)#
Read the whole content of the input file into a string.
- Returns:
std::nullopt if the file doesn’t exists.
-
std::optional<std::vector<std::byte>> readBinaryFile(const std::filesystem::path &path)#
Read the whole content of the input binary file into a binary buffer.
- Returns:
std::nullopt if the file doesn’t exists.
-
std::optional<std::string> readFile(const std::filesystem::path &path)#
-
namespace filesystem
-
namespace utils
-
namespace heph
-
template<class ...Ts>
struct Overloads : public Ts...# - #include “hephaestus/utils/variant.h”
A helper struct which allows you to easily branch on the type of alternative held by a variant:
std::visit(heph::Overloads { [](const &FirstAlternative& value) { // Code to be run if variant holds a value of type FirstAlternative. }, [](const &SecondAlternative& value) { // Code to be run if variant holds a value of type SecondAlternative. }, }, variant);
-
template<class ...Ts>
-
namespace heph
-
namespace utils
-
namespace format#
-
namespace format#
-
namespace utils
-
namespace heph
-
namespace utils
-
namespace string
Functions
-
template<std::size_t SizeL, std::size_t SizeR>
StringLiteral<SizeL + SizeR - 1> operator+(const StringLiteral<SizeL> &lhs, const StringLiteral<SizeR> &rhs)#
-
template<std::size_t SizeL, std::size_t SizeR>
-
namespace string
-
namespace utils