scc  2022.4.0
SystemC components library
util Namespace Reference

SCC common utilities. More...

Classes

struct  BitFieldMember
 bit field element More...
 
class  BitFieldArray
 array of bit field elements More...
 
class  delegate
 
class  delegate< R(A...)>
 a fast alternative to std::function More...
 
class  IoRedirector
 allows to capture the strings written to std::cout and std::cerr (MT-safe) More...
 
class  lz4c_steambuf
 
class  lz4d_streambuf
 
class  MT19937
 a Mersenne-Twister pseudo random number generator More...
 
class  pool_allocator
 a generic pool allocator singleton not being MT-safe More...
 
class  stl_pool_allocator
 
class  range_lut
 range based lookup table More...
 
class  sparse_array
 a sparse array suitable for large sizes More...
 
struct  thread_pool
 a simple thread pool More...
 
class  thread_syncronizer
 executes a function syncronized in another thread More...
 
class  watchdog
 a watch dog based on https://github.com/didenko/TimeoutGuard More...
 

Functions

template<typename T , typename... Args>
std::unique_ptr< T > make_unique (Args &&... args)
 
template<size_t N>
constexpr size_t find_first (std::bitset< N > &bits)
 
template<typename T >
leftmost_one (T n)
 
constexpr size_t uCount (uint32_t u)
 
constexpr size_t bit_count (uint32_t u)
 
template<typename T >
CONSTEXPR std::enable_if< std::is_integral< T >::value, T >::type rotl (T n, unsigned int c)
 
template<typename T >
CONSTEXPR std::enable_if< std::is_integral< T >::value, T >::type rotr (T n, unsigned int c)
 
CONSTEXPR unsigned ilog2 (uint32_t val)
 
CONSTEXPR bool hasOddParity (uint32_t u)
 
std::vector< std::string > split (const std::string &s, char separator)
 
template<typename Range , typename Value = typename Range::value_type>
std::string join (Range const &elements, char const *const delimiter)
 
template<typename Input , typename Output , typename Value = typename Output::value_type>
void split (char delimiter, Output &output, Input const &input)
 
std::string & ltrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 
std::string & rtrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 
std::string & trim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 
std::string str_tolower (std::string str)
 
std::string str_toupper (std::string str)
 
bool iequals (const std::string &a, const std::string &b)
 compare two string ignoring case More...
 
bool ends_with (std::string const &value, std::string const &ending)
 
std::string padded (std::string str, size_t width, bool show_ellipsis=true)
 pad a string to a given length by either cutting of the overflow or inserting an ellipsis More...
 
bool file_exists (const std::string &name)
 
template<class T >
dir_name (T const &path, T const &delims="/\\")
 
template<class T >
base_name (T const &path, T const &delims="/\\")
 
template<class T >
remove_ext (T const &filename)
 
std::string glob_to_regex (std::string val)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, range_lut< T > &lut)
 
std::string strprintf (const std::string format,...)
 allocate and print to a string buffer
 

Detailed Description

SCC common utilities.

Function Documentation

◆ base_name()

template<class T >
T util::base_name ( T const &  path,
T const &  delims = "/\\" 
)
inline

return file name portion of a given path (as string)

Parameters
path
delimsthe path delimiters to use
Returns

Definition at line 362 of file ities.h.

◆ dir_name()

template<class T >
T util::dir_name ( T const &  path,
T const &  delims = "/\\" 
)
inline

return directory name portion of a given path (as string)

Parameters
path
delimsthe path delimiters to use
Returns

Definition at line 352 of file ities.h.

◆ file_exists()

bool util::file_exists ( const std::string &  name)
inline

checks if a file exists

Parameters
namethe file name
Returns
true if file exists and can be opened

Definition at line 342 of file ities.h.

◆ glob_to_regex()

std::string util::glob_to_regex ( std::string  val)
inline

converts a globbing string into a regular expression

The globbing supports ?,*,**, and character classes ([a-z] as well as [!a-z]). '.' acts as hierarchy delimiter and is only matched with ** Regular expression must start with a carret ('^') so that it can be identified as regex.

Parameters
filename
Returns

Definition at line 385 of file ities.h.

◆ iequals()

bool util::iequals ( const std::string &  a,
const std::string &  b 
)
inline

compare two string ignoring case

Parameters
astring a to compare
bstring b to compare
Returns
true if the are equal otherwise false

Definition at line 296 of file ities.h.

◆ ilog2()

CONSTEXPR unsigned util::ilog2 ( uint32_t  val)
inline

get the log2 value fo an integer

Parameters
valthe value
Returns
the number of bit needed to hold the value val

Definition at line 163 of file ities.h.

◆ join()

template<typename Range , typename Value = typename Range::value_type>
std::string util::join ( Range const &  elements,
char const *const  delimiter 
)

note: delimiter cannot contain NUL characters

Definition at line 217 of file ities.h.

◆ ltrim()

std::string& util::ltrim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inline

trim the left side of a given string

Parameters
strthe string to trim
charsset of chars to trim away
Returns

Definition at line 249 of file ities.h.

◆ operator<<()

template<typename T >
std::ostream& util::operator<< ( std::ostream &  os,
range_lut< T > &  lut 
)

overloaded stream operator

Parameters
osthe output stream
lutthe lookup table to print
Returns
the stream

Definition at line 126 of file range_lut.h.

◆ padded()

std::string util::padded ( std::string  str,
size_t  width,
bool  show_ellipsis = true 
)
inline

pad a string to a given length by either cutting of the overflow or inserting an ellipsis

Parameters
strstring to adjust
widthof the targeted field
show_ellipsisuse ellipsis (...) when shortening
Returns
string with the given length

Definition at line 324 of file ities.h.

◆ remove_ext()

template<class T >
T util::remove_ext ( T const &  filename)
inline

return the base name (without extension) of a file name (as string)

Parameters
filename
Returns

Definition at line 371 of file ities.h.

◆ rtrim()

std::string& util::rtrim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inline

trim the right side of a given string

Parameters
strthe string to trim
charsset of chars to trim away
Returns

Definition at line 259 of file ities.h.

◆ split() [1/2]

template<typename Input , typename Output , typename Value = typename Output::value_type>
void util::split ( char  delimiter,
Output &  output,
Input const &  input 
)

note: imput is assumed to not contain NUL characters

Definition at line 233 of file ities.h.

◆ split() [2/2]

std::vector<std::string> util::split ( const std::string &  s,
char  separator 
)
inline

split a given string using specified separator

Parameters
sthe string to split
separatorthe separator char
Returns
vector of splitted strings

Definition at line 192 of file ities.h.

◆ str_tolower()

std::string util::str_tolower ( std::string  str)
inline

convert string to lower case

Parameters
strthe string to convert
Returns

Definition at line 275 of file ities.h.

◆ str_toupper()

std::string util::str_toupper ( std::string  str)
inline

convert string to upper case

Parameters
strthe string to convert
Returns

Definition at line 284 of file ities.h.

◆ trim()

std::string& util::trim ( std::string &  str,
const std::string &  chars = "\t\n\v\f\r " 
)
inline

trim the both sides of a given string

Parameters
strthe string to trim
charsset of chars to trim away
Returns

Definition at line 269 of file ities.h.