HoverRace  2.0
Typedefs | Functions | Variables
HoverRace::Util::OS Namespace Reference

Operating system support utilities. More...

Typedefs

using cpstr_t = const path_t::value_type *
 
using dirEnt_t = boost::filesystem::directory_entry
 
using dirIter_t = boost::filesystem::directory_iterator
 
using fs_error_t = boost::filesystem::filesystem_error
 
using path_t = boost::filesystem::path
 
using pstr_t = path_t::value_type *
 
using timestamp_t = MR_Int64
 

Functions

std::string FileTimeString ()
 Generate a string representing the current timestamp, suitable for filenames. More...
 
OS::path_t FindExePath ()
 Find the path of the executable itself. More...
 
FILE * FOpen (const path_t &path, const char *mode)
 Open a file using the OS-specific path format. More...
 
std::string GetUsername ()
 Get the username of the current OS user. More...
 
bool OpenLink (const std::string &url)
 Open a URL. More...
 
bool OpenPath (const path_t &path)
 Open a filesystem path. More...
 
void SetEnv (const char *key, const char *val)
 Set an environment variable. More...
 
const std::locale & SetLocale (const path_t &path, const std::string &domain, const std::string &reqLocale={})
 Set the locale based on the current environment. More...
 
void ShowMessage (const std::string &s, bool error=false)
 Display a simple error message to the user. More...
 
std::string StrError (int errnum)
 Convert an error number to a string. More...
 
timestamp_t Time ()
 Retrieve a timestamp. More...
 
constexpr timestamp_t TimeDiff (timestamp_t laterTs, timestamp_t earlierTs) noexcept
 Calculate the difference between two timestamps. More...
 
void TimeInit ()
 Initialize the OS time source. More...
 
void TimeShutdown ()
 Shutdown the OS time source. More...
 

Variables

std::locale locale {""}
 Global reference to the current locale. More...
 
const std::locale & stdLocale = std::locale::classic()
 The standard "C" locale for things that should be not be affected by locale. More...
 

Detailed Description

Operating system support utilities.

Author
Michael Imamura

Typedef Documentation

using HoverRace::Util::OS::cpstr_t = typedef const path_t::value_type*
using HoverRace::Util::OS::dirEnt_t = typedef boost::filesystem::directory_entry
using HoverRace::Util::OS::dirIter_t = typedef boost::filesystem::directory_iterator
using HoverRace::Util::OS::fs_error_t = typedef boost::filesystem::filesystem_error
using HoverRace::Util::OS::path_t = typedef boost::filesystem::path
using HoverRace::Util::OS::pstr_t = typedef path_t::value_type*

Function Documentation

std::string HoverRace::Util::OS::FileTimeString ( )

Generate a string representing the current timestamp, suitable for filenames.

Returns
The string (in "YYYY-MM-DD HH.MM.SS TZ" format).
OS::path_t HoverRace::Util::OS::FindExePath ( )

Find the path of the executable itself.

Returns
The path, including the executable name.
FILE * HoverRace::Util::OS::FOpen ( const path_t path,
const char *  mode 
)

Open a file using the OS-specific path format.

Parameters
pathThe file to open.
modeThe mode (same as POSIX {fopen(3)}).
Returns
The file handle or NULL if an error occurred.
std::string HoverRace::Util::OS::GetUsername ( )

Get the username of the current OS user.

Returns
The username, or a default if it could not be retrieved.
bool HoverRace::Util::OS::OpenLink ( const std::string &  url)

Open a URL.

Parameters
urlThe URL (UTF-8 encoded).
Returns
true if successful, false otherwise.
bool HoverRace::Util::OS::OpenPath ( const path_t path)

Open a filesystem path.

Only directories may be opened; they will be opened using the native file navigator.

Parameters
pathThe path to open.
Returns
true if successful, false otherwise.
void HoverRace::Util::OS::SetEnv ( const char *  key,
const char *  val 
)

Set an environment variable.

Parameters
keyThe variable name (may not be NULL).
valThe variable value (may not be NULL).
Exceptions
Exception
const std::locale & HoverRace::Util::OS::SetLocale ( const path_t path,
const std::string &  domain,
const std::string &  reqLocale = {} 
)

Set the locale based on the current environment.

Parameters
pathThe path to where compiled translations can be found.
domainThe translation domain to use.
reqLocaleThe requested locale. If blank, the system default will be used.
Returns
The selected locale.
void HoverRace::Util::OS::ShowMessage ( const std::string &  s,
bool  error = false 
)

Display a simple error message to the user.

On Windows, this will pop up a message box, elsewhere this will just output to the console.

Parameters
sThe message.
errortrue to indicate this is an error message.
std::string HoverRace::Util::OS::StrError ( int  errnum)

Convert an error number to a string.

Parameters
errnumThe error number, usually errno.
Returns
The error as a string.
OS::timestamp_t HoverRace::Util::OS::Time ( )

Retrieve a timestamp.

The value returned is OS-dependent and should only be used for relative calculations.

Returns
A relative timestamp, in milliseconds.
constexpr timestamp_t HoverRace::Util::OS::TimeDiff ( timestamp_t  laterTs,
timestamp_t  earlierTs 
)
inlinenoexcept

Calculate the difference between two timestamps.

This properly handles wraparound in timestamps.

Parameters
laterTsThe later timestamp.
earlierTsThe earlier timestamp.
Returns
laterTs - earlierTs
void HoverRace::Util::OS::TimeInit ( )

Initialize the OS time source.

void HoverRace::Util::OS::TimeShutdown ( )

Shutdown the OS time source.

Variable Documentation

std::locale HoverRace::Util::OS::locale {""}

Global reference to the current locale.

Defaults to "C" until OS::SetLocale() is called.

const std::locale & HoverRace::Util::OS::stdLocale = std::locale::classic()

The standard "C" locale for things that should be not be affected by locale.