Conscience Core
Namespaces | Classes | Functions | Variables
conscience_utils Namespace Reference

Namespaces

 async
 
 Cartography
 
 crypto
 
 detection_logger
 
 file_system
 
 geom
 
 JSON
 
 logging
 
 mutexutils
 
 systemutils
 
 untar
 

Classes

class  CannotParseEnumException
 
class  CscException
 
struct  DoubleSizedArray
 
struct  FloatSizedArray
 
struct  IsStdFixedArrayStruct
 
struct  IsStdFixedArrayStruct< std::array< T, I > >
 
struct  PointeeType
 
struct  PointeeType< const U * >
 
struct  PointeeType< const U *const >
 
struct  PointeeType< U * >
 
struct  PointeeType< U *const >
 
struct  SharedPtrTraits
 
struct  SharedPtrTraits< std::shared_ptr< U > >
 

Functions

string getLocalMacAddressAsHexString ()
 
optional< string > resolveReachableIpAddress ()
 returns VPN address or public address, if found More...
 
optional< string > resolveReachableLocalIpAddress ()
 returns local address, if found More...
 
string getLocalIpAddress ()
 
string trim (const string &str, const string &trimmedChars)
 
string floatArrayToString (float *floatArray, int size)
 
string doubleArrayToString (double *doubleArray, int size)
 
string intArrayToString (int *intArray, int size)
 
string boolToString (bool value)
 
bool replaceInString (string &str, const string &from, const string &to, bool onlyFirst)
 
bool replaceAllInString (string &str, const string &from, const string &to)
 
void removeSpacesInString (string &str)
 
string toStringCurrentTimeWithMillis ()
 
string toStringDateAndTime ()
 
vector< float > * parseFloatList (string input, char separator)
 
vector< int > * parseIntList (string input, char separator)
 
map< string, string > parseMap (string input, const string &entriesSeparator, const string &keyValueSeparator, bool removeGlobalBracketIfExist)
 
vector< string > * splitString (const string &inputString, const string &delimiter, bool escapeDelimiterWithBackslash)
 
system_clock::time_point timepointWithTime (optional< int > hours, optional< int > minutes, optional< int > seconds, system_clock::time_point timePoint)
 
unsigned long long timestampWithTime (optional< int > hours, optional< int > minutes, optional< int > seconds, system_clock::time_point timePoint)
 
unsigned long long toMillis (system_clock::time_point timePoint)
 
unsigned long long diffMillis (system_clock::time_point timePoint1, system_clock::time_point timePoint2)
 
unsigned long long nowMillis ()
 
system_clock::time_point toTimePoint (unsigned long long timestampMillis)
 
bool stringIsNumber (const string &str)
 
char * copyStringChars (const string &str)
 
bool stringsAreEqualCaseInsensitive (const string &a, const string &b)
 
bool findSubString (const string str, const string sub)
 
int randomInt (int lowerBound, int upperBound)
 
string randomUUID ()
 
string randomString (size_t length, const string &allowedChars)
 
float randomFloat (float aBound, float bBound)
 
char * longToCharArray (long value)
 
char * concatenateCharArray (const char *a, const char *b)
 
optional< int > parseInt (const string &inputString)
 
optional< double > parseDouble (const string &inputString)
 
float inchToCentimeter (float inchValue)
 
double inchToCentimeter (double inchValue)
 
string toStringTimestampMillis (unsigned long long timestampInMs, string format)
 
string toLowerCase (string &str)
 
string toUpperCase (string &str)
 
bool startsWithIgnoreCase (const string &str, const string &searchedPrefix)
 
string snakeCaseToPascalCase (const string &snakeCaseString)
 
bool doublesEqual (double value1, double value2, double epsilon)
 
bool floatsEqual (float value1, float value2, float epsilon)
 
bool stringContainsIgnoreCase (const string &theString, const string &searchedToken)
 
string truncateString (const string &input, size_t maxSize)
 
optional< any > getMapValueByPath (const map< string, any > &data, const string &path)
 
string getClassName (const type_info &paramsClass, bool withNamespace)
 
string getStackTrace ()
 
string stringPadLeft (const string &input, size_t totalLength, char padChar)
 
