BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Utilities
Collaboration diagram for Utilities:

Topics

 General maths utilities
 Memory utilities
 String utilities

Files

file  Chrono.hpp
file  Console.hpp
file  Files.hpp
file  Logger.hpp
file  Threading.hpp
file  Variant.hpp

Namespaces

namespace  util

Concepts

concept  util::ChronoDuration

Classes

struct  util::Visitor< Callable >

Functions

void util::enable_utf8_console_output ()
auto util::files::load (const path &file) -> std::expected< std::string, std::string >
auto util::files::overwrite (const path &file, std::string_view text) -> std::expected< void, std::string >
void util::progressive_backoff (std::function< bool()> pred)
auto util::start_file_logger (const std::filesystem::path &logFile) -> std::expected< void, std::string >

Detailed Description

General utilities not specifically related to chess.

Function Documentation

◆ enable_utf8_console_output()

void util::enable_utf8_console_output ( )

Ensures that std::cout will interpret strings as UTF-8. On non-Windows platforms, this is a no-op.

◆ load()

auto util::files::load ( const path & file) -> std::expected< std::string, std::string >
nodiscard

Loads the file's content as a string. If the file cannot be loaded, returns an explanatory error message.

See also
overwrite()

◆ overwrite()

auto util::files::overwrite ( const path & file,
std::string_view text ) -> std::expected< void, std::string >
nodiscard

Overwrites the given filepath with the given text. If the file cannot be written, returns an explanatory error message.

See also
load()

◆ progressive_backoff()

void util::progressive_backoff ( std::function< bool()> pred)

Blocks the calling thread until pred returns true. Blocking is implemented by spinning on the predicate and using a progressive backoff strategy.

This progressive backoff strategy avoids wasting energy, and allows other threads to make progress by yielding the waiting thread after a certain amount of time. This time is chosen to be about 1 millisecond.

On platforms other than x86, x86_64, or arm64, a simple implementation will be used.

◆ start_file_logger()

auto util::start_file_logger ( const std::filesystem::path & logFile) -> std::expected< void, std::string >
nodiscard

Starts a file logger. This works by duplicating std::cout and std::cerr output to a file at the given path. If the operation fails, returns an explanatory error string. This may be called multiple times with different file paths; each call will flush output to the previous log file and start writing output to the new log file.