![]() |
UtilsLite
Utilities for C++ programming
|
Namespaces | |
namespace | Table |
namespace | tp |
Classes | |
class | AABBtree |
A class representing an axis-aligned bounding box tree. More... | |
class | AlgoBracket |
Class for solving \( f(x)=0 \) without the usew of derivative. More... | |
class | AlgoHNewton |
Class for solving \( f(x)=0 \) without the usew of derivative. More... | |
class | AlgoHNewton_base_fun |
Abstract base class for defining mathematical functions used in the zero search algorithm. More... | |
class | at_scope_exit_impl |
class | Barrier |
class | BinarySearch |
class | Box2D |
A class representing a 2D axis-aligned bounding box. More... | |
class | Bracket_base_fun |
Abstract base class for defining mathematical functions used in the Bracket search algorithm. More... | |
class | Console |
Class to handle console output with different styles and levels. More... | |
class | HJPatternSearch |
Class for implementing the Hooke-Jeeves Pattern Search Algorithm. More... | |
class | Malloc |
Class for dynamic memory allocation of objects. More... | |
class | MallocFixed |
Class for fixed-size memory allocation of objects. More... | |
class | mex_class_handle |
A class template that manages a C++ object for use with MATLAB. More... | |
class | NelderMead |
Implements the Nelder-Mead optimization algorithm for nonlinear optimization problems. More... | |
class | Point2D |
A class representing a 2D point in space. More... | |
class | Poly |
Specializes the Eigen::Matrix class to represent and manipulate polynomials. More... | |
class | Polygon2D |
A class representing a 2D polygon using a dynamic matrix of vertices. More... | |
class | Quaternion |
Implement some operationn on quaternion. More... | |
class | Runtime_Error |
Custom runtime error class for handling runtime exceptions. More... | |
class | Runtime_TraceError |
A custom exception class that captures and stores a backtrace on error. More... | |
class | Segment2D |
A class representing a 2D line segment defined by two endpoints. More... | |
class | SHA3 |
SHA-3 winning hash algorithm Keccak. More... | |
class | SimpleSemaphore |
class | SpinLock |
class | SpinLock_barrier |
class | Sturm |
Class for managing and computing the Sturm sequence associated with a polynomial. More... | |
class | ThreadPool0 |
Fake thread pool class. More... | |
class | ThreadPool1 |
Manages a pool of worker threads for concurrent task execution. More... | |
class | ThreadPool2 |
Manages a pool of worker threads for concurrent task execution. More... | |
class | ThreadPool3 |
A thread pool for concurrent task execution with worker management. More... | |
class | ThreadPool4 |
A thread pool for concurrent task execution with worker management. More... | |
class | ThreadPool5 |
A thread pool for concurrent task execution with worker management. More... | |
class | ThreadPoolBase |
class | TicToc |
A class for timing code execution. More... | |
class | Tokenizer |
A utility class for tokenizing strings. More... | |
class | Triangle2D |
A class representing a 2D triangle defined by three vertices. More... | |
class | Trichotomy |
Class for minimize the function \( f(x) \) without the usew of derivative. More... | |
class | Trichotomy_base_fun |
Abstract base class for defining mathematical functions used in the minimization algorithm. More... | |
class | TVD |
Class for performing Total Variation Denoising (TVD) on 1D signals. More... | |
class | WaitWorker |
class | WorkerLoop |
class | Zeros |
Class for solving the equation \( f(x) = 0 \) using various numerical methods. More... | |
class | Zeros_base_fun |
Abstract base class for defining mathematical functions used in root-finding algorithms. More... | |
Typedefs | |
using | istream_type = std::basic_istream<char> |
Type for input stream. | |
using | ostream_type = std::basic_ostream<char> |
Type for output stream. | |
using | string = std::string |
Type for string. | |
Functions | |
string | basename (string_view filename) |
Get the base name of a file. | |
string | out_bytes (size_t nb) |
Utility function to convert byte size into a human-readable format. | |
void | mex_error_message (string_view msg) |
Sends an error message to MATLAB. | |
bool | mex_is_scalar (mxArray const *arg, string_view msg) |
Checks if the input argument is a scalar. | |
double | mex_get_scalar_value (mxArray const *arg, string_view msg) |
Gets the scalar value from the input argument. | |
bool | mex_get_bool (mxArray const *arg, string_view msg) |
Gets a boolean value from the input argument. | |
int64_t | mex_get_int64 (mxArray const *arg, string_view msg) |
Gets a 64-bit integer value from the input argument. | |
double const * | mex_vector_pointer (mxArray const *arg, mwSize &sz, string_view msg) |
Gets a pointer to a vector from the input argument. | |
double const * | mex_matrix_pointer (mxArray const *arg, mwSize &nr, mwSize &nc, string_view msg) |
Gets a pointer to a matrix from the input argument. | |
void | mex_set_scalar_value (mxArray *&arg, double value) |
Sets a scalar value in the output argument. | |
void | mex_set_scalar_int32 (mxArray *&arg, int32_t value) |
Sets a scalar integer value in the output argument. | |
void | mex_set_scalar_int64 (mxArray *&arg, int64_t value) |
Sets a scalar 64-bit integer value in the output argument. | |
void | mex_set_scalar_bool (mxArray *&arg, bool value) |
Sets a boolean value in the output argument. | |
int32_t * | mex_create_matrix_int32 (mxArray *&arg, mwSize nrow, mwSize ncol) |
Creates a numeric matrix of type int32 and returns a pointer to its data. | |
int64_t * | mex_create_matrix_int64 (mxArray *&arg, mwSize nrow, mwSize ncol) |
Creates a numeric matrix of type int64 and returns a pointer to its data. | |
double * | mex_create_matrix_value (mxArray *&arg, mwSize nrow, mwSize ncol) |
Creates a numeric matrix of type double and returns a pointer to its data. | |
template<typename R, typename I> | |
int | mex_create_sparse_matrix (size_t nnz, size_t nrows, size_t ncols, I i_rows[], I j_cols[], R vals[], mxArray *arg_out[]) |
Creates a sparse matrix in MATLAB format. | |
void | mex_create_string_cell_array (mxArray *&arg, vector< string > const &str_vec) |
Creates a MATLAB cell array and fills it with a vector of C++ strings. | |
template<typename base> | |
mxArray * | mex_convert_ptr_to_mx (base *ptr) |
Converts a pointer to a mex_class_handle into a MATLAB mxArray. | |
template<typename base> | |
mex_class_handle< base > * | mex_convert_mx_to_handle_ptr (mxArray const *in) |
Converts a MATLAB mxArray back to a mex_class_handle pointer. | |
template<typename base> | |
base * | mex_convert_mx_to_ptr (mxArray const *in) |
Converts a MATLAB mxArray to a pointer of the wrapped C++ object. | |
template<typename base> | |
void | mex_destroy_object (mxArray const *&in) |
Destroys the object wrapped by the mex_class_handle. | |
template<typename T> | |
T | NaN () |
template<typename T> | |
T | Inf () |
template<typename T> | |
T | machine_eps () |
template<typename T> | |
T | sqrt_machine_eps () |
template<typename T> | |
T | maximum_value () |
template<typename T> | |
T | minimum_value () |
bool | found_NaN (double const *pv, int DIM) |
bool | found_NaN (float const *pv, int DIM) |
void | check_NaN (double const *pv, string_view v_name, int DIM, int line, string_view file) |
void | check_NaN (float const *pv, string_view v_name, int DIM, int line, string_view file) |
template<typename T> | |
Quaternion< T > | operator* (Quaternion< T > const &a, Quaternion< T > const &b) |
template<typename T> | |
ostream_type & | operator<< (ostream_type &os, Quaternion< T > const &Q) |
template<class Function> | |
auto | at_scope_exit (Function &&fun) -> at_scope_exit_impl< Function > |
template<class Function> | |
auto | at_scope_exit (Function const &fun) -> at_scope_exit_impl< Function const & > |
void | sleep_for_seconds (unsigned s) |
Sleep for a specified number of seconds. | |
void | sleep_for_milliseconds (unsigned ms) |
Sleep for a specified number of milliseconds. | |
void | sleep_for_microseconds (unsigned mus) |
Sleep for a specified number of microseconds. | |
void | sleep_for_nanoseconds (unsigned ns) |
Sleep for a specified number of nanoseconds. | |
void | split_string (string const &str, string const &sep, vector< string > &arr) |
string | get_basename (string_view path) |
string | get_filename (string_view path) |
string | get_extension (string_view path) |
bool | get_environment (string_view ename, string &res) |
Fetches the value of an environment variable. | |
void | set_environment (string_view ename, string_view newval, bool overwrite) |
Sets the value of an environment variable. | |
void | get_MAC_address (std::map< string, string > &addr) |
Retrieves the MAC addresses of network interfaces. | |
string | get_host_name () |
Retrieves the hostname of the system. | |
void | get_IP_address (std::vector< string > &addr) |
Fetches the IP addresses of the system. | |
string | get_user_name () |
Retrieves the username of the current user. | |
string | get_home_directory () |
Retrieves the home directory of the current user. | |
string | get_executable_path_name () |
Retrieves the full path to the current executable. | |
bool | check_if_file_exists (string_view fname) |
Checks if a file exists. | |
bool | check_if_dir_exists (string_view dirname) |
Checks if a directory exists. | |
bool | make_directory (string_view dirname, unsigned mode=0777) |
Creates a directory if it does not exist. | |
string | get_date () |
string | get_day_time () |
string | get_day_time_and_date () |
string | get_log_date_time () |
template<typename T_int, typename T_real> | |
void | search_interval (T_int npts, T_real const X[], T_real &x, T_int &last_interval, bool closed, bool can_extend) |
template<typename T_int, typename T_real> | |
void | searchInterval (T_int npts, T_real const X[], T_real &x, T_int &last_interval, bool closed, bool can_extend) |
string | progress_bar (double const progress, int const width) |
Generates a text-based progress bar as a string. | |
void | progress_bar (ostream_type &s, double const progress, int const width, string_view const msg) |
Outputs a text-based progress bar to the specified output stream. | |
void | progress_bar2 (ostream_type &s, double const progress, int const width, string_view const msg) |
Outputs an enhanced text-based progress bar to the specified output stream. | |
void | info (bool &bMMX, bool &bMMXplus, bool &bSSE, bool &bSSE2, bool &bSSE3, bool &bSSSE3, bool &bSSE41, bool &bSSE42, bool &bSSE4a, bool &bSSE5, bool &b3Dnow, bool &b3DnowExt) |
bool | has_MMX () |
check if CPU support MMX instruction set | |
bool | has_MMXplus () |
check if CPU support MMXplus instruction set | |
bool | has_SSE () |
check if CPU support SSE instruction set | |
bool | has_SSE2 () |
check if CPU support SSE2 instruction set | |
bool | has_SSE3 () |
check if CPU support SSE3 instruction set | |
bool | has_SSSE3 () |
check if CPU support SSSE3 instruction set | |
bool | has_SSE41 () |
check if CPU support SSE41 instruction set | |
bool | has_SSE42 () |
check if CPU support SSE42 instruction set | |
bool | has_SSE4a () |
check if CPU support SSE4a instruction set | |
bool | has_SSE5 () |
check if CPU support SSE5 instruction set | |
bool | has_3Dnow () |
check if CPU support 3Dnow instruction set | |
bool | has_3DnowExt () |
check if CPU support 3DnowExt instruction set | |
string | cpuInfo () |
string | fmt_table_row (unsigned const width, string_view const L, string_view const R, string_view const F, string_view const title, string_view const align) |
string | fmt_table_row (unsigned const width, string_view const L, string_view const C, string_view const R, string_view const F, std::initializer_list< string_view > const names, string_view align) |
string | fmt_table_row (unsigned const width, string_view const L, string_view const C, string_view const R, string_view const F, unsigned const N) |
string | fmt_table_left_top () |
string | fmt_table_left_middle () |
string | fmt_table_left_bottom () |
string | fmt_table_middle_top () |
string | fmt_table_middle_middle () |
string | fmt_table_middle_bottom () |
string | fmt_table_right_top () |
string | fmt_table_right_middle () |
string | fmt_table_right_bottom () |
string | fmt_table_cross () |
string | fmt_table_bar () |
string | fmt_table_vbar () |
string | fmt_table_dot () |
string | fmt_table_vdots () |
string | fmt_table_row (unsigned width, string_view title="", string_view align="^", string_view fill=" ") |
string | fmt_table_top_row (unsigned width, string_view title="", string_view align="^", string_view fill="─") |
string | fmt_table_middle_row (unsigned width, string_view title="", string_view align="^", string_view fill="─") |
string | fmt_table_bottom_row (unsigned width, string_view title="", string_view align="^", string_view fill="─") |
string | fmt_table_row (unsigned width, std::initializer_list< string_view > names, string_view align="<", string_view fill=" ") |
string | fmt_table_top_row (unsigned width, std::initializer_list< string_view > names, string_view align="<", string_view fill="─") |
string | fmt_table_middle_row (unsigned width, std::initializer_list< string_view > names, string_view align="<", string_view fill="─") |
string | fmt_table_bottom_row (unsigned width, std::initializer_list< string_view > names, string_view align="<", string_view fill="─") |
string | fmt_table_row (unsigned width, unsigned N, string_view fill=" ") |
string | fmt_table_top_row (unsigned width, unsigned N, string_view fill="─") |
string | fmt_table_middle_row (unsigned width, unsigned N, string_view fill="─") |
string | fmt_table_bottom_row (unsigned width, unsigned N, string_view fill="─") |
template<typename Real, typename Char> | |
std::basic_ostream< Char > & | operator<< (std::basic_ostream< Char > &output, Poly< Real > const &p) |
template<typename Real, typename Char> | |
std::basic_ostream< Char > & | operator<< (std::basic_ostream< Char > &output, Sturm< Real > const &S) |
void | print_trace (int line, string_view file, string_view msg, ostream_type &stream) |
Prints a formatted trace message to the specified stream. | |
void | printTrace (int line, string_view file, string_view reason, ostream_type &stream) |
Variables | |
std::mutex | MallocMutex |
Global mutex for thread-safe memory operations. | |
int64_t | CountAlloc |
Global variables for tracking memory allocation statistics. | |
int64_t | CountFreed |
int64_t | AllocatedBytes |
int64_t | MaximumAllocatedBytes |
bool | MallocDebug |
using Utils::istream_type = std::basic_istream<char> |
Type for input stream.
using Utils::ostream_type = std::basic_ostream<char> |
Type for output stream.
using Utils::string = std::string |
Type for string.
string Utils::basename | ( | string_view | filename | ) |
Get the base name of a file.
filename | C-style string representing the file name. |
void Utils::check_NaN | ( | double const * | pv, |
string_view | v_name, | ||
int | DIM, | ||
int | line, | ||
string_view | file ) |
Checks for NaN values in an array of doubles and logs an error if found.
pv | Pointer to the array of double values. |
v_name | The name of the variable for logging. |
DIM | The dimension (size) of the array. |
line | The line number where the check is performed. |
file | The name of the file where the check is performed. |
void Utils::check_NaN | ( | float const * | pv, |
string_view | v_name, | ||
int | DIM, | ||
int | line, | ||
string_view | file ) |
Checks for NaN values in an array of floats and logs an error if found.
pv | Pointer to the array of float values. |
v_name | The name of the variable for logging. |
DIM | The dimension (size) of the array. |
line | The line number where the check is performed. |
file | The name of the file where the check is performed. |
string Utils::cpuInfo | ( | ) |
Return a string describing the CPU.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
string Utils::fmt_table_row | ( | unsigned const | width, |
string_view const | L, | ||
string_view const | C, | ||
string_view const | R, | ||
string_view const | F, | ||
std::initializer_list< string_view > const | names, | ||
string_view | align ) |
string Utils::fmt_table_row | ( | unsigned const | width, |
string_view const | L, | ||
string_view const | C, | ||
string_view const | R, | ||
string_view const | F, | ||
unsigned const | N ) |
string Utils::fmt_table_row | ( | unsigned const | width, |
string_view const | L, | ||
string_view const | R, | ||
string_view const | F, | ||
string_view const | title, | ||
string_view const | align ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool Utils::found_NaN | ( | double const * | pv, |
int | DIM ) |
Checks if a NaN value is found in an array of doubles.
pv | Pointer to the array of double values. |
DIM | The dimension (size) of the array. |
bool Utils::found_NaN | ( | float const * | pv, |
int | DIM ) |
Checks if a NaN value is found in an array of floats.
pv | Pointer to the array of float values. |
DIM | The dimension (size) of the array. |
|
inline |
|
inline |
|
inline |
bool Utils::has_3Dnow | ( | ) |
check if CPU support 3Dnow instruction set
bool Utils::has_3DnowExt | ( | ) |
check if CPU support 3DnowExt instruction set
bool Utils::has_MMX | ( | ) |
check if CPU support MMX instruction set
bool Utils::has_MMXplus | ( | ) |
check if CPU support MMXplus instruction set
bool Utils::has_SSE | ( | ) |
check if CPU support SSE instruction set
bool Utils::has_SSE2 | ( | ) |
check if CPU support SSE2 instruction set
bool Utils::has_SSE3 | ( | ) |
check if CPU support SSE3 instruction set
bool Utils::has_SSE41 | ( | ) |
check if CPU support SSE41 instruction set
bool Utils::has_SSE42 | ( | ) |
check if CPU support SSE42 instruction set
bool Utils::has_SSE4a | ( | ) |
check if CPU support SSE4a instruction set
bool Utils::has_SSE5 | ( | ) |
check if CPU support SSE5 instruction set
bool Utils::has_SSSE3 | ( | ) |
check if CPU support SSSE3 instruction set
T Utils::Inf | ( | ) |
Returns an infinity constant for the specified type.
T | The type of the infinity constant. Supported types include float and double. |
void Utils::info | ( | bool & | bMMX, |
bool & | bMMXplus, | ||
bool & | bSSE, | ||
bool & | bSSE2, | ||
bool & | bSSE3, | ||
bool & | bSSSE3, | ||
bool & | bSSE41, | ||
bool & | bSSE42, | ||
bool & | bSSE4a, | ||
bool & | bSSE5, | ||
bool & | b3Dnow, | ||
bool & | b3DnowExt ) |
Get info of Intel CPU
[out] | bMMX | booelan, support MMX instruction set |
[out] | bMMXplus | booelan, support MMXplus instruction set |
[out] | bSSE | booelan, support SSE instruction set |
[out] | bSSE2 | booelan, support SSE2 instruction set |
[out] | bSSE3 | booelan, support SSE3 instruction set |
[out] | bSSSE3 | booelan, support SSEE3 instruction set |
[out] | bSSE41 | booelan, support SSE41 instruction set |
[out] | bSSE42 | booelan, support SSE42 instruction set |
[out] | bSSE4a | booelan, support SSE4a instruction set |
[out] | bSSE5 | booelan, support SSE5 instruction set |
[out] | b3Dnow | booelan, support 3Dnow instruction set |
[out] | b3DnowExt | booelan, support 3DnowExt instruction set |
T Utils::machine_eps | ( | ) |
Returns the machine epsilon for the specified type.
T | The type of the machine epsilon. Supported types include float and double. |
T Utils::maximum_value | ( | ) |
Returns the maximum representable value for the specified type.
T | The type for which to compute the maximum value. Supported types include float and double. |
T Utils::minimum_value | ( | ) |
Returns the minimum representable value for the specified type.
T | The type for which to compute the minimum value. Supported types include float and double. |
T Utils::NaN | ( | ) |
Returns a Not-a-Number (NaN) constant for the specified type.
T | The type of the NaN constant. Supported types include float and double. |
|
inline |
Multiplies two quaternions.
The multiplication of two quaternions is defined as follows:
\[\mathbf{i} * \mathbf{j} = -\mathbf{j} * \mathbf{i} = \mathbf{k} \]
\[\mathbf{j} * \mathbf{k} = -\mathbf{k} * \mathbf{j} = \mathbf{i} \]
\[\mathbf{k} * \mathbf{i} = -\mathbf{i} * \mathbf{k} = \mathbf{j} \]
\[\mathbf{i} * \mathbf{i} = \mathbf{j} * \mathbf{j} = \mathbf{k} * \mathbf{k} = -1 \]
a | The first quaternion. |
b | The second quaternion. |
|
inline |
Overloads the output stream operator for quaternions.
os | The output stream. |
Q | The quaternion to output. |
|
inline |
|
inline |
string Utils::progress_bar | ( | double const | progress, |
int const | width ) |
Generates a text-based progress bar as a string.
This function creates a progress bar in the form of a string representation, which visually indicates the progress of a task. The progress is shown using equal signs, a greater-than symbol for the current position, and underscores for the remaining part of the bar.
progress | A value between 0.0 and 1.0 representing the progress of the task. |
width | The total width of the progress bar (number of characters). |
void Utils::progress_bar | ( | ostream_type & | s, |
double const | progress, | ||
int const | width, | ||
string_view const | msg ) |
Outputs a text-based progress bar to the specified output stream.
This function generates a progress bar and outputs it directly to the provided output stream, indicating the current progress of a task. The visual representation uses filled and unfilled squares to indicate progress and includes a percentage along with an optional message.
s | The output stream where the progress bar will be displayed. |
progress | A value between 0.0 and 1.0 representing the progress of the task. |
width | The total width of the progress bar (number of characters). |
msg | An optional message to display alongside the progress bar. |
void Utils::progress_bar2 | ( | ostream_type & | s, |
double const | progress, | ||
int const | width, | ||
string_view const | msg ) |
Outputs an enhanced text-based progress bar to the specified output stream.
This function generates a more detailed progress bar using various characters to represent different levels of completion. It outputs the progress bar directly to the provided output stream, including a percentage and an optional message.
s | The output stream where the progress bar will be displayed. |
progress | A value between 0.0 and 1.0 representing the progress of the task. |
width | The total width of the progress bar (number of characters). |
msg | An optional message to display alongside the progress bar. |
void Utils::search_interval | ( | T_int | npts, |
T_real const | X[], | ||
T_real & | x, | ||
T_int & | last_interval, | ||
bool | closed, | ||
bool | can_extend ) |
|
inline |
|
inline |
Sleep for a specified number of microseconds.
This function pauses the execution of the current thread for the specified number of microseconds.
mus | The number of microseconds to sleep. |
|
inline |
Sleep for a specified number of milliseconds.
This function pauses the execution of the current thread for the specified number of milliseconds.
ms | The number of milliseconds to sleep. |
|
inline |
Sleep for a specified number of nanoseconds.
This function pauses the execution of the current thread for the specified number of nanoseconds.
ns | The number of nanoseconds to sleep. |
|
inline |
Sleep for a specified number of seconds.
This function pauses the execution of the current thread for the specified number of seconds.
s | The number of seconds to sleep. |
T Utils::sqrt_machine_eps | ( | ) |
Returns the square root of the machine epsilon for the specified type.
T | The type for which to compute the square root of machine epsilon. Supported types include float and double. |