string stringPadRight (const string &input, size_t totalLength, char padChar)
 
string timePointToString (system_clock::time_point point)
 
string timePointToString (const std::chrono::steady_clock::time_point &tp)
 
void stringRemoveToken (string &s, const std::string_view &token)
 
template<class T >
string toStringOrNullString (T *object)
 
template<class T >
string toStringOrNullString (T object)
 
template<class T >
string vectorToString (const vector< T > &vector, const char *separator=",")
 
template<class T >
vector< const T * > * vectorOfPointerToConst (vector< T * > *theVector)
 
template<class T >
vector< const T * > & vectorOfPointerToConst (vector< T * > &&theVector)
 
template<class T >
vector< const T * > & vectorOfPointerToConst (vector< T * > &theVector)
 
template<class T >
const vector< const T * > & vectorOfPointerToConst (const vector< T * > &theVector)
 
template<class T >
vector< T > vectorsConcat (const vector< T > &vector1, const vector< T > &vector2)
 
template<class T >
vector< T * > * vectorCloneDeep (const vector< T * > *source)
 
template<class T >
void vectorPushIfMissing (vector< T > &vector, T value)
 
template<class T , class R >
vector< R > vectorTransform (const vector< T > &source, function< R(const T &item)> transformFunction)
 
template<class T >
std::vector< T >::iterator vectorIndexOf (const vector< T > &vector, T value)
 
template<class T >
bool vectorContains (const vector< T > &vector, T value)
 
template<class T >
vector< T > & vectorRemoveIf (vector< T > &theVector, function< bool(const T &)> predicate)
 
template<class T >
vector< T > & vectorRemove (vector< T > &theVector, const T &item)
 
template<class K , class V >
const optional< K > keyOfValueInMap (const map< K, V > *map, V searchedValue)
 
template<class TKey , class TValue >
bool areMapsEqual (const map< TKey, TValue > &map1, const map< TKey, TValue > &map2)
 
template<class TKey , class TValue >
vector< TKey > mapKeys (const map< TKey, TValue > &theMap)
 
template<class TKey , class TValue >
vector< TValue > mapValuesConst (const map< TKey, const TValue > &theMap)
 
template<class TKey , class TValue >
vector< TValue > mapValues (const map< TKey, TValue > &theMap)
 
template<class TKey , class TValue >
vector< TValue * > mapValues (const map< TKey, TValue * > &theMap)
 
template<class TKey , class TValue >
void mapEraseIfExist (std::map< TKey, TValue > &theMap, const TKey &key)
 
template<class K , class V >
string mapToString (const map< K, V > &theMap, const string &entriesSeparator=",", const string &keyValueSeparator="=")
 
template<typename K , typename V >
bool equals (const map< K, V > &map1, const map< K, V > &map2)
 
template<typename T >
enforceBounds (T valueToBound, T min, T max)
 
template<typename T >
string to_string_precision (const T value, const int n=2)
 
template<typename T >
string to_string_precision_float (const T value)
 
template<typename T >
string to_string_precision_double (const T value)
 
template<typename T >
string to_string_precision_lngLat (const T value)
 
template<typename T >
constexpr size_t size_of ()
 
template<typename T >
void pushInBytes (char *bytes, int &index, T data)
 
template<typename T >
findMinValue (T *array, size_t size)
 
template<typename T >
findMaxValue (T *array, size_t size)
 
template<typename T >
findMinRowValueFromArray (T **array, size_t size, int row)
 
template<typename T >
findMaxRowValueFromArray (T **array, size_t size, int row)
 
template<typename T >
vectorGetRandomElement (const std::vector< T > *vec)
 
string getClassName (const std::type_info &paramsClass, bool withNamespace)
 

Variables

template<class TTestedType , class TPointee >
concept IsPointerOf = std::is_same_v<TTestedType, const TPointee *> || std::is_same_v<TTestedType, TPointee *> || std::is_same_v<TTestedType, std::shared_ptr<const TPointee>> || std::is_same_v<TTestedType, std::shared_ptr<TPointee>>
 
template<class , template< class... > class>
constexpr bool IsTemplatedType = false
 
template<template< class... > class T, class... Args>
constexpr bool IsTemplatedType< T< Args... >, T > = true
 
