ifw-core 7.0.0
 
Loading...
Searching...
No Matches
tools.hpp
Go to the documentation of this file.
1
6
7#ifndef IFW_CORE_UTILS_TOOLS_HPP_
8#define IFW_CORE_UTILS_TOOLS_HPP_
9
10#include <limits.h>
11#include <stdarg.h>
12#include <string>
13#include <map>
14#include <list>
15#include <fstream>
16#include <variant>
17
18#include <ciiLogManager.hpp>
19
21
22
23namespace ifw {
24
26 // TODO: Remove this and replace calls to this function with (fmt::print(). fmtlib).
27 std::string Write(const char* format, ...);
28
29}
30
31#define IFW_LOCATION {\
32 std::string(__FILE__), \
33 std::string(__FUNCTION__), \
34 std::to_string(__LINE__)}
35
36
37namespace ifw::core::utils::base {
38
40 std::string ResolvePath(const std::string& filename);
41
43 std::string GenUniqueId(const std::string& prefix = "");
44
46 template <class TYPE>
47 void CleanVector(const std::vector<TYPE>& vect,
48 const TYPE& pattern,
49 std::vector<TYPE>& clean_vect) {
50 clean_vect.clear();
51 for (const TYPE& el : vect) {
52 if (el != pattern) {
53 clean_vect.insert(el);
54 }
55 }
56 }
57
60 template <class TYPE>
61 void CheckRange(const std::string& par,
62 TYPE value,
63 TYPE lower_limit,
64 TYPE upper_limit);
65
68 template <class TYPE>
69 void CheckRange(const std::string& par,
70 const TYPE& value,
71 std::vector<TYPE>& valid_values);
72
74 template <class TYPE>
75 int32_t ElInVector(const std::vector<TYPE>& vect,
76 const TYPE& value) {
77 int32_t i = 0;
78 for (auto it = vect.begin(); it != vect.end(); it++, i++) {
79 if (*it == value) {
80 return i;
81 }
82 }
83 return -1;
84 }
85
87 template <class TYPE>
88 std::string DumpVector(const std::vector<TYPE>& vector,
89 const std::string& separator = "\n") {
90 std::stringstream tmp_buf;
91 int32_t i = 0;
92 for (auto it = vector.begin(); it != vector.end(); it++, i++) {
93 tmp_buf << *it << separator;
94 }
95 return tmp_buf.str();
96 }
97
99 template <class MAP_TYPE>
100 bool ElInMap(const std::string& key,
101 const MAP_TYPE& map) {
102 return (map.find(key) != map.end());
103 }
104
105 namespace testutils {
106
107 // TODO: Remove this function not needed (can use WAF_MODULE_PATH instead).
110 std::string GetResDir(const std::string& module_path,
111 const std::string& test_res_dir); // = "test/resource");
112
113 // TODO: Remove this function not needed (can use WAF_MODULE_PATH instead).
115 void SetRootEnvVars(const std::string& module_path,
116 const std::string& test_res_dir, // = "test/resource",
117 const std::vector<std::string>& cfgpath_dirs);
118
119 } // namespace testutils
120
121}
122
124void IFW_DEBUG(const char* format, ...);
125
126#endif // IFW_CORE_UTILS_TOOLS_HPP_
std::string GetResDir(const std::string &module_path, const std::string &test_res_dir)
Derives the "resource" directory from the current working point.
Definition tools.cpp:81
void SetRootEnvVars(const std::string &module_path, const std::string &test_res_dir, const std::vector< std::string > &cfgpath_dirs)
Set the root environment variables: CFGPATH, INTROOT, DATAROOT.
Definition tools.cpp:114
Definition fndLog4cplusBridge.cpp:19
void CleanVector(const std::vector< TYPE > &vect, const TYPE &pattern, std::vector< TYPE > &clean_vect)
Remove elements from list, which are equal to "pattern".
Definition tools.hpp:47
void CheckRange(const std::string &par, TYPE value, TYPE lower_limit, TYPE upper_limit)
Check if a value is within a given range.
std::string GenUniqueId(const std::string &prefix="")
Generate a unique UUID based ID. A prefix may be prepended, if requested.
Definition tools.cpp:58
std::string DumpVector(const std::vector< TYPE > &vector, const std::string &separator="\n")
Dump contents of a list into a string buffer.
Definition tools.hpp:88
int32_t ElInVector(const std::vector< TYPE > &vect, const TYPE &value)
Check for specific element in the list. Return index if found, otherwise -1.
Definition tools.hpp:75
bool ElInMap(const std::string &key, const MAP_TYPE &map)
Check if a given key is contained in an STL map.
Definition tools.hpp:100
std::string ResolvePath(const std::string &filename)
Resolve the filename if it contains env. variables, "~" and relative paths.
Definition tools.cpp:30
Definition defines.cpp:15
std::string Write(const char *format,...)
Create formatted string, return formatted string (C formatting convention).
Definition testutils.py:1
void IFW_DEBUG(const char *format,...)
Print out a temporary debug log. These kind of logs should be removed from the code.
Definition tools.cpp:158