arsenalgear-cpp
A library containing general purpose C++ utils.
Classes | Enumerations | Functions | Variables
agr Namespace Reference

Classes

class  savebuf
 Class used to store the output sent to an output stream. More...
 
struct  select_cout
 Struct used to define a way to template the choice of the "std::cout" object in order to be "std::cout" for "char" type or "std::wcout" for "wchar_t" type. More...
 
struct  select_cin
 Struct used to define a way to template the choice of the "std::cin" object in order to be "std::cin" for "char" type or "std::wcin" for "wchar_t" type. More...
 
struct  is_streamable
 Struct used to check if a type is a streamable or not, i.e. it has operator << overload or not. More...
 
struct  is_streamable< S, T, std::void_t< decltype(std::declval< S & >()<< std::declval< T >()) > >
 

Enumerations

enum class  ANSI { first , generic }
 

Functions

std::string getCommandOut (const char *command)
 Function used to get the output of a shell command. More...
 
std::string multi (const std::string &element, unsigned int n_times)
 Function used to multiply a string for n times. More...
 
std::vector< std::string > split_string (const std::string &input, const std::string &regex)
 Function used to split a string based on a certain reges. More...
 
template<typename TK , typename TV >
std::vector< TK > extract_map_keys (std::map< TK, TV > const &input_map)
 Function used to extract a vector of keys from a map. More...
 
template<typename TK , typename TV >
std::vector< TV > extract_map_elem (std::map< TK, TV > const &input_map)
 Function used to extract a vector of elements from a map. More...
 
template<typename T >
roundoff (T value, unsigned char prec)
 Function to round a floating point to n-th decimal place after comma. More...
 
template<typename T >
bool IsInBounds (T value, T low, T high)
 Function to check if a number lies in a certain bound or not. More...
 
template<typename T , std::size_t N>
constexpr bool is_pointer_to_const_char (T(&)[N])
 Function used to check if an input array is a pointer to const char. More...
 
template<typename T >
constexpr bool is_pointer_to_const_char (T &&)
 Function used to check if an input variable is a pointer to const char. More...
 
template<class T >
constexpr bool is_str (const T &obj)
 Function used to check if a variable is a string object (std::string, const char*, etc...). More...
 
template<typename Kind , typename... Kinds>
bool is_any ()
 Function used to check if a type is in a list or not. More...
 
template<typename T_err = std::runtime_error>
T_err except_error_func (const std::string &beg="", std::string var=nullptr, const std::string &end="")
 Function used to throw customized stdexception error. This function is extremely specific to my purposes and you can find examples usages in other my projects lik "osmanip" or "SAFD-algorithm". More...
 
template<typename T >
bool isFloatingPoint (const T &)
 Function to check if an expression (not a type) is a floating point or not. I know this function is almost useless, but it has been created for lazy purposes and since it is used in other projects it cannot be eliminated now in order to not break backward compatibility. More...
 
template<typename T >
one (const T &iterating_var)
 Function to find the incremented unit of a loop. Not easy to understand its purpose without context, but it is used to get the loop incremented unit in case of loops with floating-point indexes. See example usage in "osmanip" in progress bars "update" method. More...
 
template<class CharT >
std::conditional_t< std::is_same_v< CharT, char >, const std::basic_string< CharT > &, std::basic_string< CharT > > StringConverter (const std::string &input_str)
 Function used to convert an std::string into other string types (std::wstring etc...). If the argument is an std::string it will be returned without any modification. More...
 
template<typename T >
bool is_escape (const T &str, const ANSI &flag)
 This method is used to check if an input variable is an ANSI escape sequency or not. More...
 

Variables

template<typename T >
const T null_str = ""
 The string used to represent the null value. More...
 
template<typename T >
const T empty_space = " "
 The string used to represent the empty space. More...
 

Enumeration Type Documentation

◆ ANSI

enum agr::ANSI
strong
Enumerator
first 
generic 

Function Documentation

◆ except_error_func()

template<typename T_err = std::runtime_error>
T_err agr::except_error_func ( const std::string &  beg = "",
std::string  var = nullptr,
const std::string &  end = "" 
)
inline

Function used to throw customized stdexception error. This function is extremely specific to my purposes and you can find examples usages in other my projects lik "osmanip" or "SAFD-algorithm".

Template Parameters
T_errThe type of the exception error.
Parameters
begThe first part of the error message.
varThe variable to be inserted in the error message.
endThe last part of the error message.
Returns
T_err The modified exception error.

◆ extract_map_elem()

template<typename TK , typename TV >
std::vector<TV> agr::extract_map_elem ( std::map< TK, TV > const &  input_map)
inline

Function used to extract a vector of elements from a map.

Template Parameters
TKTemplate parameter of the map key.
TVTemplate parameter of the map element.
Parameters
input_mapThe input map.
Returns
std::vector<TV> The vector of elements.

◆ extract_map_keys()

template<typename TK , typename TV >
std::vector<TK> agr::extract_map_keys ( std::map< TK, TV > const &  input_map)
inline

Function used to extract a vector of keys from a map.

