25#if defined(__APPLE__) && defined(__MACH__)
27 #define UTILS_OS_OSX 1
29 #define UTILS_ARCH32 1
30 #elif defined(__x86_64__)
31 #define UTILS_ARCH64 1
33#elif defined(__unix__)
35 #define UTILS_OS_LINUX 1
37 #define UTILS_ARCH32 1
38 #elif defined(__x86_64__)
39 #define UTILS_ARCH64 1
41#elif defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
43 #define UTILS_OS_WINDOWS 1
45 #if defined(__MINGW64__)
46 #define UTILS_OS_MINGW 1
47 #define UTILS_ARCH64 1
48 #elif defined(__MINGW32__)
49 #define UTILS_OS_MINGW 1
50 #define UTILS_ARCH32 1
52 #if defined(_M_X64) || defined(_M_AMD64) || defined(_WIN64) || defined(WIN64)
53 #define UTILS_ARCH64 1
55 #define UTILS_ARCH32 1
68 #error "unsupported OS!"
72#if (defined(_MSC_VER) && _MSC_VER >= 1800) || \
73 (defined(__cplusplus) && __cplusplus > 199711L)
75 #if (defined(__cplusplus) && __cplusplus <= 201103L)
76 #define UTILS_DEFAULT {}
78 #define UTILS_DEFAULT = default
81 #error "Lapack Wrapper must be compiled using C++ >= C++11"
84#define UTILS_PURE_VIRTUAL = 0
85#ifndef UTILS_OS_WINDOWS
86 #define UTILS_OVERRIDE override
87 #define UTILS_CONSTEXPR constexpr
89 #define UTILS_OVERRIDE
90 #define UTILS_CONSTEXPR
103#include <string_view>
124#if defined(__MINGW32__) || defined(__MINGW64__) && !defined(MATLAB_MEX_FILE )
126 #if defined(__MINGW64_VERSION_MAJOR)
127 #if __MINGW64_VERSION_MAJOR < 8
128 #define UTILS_USE_MINGW_PORTABLE_THREADS
131 #if defined(__MINGW32_VERSION_MAJOR)
132 #if __MINGW32_VERSION_MAJORs < 8
133 #define UTILS_USE_MINGW_PORTABLE_THREADS
138#ifdef UTILS_USE_MINGW_PORTABLE_THREADS
139 #include "mingw-std-threads/mingw.future.h"
140 #include "mingw-std-threads/mingw.mutex.h"
141 #include "mingw-std-threads/mingw.invoke.h"
142 #include "mingw-std-threads/mingw.shared_mutex.h"
143 #include "mingw-std-threads/mingw.thread.h"
144 #include "mingw-std-threads/mingw.condition_variable.h"
148 #include <shared_mutex>
150 #include <condition_variable>
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
166 using string = std::string;
167 using string_view = std::string_view;
206 namespace fs = std::filesystem;
207 return fs::path(path).parent_path().string();
213 namespace fs = std::filesystem;
214 return fs::path(path).filename().string();
220 namespace fs = std::filesystem;
221 return fs::path(path).extension().string();
329 template <
typename T_
int,
typename T_real>
335 T_int & last_interval,
340 #ifndef DOXYGEN_SHOULD_SKIP_THIS
345 int32_t & last_interval,
354 int32_t & last_interval,
363 int64_t & last_interval,
372 int64_t & last_interval,
378 template <
typename T_
int,
typename T_real>
385 T_int & last_interval,
392 static inline void to_upper (
string & str ) { std::transform(str.begin(), str.end(), str.begin(), [](
unsigned char c) { return std::toupper(c); }); }
393 static inline void to_lower (
string & str ) { std::transform(str.begin(), str.end(), str.begin(), [](
unsigned char c) { return std::tolower(c); }); }
394 static inline bool is_lower ( string_view s ) {
return std::all_of( s.begin(), s.end(), islower ); }
395 static inline bool is_upper ( string_view s ) {
return std::all_of( s.begin(), s.end(), isupper ); }
396 static inline bool is_alpha ( string_view s ) {
return std::all_of( s.begin(), s.end(), isalpha ); }
397 static inline bool is_alphanum ( string_view s ) {
return std::all_of( s.begin(), s.end(), isalnum ); }
398 static inline bool is_digits ( string_view s ) {
return std::all_of( s.begin(), s.end(), isdigit ); }
399 static inline bool is_xdigits ( string_view s ) {
return std::all_of( s.begin(), s.end(), isxdigit ); }
405 iLog2( uint32_t N ) {
406 static unsigned const tab32[32] = {
407 0, 9, 1, 10, 13, 21, 2, 29,
408 11, 14, 16, 18, 22, 25, 3, 30,
409 8, 12, 20, 28, 15, 17, 24, 7,
410 19, 27, 23, 6, 26, 5, 4, 31
417 return tab32[uint32_t(N*0x07C4ACDD)>>27];
423 iLog2( uint64_t N ) {
424 static unsigned const tab64[64] = {
425 63, 0, 58, 1, 59, 47, 53, 2,
426 60, 39, 48, 27, 54, 33, 42, 3,
427 61, 51, 37, 40, 49, 18, 28, 20,
428 55, 30, 34, 11, 43, 14, 22, 4,
429 62, 57, 46, 52, 38, 26, 32, 41,
430 50, 36, 17, 19, 29, 10, 13, 21,
431 56, 45, 25, 31, 35, 16, 9, 12,
432 44, 24, 15, 8, 23, 7, 6, 5
440 return tab64[uint64_t((N - (N>>1))*0x07EDD5E59A4E28C2) >> 58];
Console utility for formatted output with different message levels.
void get_IP_address(std::vector< string > &addr)
Fetches the IP addresses of the system.
string get_executable_path_name()
Retrieves the full path to the current executable.
string get_log_date_time()
string get_home_directory()
Retrieves the home directory of the current user.
void get_MAC_address(std::map< string, string > &addr)
Retrieves the MAC addresses of network interfaces.
bool check_if_dir_exists(string_view dirname)
Checks if a directory exists.
string get_user_name()
Retrieves the username of the current user.
string get_host_name()
Retrieves the hostname of the system.
string get_day_time_and_date()
void set_environment(string_view ename, string_view newval, bool overwrite)
Sets the value of an environment variable.
bool get_environment(string_view ename, string &res)
Fetches the value of an environment variable.
bool check_if_file_exists(string_view fname)
Checks if a file exists.
bool make_directory(string_view dirname, unsigned mode=0777)
Creates a directory if it does not exist.
Definition SystemUtils.cc:39
std::basic_istream< char > istream_type
Type for input stream.
Definition Console.hxx:27
std::basic_ostream< char > ostream_type
Type for output stream.
Definition Console.hxx:28
string get_extension(string_view path)
Definition Utils.hxx:219
std::string string
Type for string.
Definition Console.hxx:29
void searchInterval(T_int npts, T_real const X[], T_real &x, T_int &last_interval, bool closed, bool can_extend)
Definition Utils.hxx:381
void progress_bar2(ostream_type &, double progress, int width, string_view msg)
Outputs an enhanced text-based progress bar to the specified output stream.
Definition Utils_progress_bar.cc:95
string get_filename(string_view path)
Definition Utils.hxx:212
void search_interval(T_int npts, T_real const X[], T_real &x, T_int &last_interval, bool closed, bool can_extend)
string progress_bar(double progress, int width)
Generates a text-based progress bar as a string.
Definition Utils_progress_bar.cc:47
string get_basename(string_view path)
Definition Utils.hxx:205