namespace ov::util¶
Overview¶
namespace util {
// typedefs
typedef std::string FilePath;
// enums
enum LOG_TYPE;
// structs
template <typename T>
struct AsTypePtr;
template <typename In>
struct AsTypePtr<std::shared_ptr<In>>;
template <>
struct FileTraits<char>;
template <class C>
struct FileTraits;
template <>
struct FileTraits<wchar_t>;
struct NullLogger;
// classes
class ConstString;
class LogHelper;
class Logger;
// global functions
template <typename T>
std::string join(
const T& v,
const std::string& sep = ", "
);
template <typename T>
std::string vector_to_string(const T& v);
std::string to_lower(const std::string& s);
std::string to_upper(const std::string& s);
size_t hash_combine(const std::vector<size_t>& list);
std::string ltrim(const std::string& s);
std::string rtrim(const std::string& s);
std::string trim(const std::string& s);
bool ends_with(const std::string& src, const char \* with);
template <typename T>
bool ends_with(
const std::basic_string<T>& str,
const std::basic_string<T>& suffix
);
std::vector<std::string> split(
const std::string& s,
char delimiter,
bool trim = false
);
template <typename T>
T ceil_div(const T& x, const T& y);
template <typename T, typename A, typename V>
bool contains(
const std::vector<T, A>& vec,
const V& v
);
std::string getenv_string(const char \* env_var);
int32_t getenv_int(const char \* env_var, int32_t default_value = -1);
bool getenv_bool(const char \* env_var, bool default_value = false);
std::string sanitize_path(const std::string& path);
std::string get_file_name(const std::string& path);
std::string get_absolute_file_path(const std::string& path);
void create_directory_recursive(const std::string& path);
bool directory_exists(const std::string& path);
uint64_t file_size(const char \* path);
uint64_t file_size(const std::string& path);
template <
typename C,
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type
>
bool file_exists(const std::basic_string<C>& path);
std::string get_file_ext(const std::string& path);
std::string get_directory(const std::string& path);
std::string path_join(const std::vector<std::string>& paths);
void iterate_files(
const std::string& path,
const std::function<void(const std::string&file, bool is_dir)>& func,
bool recurse = false,
bool include_links = false
);
void convert_path_win_style(std::string& path);
std::string get_ov_lib_path();
std::string from_file_path(const FilePath& path);
FilePath to_file_path(const std::string& path);
std::string get_ov_library_path();
template <
typename C,
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type
>
std::basic_string<C> make_plugin_library_name(
const std::basic_string<C>& path,
const std::basic_string<C>& input
);
std::vector<uint8_t> load_binary(const std::string& path);
void save_binary(const std::string& path, std::vector<uint8_t> binary);
constexpr const char \* find_last(ConstString s, size_t offset, char ch);
constexpr const char \* find_last(ConstString s, char ch);
constexpr const char \* get_file_name(ConstString s);
constexpr const char \* trim_file_name(ConstString root, ConstString s);
void default_logger_handler_func(const std::string& s);
template <typename T>
NullLogger&& operator << (NullLogger&& logger, T&&);
template <typename T>
NullLogger&& operator << (NullLogger&& logger, const T&);
NullLogger&& operator << (
NullLogger&& logger,
std::basic_ostream<char, std::char_traits<char>>&&)(std::basic_ostream< char, std::char_traits< char > > &
);
std::shared_ptr<void> load_shared_object(const char \* path);
void \* get_symbol(
const std::shared_ptr<void>& shared_object,
const char \* symbolName
);
} // namespace util
Detailed Documentation¶
Global Functions¶
std::string ltrim(const std::string& s)
trim from start (in place)
Parameters:
s |
|
std::string rtrim(const std::string& s)
trim from end (in place)
Parameters:
s |
|
bool ends_with(const std::string& src, const char \* with)
check string end with given substring
Parameters:
src |
|
with |
|
Returns:
true if string end with given substring
template <typename T>
bool ends_with(
const std::basic_string<T>& str,
const std::basic_string<T>& suffix
)
check string/wstring end with given substring
Parameters:
src |
|
with |
|
Returns:
true if string end with given substring
std::string getenv_string(const char \* env_var)
Get the names environment variable as a string.
Parameters:
env_var |
The string name of the environment variable to get. |
Returns:
Returns string by value or an empty string if the environment variable is not set.
int32_t getenv_int(const char \* env_var, int32_t default_value = -1)
Get the names environment variable as an integer. If the value is not a valid integer then an exception is thrown.
Parameters:
env_var |
The string name of the environment variable to get. |
default_value |
The value to return if the environment variable is not set. |
Returns:
Returns value or default_value if the environment variable is not set.
bool getenv_bool(const char \* env_var, bool default_value = false)
Get the names environment variable as a boolean. If the value is not a valid boolean then an exception is thrown. Valid booleans are one of 1, 0, on, off, true, false All values are case insensitive. If the environment variable is not set the default_value is returned.
Parameters:
env_var |
The string name of the environment variable to get. |
default_value |
The value to return if the environment variable is not set. |
Returns:
Returns the boolean value of the environment variable.
std::string sanitize_path(const std::string& path)
Remove path components which would allow traversing up a directory tree.
Parameters:
path |
A path to file |
Returns:
A sanitiazed path
std::string get_file_name(const std::string& path)
Returns the name with extension for a given path.
Parameters:
path |
The path to the output file |
std::string get_absolute_file_path(const std::string& path)
Interface function to get absolute path of file.
Parameters:
path |
|
runtime_exception |
if any error occurred |
Returns:
Absolute path of file
void create_directory_recursive(const std::string& path)
Interface function to create directorty recursively by given path.
Parameters:
path |
|
runtime_exception |
if any error occurred |
bool directory_exists(const std::string& path)
Interface function to check if directory exists for given path.
Parameters:
path |
|
Returns:
true if directory exists, false otherwise
uint64_t file_size(const char \* path)
Returns file size for file.
Parameters:
path |
The file name |
Returns:
file size
uint64_t file_size(const std::string& path)
Returns file size for file.
Parameters:
path |
The file name |
Returns:
file size
template <
typename C,
typename = typename std::enable_if<(std::is_same<C, char>::value || std::is_same<C, wchar_t>::value)>::type
>
bool file_exists(const std::basic_string<C>& path)
Returns true if file exists.
Parameters:
path |
The path to file |
Returns:
true if file exists
std::vector<uint8_t> load_binary(const std::string& path)
load binary data from file
Parameters:
path |
|
Returns:
binary vector
void save_binary(const std::string& path, std::vector<uint8_t> binary)
save binary data to file
Parameters:
path |
|
std::shared_ptr<void> load_shared_object(const char \* path)
Loads a library with the name specified.
Parameters:
path |
Full or relative path to the plugin library |
Returns:
Reference to shared object
void \* get_symbol(
const std::shared_ptr<void>& shared_object,
const char \* symbolName
)
Searches for a function symbol in the loaded module.
Parameters:
shared_object |
shared object reference |
symbolName |
Name of the function to find |
if the function is not found |
Returns:
A pointer to the function if found