Template Parameters
TKTemplate parameter of the map key.
TVTemplate parameter of the map element.
Parameters
input_mapThe input map.
Returns
std::vector<TK> The vector of keys.

◆ getCommandOut()

std::string agr::getCommandOut ( const char *  command)

Function used to get the output of a shell command.

Parameters
commandThe command which output is required.
Returns
std::string The output of the command variable.

◆ is_any()

template<typename Kind , typename... Kinds>
bool agr::is_any ( )

Function used to check if a type is in a list or not.

Template Parameters
KindThe type to be checked.
KindsThe types to which the type is compared.
Returns
true If the type is in a list.
false Otherwise.

◆ is_escape()

template<typename T >
bool agr::is_escape ( const T &  str,
const ANSI flag 
)

This method is used to check if an input variable is an ANSI escape sequency or not.

Template Parameters
TTemplate type of the input variable.
Parameters
strThe input variable.
flagA flag which let to return different things with respect to its value. If flag = ANSI::first the ANSI is searched as the first substring of the str argument, otherwise, if flag = ANSI::generic the ANSI is searched as a substring inside the str argument.
Returns
true If the input variable is an ANSI escape sequency.
false Otherwise.

◆ is_pointer_to_const_char() [1/2]

template<typename T >
constexpr bool agr::is_pointer_to_const_char ( T &&  )
constexpr

Function used to check if an input variable is a pointer to const char.

Template Parameters
TThe input variable to be check.
Returns
true If the variable is a pointer to const char.
false Otherwise.

◆ is_pointer_to_const_char() [2/2]

template<typename T , std::size_t N>
constexpr bool agr::is_pointer_to_const_char ( T(&)  [N])
constexpr

Function used to check if an input array is a pointer to const char.

Template Parameters
TThe input array to be check.
NThe dimension of the array.
Returns
true If the array is a pointer to const char.
false Otherwise.

◆ is_str()

template<class T >
constexpr bool agr::is_str ( const T &  obj)
constexpr

Function used to check if a variable is a string object (std::string, const char*, etc...).

Template Parameters
TThe type of the input variable.
Parameters
objThe input variable.
Returns
true If the variable is a string object.
false Otherwise.

◆ isFloatingPoint()

template<typename T >
bool agr::isFloatingPoint ( const T &  )
inline

Function to check if an expression (not a type) is a floating point or not. I know this function is almost useless, but it has been created for lazy purposes and since it is used in other projects it cannot be eliminated now in order to not break backward compatibility.

Template Parameters
TThe type of the expression.
Returns
bool True if the expression is a floating point, false otherwise.

◆ IsInBounds()

template<typename T >
bool agr::IsInBounds ( value,
low,
high 
)
inline

Function to check if a number lies in a certain bound or not.

Template Parameters
TThe Type of the variable to be checked.
Parameters
valueThe variable to be checked.
lowThe lower bound.
highThe upper bound.
Returns
bool True if the variable lies in the bound, false otherwise.

◆ multi()

std::string agr::multi ( const std::string &  element,
unsigned int  n_times 
)

Function used to multiply a string for n times.

Parameters
elementThe string to be multiplied.
n_timesThe times for the string multiplication.
Returns
std::string The multiplied string.

◆ one()

template<typename T >
T agr::one ( const T &  iterating_var)
inline

Function to find the incremented unit of a loop. Not easy to understand its purpose without context, but it is used to get the loop incremented unit in case of loops with floating-point indexes. See example usage in "osmanip" in progress bars "update" method.

Template Parameters
TThe type of the iterating variable of the loop.
Parameters
iterating_varThe iterating variable of the loop.
Returns
T The incremented unit of the loop.

◆ roundoff()

template<typename T >
T agr::roundoff ( value,
unsigned char  prec 
)
inline

Function to round a floating point to n-th decimal place after comma.

Template Parameters
TThe Type of the variable to be rounded.
Parameters
valueThe variable to be rounded
precPrecision of the rounding.
Returns
T The rounded variable.

◆ split_string()

std::vector< std::string > agr::split_string ( const std::string &  input,
const std::string &  regex 
)

Function used to split a string based on a certain reges.

Parameters
inputThe input string.
regexThe regex.
Returns
std::vector<std::string> The collection of string elements splitted by the regex.

◆ StringConverter()

template<class CharT >
std::conditional_t<std::is_same_v<CharT, char>, const std::basic_string<CharT>&, std::basic_string<CharT> > agr::StringConverter ( const std::string &  input_str)

Function used to convert an std::string into other string types (std::wstring etc...). If the argument is an std::string it will be returned without any modification.

Template Parameters
CharTThe char type (char, wchar_t...) to which the string is converted..
Parameters
input_strThe input std::string object.
Returns
std::conditional_t<std::is_same_v<CharT, char>, const std::basic_string<CharT>&, std::basic_string<CharT>> The converted string object.

Variable Documentation

◆ empty_space

template<typename T >
const T agr::empty_space = " "
inline

The string used to represent the empty space.

◆ null_str

template<typename T >
const T agr::null_str = ""
inline

The string used to represent the null value.