rcpputils  master
C++ API providing common utilities and data structures.
Namespaces | Classes | Enumerations | Functions
rcpputils Namespace Reference

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...
 
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 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...
 
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::stringsplit (const std::string &input, char delim, bool skip_empty=false)
 Split a specified input into tokens using a delimiter. More...
 

Enumeration Type Documentation

◆ endian

enum rcpputils::endian
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 

Function Documentation

◆ require_true()

void rcpputils::require_true ( bool  condition,
const std::string msg = "invalid argument passed" 
)
inline

Check that an argument condition passes.

Parameters
conditioncondition that is asserted to be true
msgmessage to pass to exception when condition is false
Exceptions
std::invalid_argumentif the condition is not met.

◆ check_true()

void rcpputils::check_true ( bool  condition,
const std::string msg = "check reported invalid state" 
)
inline

Check that a state condition passes.

Parameters
conditioncondition to check whether it is true or not
msgmessage to pass to exception when condition is false
Exceptions
rcpputils::IllegalStateExceptionif the condition is not met.

◆ assert_true()

void rcpputils::assert_true ( bool  condition,
const std::string msg = "assertion failed" 
)
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

Parameters
conditioncondition to check whether it's true or not
msgmessage to pass to exception when condition is not met.
Exceptions
rcpputils::AssertionExceptionif the macro NDEBUG is not set and the condition is not met.

◆ find_and_replace() [1/2]

template<class CharT , class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>>
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.

Parameters
[in]inputThe input string.
[in]findThe substring to replace.
[in]replaceThe string to substitute for each occurrence of find.
Returns
A copy of the input string with all instances of the string find replaced with the string replace.

◆ find_and_replace() [2/2]

template<typename InputT , typename FindT , typename ReplaceT >
auto rcpputils::find_and_replace ( InputT &&  input,
FindT &&  find,
ReplaceT &&  replace 
)

Find and replace all instances of a string with another string.

Parameters
[in]inputThe input string.
[in]findThe substring to replace.
[in]replaceThe string to substitute for each occurrence of find.
Returns
A copy of the input string with all instances of the string find replaced with the string replace.

◆ find_library_path()

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:

  • Linux: ${LD_LIBRARY_PATH}, lib{}.so
  • Apple: ${DYLD_LIBRARY_PATH}, lib{}.dyld
  • Windows: PATH%, {}.dll
Parameters
[in]library_nameName of the library to find.
Returns
The absolute filesystem path, including the appropriate prefix and extension
Exceptions
std::runtime_errorif an error is encountered when accessing environment variables.

◆ get_env_var()

std::string rcpputils::get_env_var ( const char *  env_var)

Retrieve the value of the given environment variable if it exists, or "".

◆ join()

template<typename CharT , typename ValueT , typename AllocatorT , template< typename T, class A > class ContainerT>
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.

Parameters
[in]containeris a collection of values to be turned into string and joined.
[in]delimis a delimiter to join values turned into strings.
Template Parameters
CharTis the string character type.
ValueTis the container value type.
AllocatorTis the container allocator type.
ContainerTis the container template type.
Returns
joined string

◆ get_executable_name()

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.

Returns
The program name.
Exceptions
std::runtime_erroron error

◆ get_platform_library_name()

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.

Parameters
[in]library_namelibrary base name (without prefix and extension)
[in]debugif true the library will return a debug library name, otherwise it returns a normal library path
Returns
platform specific library name
Exceptions
std::runtime_errorif it's not able to create the library name

◆ split() [1/2]

template<class InsertIterator , typename std::enable_if< std::is_same< InsertIterator &, decltype(std::declval< InsertIterator >().operator=(std::declval< std::string >()))>::value , ::type * = nullptr>
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

Parameters
[in]inputthe input string to be split
[in]delimthe delimiter used to split the input string
[in]ititerator pointing to a storage container
[in]skip_emptyremove empty strings from the return vector

◆ split() [2/2]

std::vector<std::string> rcpputils::split ( const std::string input,
char  delim,
bool  skip_empty = false 
)
inline

Split a specified input into tokens using a delimiter.

The returned vector will contain the tokens split from the input

Parameters
[in]inputthe input string to be split
[in]delimthe delimiter used to split the input string
[in]skip_emptyremove empty strings from the return vector
Returns
A vector of tokens.