rcpputils
master
C++ API providing common utilities and data structures.
|
Namespaces | |
fs | |
Classes | |
class | AssertionException |
An assertion-like exception for halting tests if conditions are not met. More... | |
class | IllegalStateException |
An exception to be thrown when a state check fails. More... | |
struct | is_pointer |
Type traits for validating if T is of type pointer or smart pointer. More... | |
struct | remove_pointer |
Type traits for deducing the data type of T from a pointer or smart pointer. More... | |
struct | scope_exit |
class | SharedLibrary |
Enumerations | |
enum | endian { endian::little = __ORDER_LITTLE_ENDIAN__, endian::big = __ORDER_BIG_ENDIAN__, endian::native = __BYTE_ORDER__ } |
Type traits for defining the endianness at compile-time. More... | |
Functions | |
void | require_true (bool condition, const std::string &msg="invalid argument passed") |
Check that an argument condition passes. More... | |
void | check_true (bool condition, const std::string &msg="check reported invalid state") |
Check that a state condition passes. More... | |
void | assert_true (bool condition, const std::string &msg="assertion failed") |
Assert that a condition passes. More... | |
template<class CharT , class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>> | |
std::basic_string< CharT, Traits, Allocator > | find_and_replace (const std::basic_string< CharT, Traits, Allocator > &input, const std::basic_string< CharT, Traits, Allocator > &find, const std::basic_string< CharT, Traits, Allocator > &replace) |
Find and replace all instances of a string with another string. More... | |
template<typename InputT , typename FindT , typename ReplaceT > | |
auto | find_and_replace (InputT &&input, FindT &&find, ReplaceT &&replace) |
Find and replace all instances of a string with another string. More... | |
std::string | find_library_path (const std::string &library_name) |
Find a library located in the OS's specified environment variable for library paths. More... | |
std::string | path_for_library (const std::string &directory, const std::string &library_name) |
Construct the filepath for a library given its directory, and checks that it exists. More... | |
std::string | filename_for_library (const std::string &library_name) |
Create the filename corresponding to the library name. More... | |
std::string | get_env_var (const char *env_var) |
Retrieve the value of the given environment variable if it exists, or "". More... | |
template<typename CharT , typename ValueT , typename AllocatorT , template< typename T, class A > class ContainerT> | |
std::basic_string< CharT > | join (const ContainerT< ValueT, AllocatorT > &container, const CharT *delim) |
Join values in a container turned into strings by a given delimiter. More... | |
std::string | get_executable_name () |
Retrieve the current executable name. More... | |
template<typename CallableT > | |
scope_exit< CallableT > | make_scope_exit (CallableT &&callable) |
std::string | get_platform_library_name (std::string library_name, bool debug=false) |
Get the platform specific library name. More... | |
template<class InsertIterator , typename std::enable_if< std::is_same< InsertIterator &, decltype(std::declval< InsertIterator >().operator=(std::declval< std::string >()))>::value , ::type * = nullptr> | |
void | split (const std::string &input, char delim, InsertIterator &it, bool skip_empty=false) |
Split a specified input into tokens using a delimiter and a type erased insert iterator. More... | |
std::vector< std::string > | split (const std::string &input, char delim, bool skip_empty=false) |
Split a specified input into tokens using a delimiter. More... | |
|
strong |
Type traits for defining the endianness at compile-time.
cppreference.com documentation
From: https://en.cppreference.com/w/Cppreference:FAQ, this is licensed Creative Commons Attribution-Sharealike 3.0 Unported License (CC-BY-SA)
Enumerator | |
---|---|
little | |
big | |
native |
|
inline |
Check that an argument condition passes.
condition | condition that is asserted to be true |
msg | message to pass to exception when condition is false |
std::invalid_argument | if the condition is not met. |
|
inline |
Check that a state condition passes.
condition | condition to check whether it is true or not |
msg | message to pass to exception when condition is false |
rcpputils::IllegalStateException | if the condition is not met. |
|
inline |
Assert that a condition passes.
This function behaves similar to assert, except that it throws instead of invoking abort(). It is only enabled when NDEBUG is not defined
condition | condition to check whether it's true or not |
msg | message to pass to exception when condition is not met. |
rcpputils::AssertionException | if the macro NDEBUG is not set and the condition is not met. |
std::basic_string<CharT, Traits, Allocator> rcpputils::find_and_replace | ( | const std::basic_string< CharT, Traits, Allocator > & | input, |
const std::basic_string< CharT, Traits, Allocator > & | find, | ||
const std::basic_string< CharT, Traits, Allocator > & | replace | ||
) |
Find and replace all instances of a string with another string.
[in] | input | The input string. |
[in] | find | The substring to replace. |
[in] | replace | The string to substitute for each occurrence of find . |
find
replaced with the string replace
. auto rcpputils::find_and_replace | ( | InputT && | input, |
FindT && | find, | ||
ReplaceT && | replace | ||
) |
Find and replace all instances of a string with another string.
[in] | input | The input string. |
[in] | find | The substring to replace. |
[in] | replace | The string to substitute for each occurrence of find . |
find
replaced with the string replace
. std::string rcpputils::find_library_path | ( | const std::string & | library_name | ) |
Find a library located in the OS's specified environment variable for library paths.
The environment variable and file format per platform:
${LD_LIBRARY_PATH}
, lib{}.so
${DYLD_LIBRARY_PATH}
, lib{}.dyld
PATH%
, {}.dll
[in] | library_name | Name of the library to find. |
std::runtime_error | if an error is encountered when accessing environment variables. |
std::string rcpputils::path_for_library | ( | const std::string & | directory, |
const std::string & | library_name | ||
) |
Construct the filepath for a library given its directory, and checks that it exists.
[in] | directory | The directory that contains the library. |
[in] | library_name | Name of the library to find. |
std::string rcpputils::filename_for_library | ( | const std::string & | library_name | ) |
Create the filename corresponding to the library name.
[in] | library_name | Name of the library. |
std::string rcpputils::get_env_var | ( | const char * | env_var | ) |
Retrieve the value of the given environment variable if it exists, or "".
std::basic_string<CharT> rcpputils::join | ( | const ContainerT< ValueT, AllocatorT > & | container, |
const CharT * | delim | ||
) |
Join values in a container turned into strings by a given delimiter.
[in] | container | is a collection of values to be turned into string and joined. |
[in] | delim | is a delimiter to join values turned into strings. |
CharT | is the string character type. |
ValueT | is the container value type. |
AllocatorT | is the container allocator type. |
ContainerT | is the container template type. |
std::string rcpputils::get_executable_name | ( | ) |
Retrieve the current executable name.
This function portably retrieves the current program name and returns a copy of it.
This function is thread-safe.
std::runtime_error | on error |
scope_exit<CallableT> rcpputils::make_scope_exit | ( | CallableT && | callable | ) |
std::string rcpputils::get_platform_library_name | ( | std::string | library_name, |
bool | debug = false |
||
) |
Get the platform specific library name.
The maximum file name size is 1024 characters, if the input library_name is bigger than this value then the method throws an exception.
[in] | library_name | library base name (without prefix and extension) |
[in] | debug | if true the library will return a debug library name, otherwise it returns a normal library path |
std::runtime_error | if it's not able to create the library name |
void rcpputils::split | ( | const std::string & | input, |
char | delim, | ||
InsertIterator & | it, | ||
bool | skip_empty = false |
||
) |
Split a specified input into tokens using a delimiter and a type erased insert iterator.
The returned vector will contain the tokens split from the input
[in] | input | the input string to be split |
[in] | delim | the delimiter used to split the input string |
[in] | it | iterator pointing to a storage container |
[in] | skip_empty | remove empty strings from the return vector |
|
inline |
Split a specified input into tokens using a delimiter.
The returned vector will contain the tokens split from the input
[in] | input | the input string to be split |
[in] | delim | the delimiter used to split the input string |
[in] | skip_empty | remove empty strings from the return vector |