template<typename T >
concept IsOptional = IsTemplatedType<T, std::optional>
 
template<typename T >
concept IsVector = IsTemplatedType<T, std::vector>
 
template<class T >
constexpr bool IsStdFixedArray = IsStdFixedArrayStruct<T>::value
 
template<typename T >
concept IsMap = IsTemplatedType<T, std::map>
 
template<typename T >
concept IsEnum = std::is_enum_v<T>
 
template<typename T >
concept IsStarPointer = PointeeType<std::remove_cvref_t<T>>::isPointer
 
template<typename T >
concept IsSharedPointer = SharedPtrTraits<std::remove_cvref_t<T>>::isSharedPtr
 
static const string ALL_SPACES_STRING = " \n\t\r"
 
const string ALPHABETICAL_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
const string ALPHANUMERIC_CHARS = ALPHABETICAL_CHARS + "0123456789"
 

Function Documentation

◆ areMapsEqual()

template<class TKey , class TValue >
bool conscience_utils::areMapsEqual ( const map< TKey, TValue > &  map1,
const map< TKey, TValue > &  map2 
)

◆ boolToString()

string conscience_utils::boolToString ( bool  value)

◆ concatenateCharArray()

char * conscience_utils::concatenateCharArray ( const char *  a,
const char *  b 
)

◆ copyStringChars()

char * conscience_utils::copyStringChars ( const string &  str)

◆ diffMillis()

unsigned long long conscience_utils::diffMillis ( system_clock::time_point  timePoint1,
system_clock::time_point  timePoint2 
)

◆ doubleArrayToString()

string conscience_utils::doubleArrayToString ( double *  doubleArray,
int  size 
)

◆ doublesEqual()

bool conscience_utils::doublesEqual ( double  value1,
double  value2,
double  epsilon 
)

◆ enforceBounds()

template<typename T >
T conscience_utils::enforceBounds ( valueToBound,
min,
max 
)

◆ equals()

template<typename K , typename V >
bool conscience_utils::equals ( const map< K, V > &  map1,
const map< K, V > &  map2 
)

◆ findMaxRowValueFromArray()

template<typename T >
T conscience_utils::findMaxRowValueFromArray ( T **  array,
size_t  size,
int  row 
)

◆ findMaxValue()

template<typename T >
T conscience_utils::findMaxValue ( T *  array,
size_t  size 
)

◆ findMinRowValueFromArray()

template<typename T >
T conscience_utils::findMinRowValueFromArray ( T **  array,
size_t  size,
int  row 
)

◆ findMinValue()

template<typename T >
T conscience_utils::findMinValue ( T *  array,
size_t  size 
)

◆ findSubString()

bool conscience_utils::findSubString ( const string  str,
const string  sub 
)

◆ floatArrayToString()

string conscience_utils::floatArrayToString ( float *  floatArray,
int  size 
)

◆ floatsEqual()

bool conscience_utils::floatsEqual ( float  value1,
float  value2,
float  epsilon 
)

◆ getClassName() [1/2]

string conscience_utils::getClassName ( const std::type_info &  paramsClass,
bool  withNamespace 
)

◆ getClassName() [2/2]

string conscience_utils::getClassName ( const type_info &  paramsClass,
bool  withNamespace 
)

◆ getLocalIpAddress()

string conscience_utils::getLocalIpAddress ( )

◆ getLocalMacAddressAsHexString()

string conscience_utils::getLocalMacAddressAsHexString ( )

◆ getMapValueByPath()

optional< any > conscience_utils::getMapValueByPath ( const map< string, any > &  data,
const string &  path 
)
Parameters
pathdot separated path, for instance: getMapValueByPath(myMap, "position.x") will select value at key "position" in data, and expect it to be a submap, in which there is a key "x"

◆ getStackTrace()

string conscience_utils::getStackTrace ( )
Returns
Retrieves stack trace if system allows it, otherwise a default error string

◆ inchToCentimeter() [1/2]

double conscience_utils::inchToCentimeter ( double  inchValue)

◆ inchToCentimeter() [2/2]

float conscience_utils::inchToCentimeter ( float  inchValue)

