Go to the documentation of this file.
17 #ifndef GZ_COMMON_UTIL_HH_
18 #define GZ_COMMON_UTIL_HH_
28 #include <gz/common/Export.hh>
37 # define IGN_HOMEDIR "USERPROFILE"
39 # define IGN_HOMEDIR "HOME"
43 #define IGN_NANO_TO_SEC 1e-9
46 #define IGN_SEC_TO_NANO 1000000000
49 #define IGN_MS_TO_NANO 1000000
52 #define IGN_US_TO_NANO 1000
55 #define IGN_SPEED_OF_LIGHT = 299792458.0
58 #define IGN_SLEEP_S(_s) (std::this_thread::sleep_for(\
59 std::chrono::seconds(_s)))
62 #define IGN_SLEEP_US(_us) (std::this_thread::sleep_for(\
63 std::chrono::microseconds(_us)))
66 #define IGN_SLEEP_MS(_ms) (std::this_thread::sleep_for(\
67 std::chrono::milliseconds(_ms)))
70 #define IGN_SLEEP_NS(_ns) (std::this_thread::sleep_for(\
71 std::chrono::nanoseconds(_ns)))
74 #define IGN_SYSTEM_TIME() (std::chrono::system_clock::now())
77 #define IGN_SYSTEM_TIME_S() (std::chrono::duration_cast<std::chrono::seconds>(\
78 std::chrono::system_clock::now().time_since_epoch()).count())
81 #define IGN_SYSTEM_TIME_US() (\
82 std::chrono::duration_cast<std::chrono::microseconds>(\
83 std::chrono::system_clock::now().time_since_epoch()).count())
86 #define IGN_SYSTEM_TIME_MS() (\
87 std::chrono::duration_cast<std::chrono::milliseconds>(\
88 std::chrono::system_clock::now().time_since_epoch()).count())
91 #define IGN_SYSTEM_TIME_NS() (\
92 std::chrono::duration_cast<std::chrono::nanoseconds>(\
93 std::chrono::system_clock::now().time_since_epoch()).count())
97 #define IGN_ASSERT(_expr, _msg) assert((_msg, _expr))
148 bool _searchLocalPath);
194 constexpr uint64_t IGNITION_COMMON_VISIBLE
hash64(std::string_view _key)
196 const char *data = _key.data();
197 const auto len = _key.size();
198 const uint64_t prime = 0x100000001b3;
199 uint64_t hash = 0xcbf29ce484222325;
201 for (
auto i = 0u; i < len; ++i)
203 uint8_t value =
static_cast<uint8_t
>(data[i]);
218 bool IGNITION_COMMON_VISIBLE
env(
227 bool IGNITION_COMMON_VISIBLE
env(
239 bool IGNITION_COMMON_VISIBLE
setenv(
327 if (_buffer.size() == 0)
332 &(_buffer[0]), _buffer.size() *
sizeof(_buffer[0]));
std::string sha1(const T &_buffer)
Compute the SHA1 hash of an array of bytes.
Definition: include/gz/common/Util.hh:325
NodeTransformType
Enumeration of the transform types.
Definition: include/gz/common/Util.hh:105
Forward declarations for the common classes.
std::string findFile(const std::string &_file)
search for file in common::SystemPaths
std::vector< std::string > split(const std::string &_str, const std::string &_delim)
Splits a string into tokens.
constexpr uint64_t hash64(std::string_view _key)
fnv1a algorithm for 64-bit platforms.
Definition: include/gz/common/Util.hh:194
std::string lowercase(const std::string &_in)
Transforms a string to its lowercase equivalent.
std::string timeToIso(const std::chrono::time_point< std::chrono::system_clock > &_time)
Converts a time point to an ISO string: YYYY-MM-DDTHH:MM:SS.NS.
@ TRANSLATE
Definition: include/gz/common/Util.hh:105
@ MATRIX
Definition: include/gz/common/Util.hh:105
std::string trimmed(std::string _s)
Copying trim from both ends.
void addFindFileURICallback(std::function< std::string(const URI &)> _cb)
Add a callback to use when findFile() can't find a file that is a valid URI. The callback should retu...
std::string rtrimmed(std::string _s)
Copying right trim.
@ ROTATE
Definition: include/gz/common/Util.hh:105
@ SCALE
Definition: include/gz/common/Util.hh:105
void trim(std::string &_s)
In place trim from both ends.
A complete URI.
Definition: gz/common/URI.hh:263
bool setenv(const std::string &_name, const std::string &_value)
Set the environment variable '_name'.
Functions to handle getting system paths, keeps track of:
Definition: gz/common/SystemPaths.hh:51
void ltrim(std::string &_s)
In place left trim.
std::string findFilePath(const std::string &_file)
search for a file in common::SystemPaths
void replaceAll(std::string &_result, const std::string &_orig, const std::string &_key, const std::string &_replacement)
Replace all occurances of _key with _replacement.
std::string ltrimmed(std::string _s)
Copying left trim.
std::string uuid()
Get a UUID.
void addSearchPathSuffix(const std::string &_suffix)
add path suffix to common::SystemPaths
bool unsetenv(const std::string &_name)
Unset the environment variable '_name'.
std::string systemTimeISO()
Please use systemTimeIso() as this function will be deprecated in Ignition Common 4....
std::runtime_error exception
A runtime error.
Definition: include/gz/common/Util.hh:108
bool env(const std::string &_name, std::string &_value)
Find the environment variable '_name' and return its value.
common::SystemPaths * systemPaths()
Get a pointer to the global system paths that is used by all the findFile functions....
std::string systemTimeIso()
Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.NS.
void rtrim(std::string &_s)
In place right trim.
std::string logPath()
Get the log path.