◆ intArrayToString()

string conscience_utils::intArrayToString ( int *  intArray,
int  size 
)

◆ keyOfValueInMap()

template<class K , class V >
const optional<K> conscience_utils::keyOfValueInMap ( const map< K, V > *  map,
searchedValue 
)

return key of searchedValue in given map, or null if not found

◆ longToCharArray()

char * conscience_utils::longToCharArray ( long  value)

◆ mapEraseIfExist()

template<class TKey , class TValue >
void conscience_utils::mapEraseIfExist ( std::map< TKey, TValue > &  theMap,
const TKey &  key 
)
inline

Erase from the map only if key exist

◆ mapKeys()

template<class TKey , class TValue >
vector<TKey> conscience_utils::mapKeys ( const map< TKey, TValue > &  theMap)

Gets all values in given map

◆ mapToString()

template<class K , class V >
string conscience_utils::mapToString ( const map< K, V > &  theMap,
const string &  entriesSeparator = ",",
const string &  keyValueSeparator = "=" 
)

Converts given map to a printable string (debug format, key1=value1, key2=value2

◆ mapValues() [1/2]

template<class TKey , class TValue >
vector<TValue *> conscience_utils::mapValues ( const map< TKey, TValue * > &  theMap)

Gets all values in given map

◆ mapValues() [2/2]

template<class TKey , class TValue >
vector<TValue> conscience_utils::mapValues ( const map< TKey, TValue > &  theMap)

Gets all values in given map

◆ mapValuesConst()

template<class TKey , class TValue >
vector<TValue> conscience_utils::mapValuesConst ( const map< TKey, const TValue > &  theMap)

Gets all values in given map

◆ nowMillis()

unsigned long long conscience_utils::nowMillis ( )

◆ parseDouble()

optional< double > conscience_utils::parseDouble ( const string &  inputString)

◆ parseFloatList()

vector< float > * conscience_utils::parseFloatList ( string  input,
char  separator 
)

◆ parseInt()

optional< int > conscience_utils::parseInt ( const string &  inputString)

◆ parseIntList()

vector< int > * conscience_utils::parseIntList ( string  input,
char  separator 
)

◆ parseMap()

map< string, string > conscience_utils::parseMap ( string  input,
const string &  entriesSeparator,
const string &  keyValueSeparator,
bool  removeGlobalBracketIfExist 
)

◆ pushInBytes()

template<typename T >
void conscience_utils::pushInBytes ( char *  bytes,
int &  index,
data 
)

◆ randomFloat()

float conscience_utils::randomFloat ( float  aBound,
float  bBound 
)

Returns a random float between aBound and bBound inclusive

◆ randomInt()

int conscience_utils::randomInt ( int  lowerBound,
int  upperBound 
)

Returns a random int between aBound and bBound inclusive

◆ randomString()

string conscience_utils::randomString ( size_t  length,
const string &  allowedChars 
)

◆ randomUUID()

string conscience_utils::randomUUID ( )

◆ removeSpacesInString()

void conscience_utils::removeSpacesInString ( string &  str)

removes all kind of spaces from [str]

◆ replaceAllInString()

bool conscience_utils::replaceAllInString ( string &  str,
const string &  from,
const string &  to 
)

Replace all occurrences of [from] in [str] with [to].

◆ replaceInString()

bool conscience_utils::replaceInString ( string &  str,
const string &  from,
const string &  to,
bool  onlyFirst = true 
)

Replace occurence(s) of [from] in [str] with [to]. /!\ If [onlyFirst] is true, will replace only first occurence

◆ resolveReachableIpAddress()

optional< string > conscience_utils::resolveReachableIpAddress ( )

returns VPN address or public address, if found

◆ resolveReachableLocalIpAddress()

optional< string > conscience_utils::resolveReachableLocalIpAddress ( )

returns local address, if found

◆ size_of()

template<typename T >
constexpr size_t conscience_utils::size_of ( )
constexpr

◆ snakeCaseToPascalCase()

string conscience_utils::snakeCaseToPascalCase ( const string &  snakeCaseString)
Returns
PascalCaseString from a SNAKE_CASE_STRING

◆ splitString()

vector< string > * conscience_utils::splitString ( const string &  inputString,
const string &  delimiter,
bool  escapeDelimiterWithBackslash 
)

◆ startsWithIgnoreCase()

bool conscience_utils::startsWithIgnoreCase ( const string &  str,
const string &  searchedPrefix 
)

◆ stringContainsIgnoreCase()

bool conscience_utils::stringContainsIgnoreCase ( const string &  theString,
const string &  searchedToken 
)

◆ stringIsNumber()

bool conscience_utils::stringIsNumber ( const string &  str)

◆ stringPadLeft()

string conscience_utils::stringPadLeft ( const string &  input,
size_t  totalLength,
char  padChar 
)

◆ stringPadRight()

string conscience_utils::stringPadRight ( const string &  input,
size_t  totalLength,
char  padChar 
)

◆ stringRemoveToken()

void conscience_utils::stringRemoveToken ( string &  s,
const std::string_view &  token 
)

◆ stringsAreEqualCaseInsensitive()

bool conscience_utils::stringsAreEqualCaseInsensitive ( const string &  a,
const string &  b 
)

◆ timePointToString() [1/2]

string conscience_utils::timePointToString ( const std::chrono::steady_clock::time_point &  tp)

◆ timePointToString() [2/2]

string conscience_utils::timePointToString ( system_clock::time_point  point)

◆ timepointWithTime()

system_clock::time_point conscience_utils::timepointWithTime ( optional< int >  hours,
optional< int >  minutes,
optional< int >  seconds,
system_clock::time_point  timePoint 
)

◆ timestampWithTime()

unsigned long long conscience_utils::timestampWithTime ( optional< int >  hours,
optional< int >  minutes,
optional< int >  seconds,
system_clock::time_point  timePoint 
)

◆ to_string_precision()

template<typename T >
string conscience_utils::to_string_precision ( const T  value,
const int  n = 2 
)
inline

◆ to_string_precision_double()

template<typename T >
string conscience_utils::to_string_precision_double ( const T  value)
inline

◆ to_string_precision_float()

template<typename T >
string conscience_utils::to_string_precision_float ( const T  value)
inline

◆ to_string_precision_lngLat()

template<typename T >
string conscience_utils::to_string_precision_lngLat ( const T  value)
inline

◆ toLowerCase()

string conscience_utils::toLowerCase ( string &  str)

◆ toMillis()

unsigned long long conscience_utils::toMillis ( system_clock::time_point  timePoint)

◆ toStringCurrentTimeWithMillis()

string conscience_utils::toStringCurrentTimeWithMillis ( )

display time with milliseconds (3 digits) in the following format : MM-DD-YY HH:M:S.ms

◆ toStringDateAndTime()

string conscience_utils::toStringDateAndTime ( )

display time in the following format : YYMMDD_HhMmSs_

◆ toStringOrNullString() [1/2]

template<class T >
string conscience_utils::toStringOrNullString ( T *  object)

◆ toStringOrNullString() [2/2]

template<class T >
string conscience_utils::toStringOrNullString ( object)

◆ toStringTimestampMillis()

string conscience_utils::toStringTimestampMillis ( unsigned long long  timestampInMs,
string  format 
)
Parameters
formatput time format used to stringified the date

◆ toTimePoint()

system_clock::time_point conscience_utils::toTimePoint ( unsigned long long  timestampMillis)

◆ toUpperCase()

string conscience_utils::toUpperCase ( string &  str)

◆ trim()

string conscience_utils::trim ( const string &  str,
const string &  trimmedChars 
)

◆ truncateString()

string conscience_utils::truncateString ( const string &  input,
size_t  maxSize 
)

◆ vectorCloneDeep()

template<class T >
vector<T *>* conscience_utils::vectorCloneDeep ( const vector< T * > *  source)

◆ vectorContains()

template<class T >
bool conscience_utils::vectorContains ( const vector< T > &  vector,
value 
)
inline

◆ vectorGetRandomElement()

template<typename T >
T conscience_utils::vectorGetRandomElement ( const std::vector< T > *  vec)

◆ vectorIndexOf()

template<class T >
std::vector<T>::iterator conscience_utils::vectorIndexOf ( const vector< T > &  vector,
value 
)
inline

◆ vectorOfPointerToConst() [1/4]

template<class T >
const vector<const T *>& conscience_utils::vectorOfPointerToConst ( const vector< T * > &  theVector)

◆ vectorOfPointerToConst() [2/4]

template<class T >
vector<const T *>& conscience_utils::vectorOfPointerToConst ( vector< T * > &&  theVector)

◆ vectorOfPointerToConst() [3/4]

template<class T >
vector<const T *>& conscience_utils::vectorOfPointerToConst ( vector< T * > &  theVector)

◆ vectorOfPointerToConst() [4/4]

template<class T >
vector<const T *>* conscience_utils::vectorOfPointerToConst ( vector< T * > *  theVector)

◆ vectorPushIfMissing()

template<class T >
void conscience_utils::vectorPushIfMissing ( vector< T > &  vector,
value 
)
inline

◆ vectorRemove()

template<class T >
vector<T>& conscience_utils::vectorRemove ( vector< T > &  theVector,
const T &  item 
)
inline

use with : vectorRemove(myVector, item);

◆ vectorRemoveIf()

template<class T >
vector<T>& conscience_utils::vectorRemoveIf ( vector< T > &  theVector,
function< bool(const T &)>  predicate 
)
inline

use with : vectorRemoveIf(myVector, [&](const item &myItem) { return ...; });

◆ vectorsConcat()

template<class T >
vector<T> conscience_utils::vectorsConcat ( const vector< T > &  vector1,
const vector< T > &  vector2 
)

◆ vectorToString()

template<class T >
string conscience_utils::vectorToString ( const vector< T > &  vector,
const char *  separator = "," 
)

◆ vectorTransform()

template<class T , class R >
vector<R> conscience_utils::vectorTransform ( const vector< T > &  source,
function< R(const T &item)>  transformFunction 
)
inline

Maps elements of a vector using given transform function. vector of T will be transformed to vector of R using R(T)

Variable Documentation

◆ ALL_SPACES_STRING

const string conscience_utils::ALL_SPACES_STRING = " \n\t\r"
inlinestatic

◆ ALPHABETICAL_CHARS

const string conscience_utils::ALPHABETICAL_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

◆ ALPHANUMERIC_CHARS

const string conscience_utils::ALPHANUMERIC_CHARS = ALPHABETICAL_CHARS + "0123456789"

◆ IsEnum

template<typename T >
concept conscience_utils::IsEnum = std::is_enum_v<T>

◆ IsMap

template<typename T >
concept conscience_utils::IsMap = IsTemplatedType<T, std::map>

◆ IsOptional

template<typename T >
concept conscience_utils::IsOptional = IsTemplatedType<T, std::optional>

◆ IsPointerOf

template<class TTestedType , class TPointee >
concept conscience_utils::IsPointerOf = std::is_same_v<TTestedType, const TPointee *> || std::is_same_v<TTestedType, TPointee *> || std::is_same_v<TTestedType, std::shared_ptr<const TPointee>> || std::is_same_v<TTestedType, std::shared_ptr<TPointee>>

true if tested type is any kind of pointer to TPointee or const TPointee

◆ IsSharedPointer

template<typename T >
concept conscience_utils::IsSharedPointer = SharedPtrTraits<std::remove_cvref_t<T>>::isSharedPtr

◆ IsStarPointer

template<typename T >
concept conscience_utils::IsStarPointer = PointeeType<std::remove_cvref_t<T>>::isPointer

◆ IsStdFixedArray

template<class T >
constexpr bool conscience_utils::IsStdFixedArray = IsStdFixedArrayStruct<T>::value
constexpr

◆ IsTemplatedType

template<class , template< class... > class>
constexpr bool conscience_utils::IsTemplatedType = false
inlineconstexpr

returns false if given template type is not of requested type<with args>

◆ IsTemplatedType< T< Args... >, T >

template<template< class... > class T, class... Args>
constexpr bool conscience_utils::IsTemplatedType< T< Args... >, T > = true
inlineconstexpr

returns true if given template type T is of requested type<with Args>

◆ IsVector

template<typename T >
concept conscience_utils::IsVector = IsTemplatedType<T, std::vector>