Gazebo Common

API Reference

5.6.0
include/gz/common/Util.hh File Reference
#include <cassert>
#include <chrono>
#include <future>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include <gz/common/Export.hh>
#include <gz/common/Filesystem.hh>
#include <gz/common/SystemPaths.hh>
#include <gz/common/URI.hh>

Go to the source code of this file.

Namespaces

 gz
 Forward declarations for the common classes.
 
 gz::common
 

Macros

#define GZ_ASSERT(_expr, _msg)   assert((_msg, _expr))
 This macro defines the standard way of launching an exception inside Gazebo. More...
 
#define GZ_HOMEDIR   "HOME"
 
#define GZ_MS_TO_NANO   1000000
 Nano seconds in one millisecond. More...
 
#define GZ_NANO_TO_SEC   1e-9
 Seconds in one nano second. More...
 
#define GZ_SEC_TO_NANO   1000000000
 Nano seconds in one second. More...
 
#define GZ_SLEEP_MS(_ms)
 Sleep for the specifed number of milliseconds. More...
 
#define GZ_SLEEP_NS(_ns)
 Sleep for the specifed number of nanoseconds. More...
 
#define GZ_SLEEP_S(_s)
 Sleep for the specifed number of seconds. More...
 
#define GZ_SLEEP_US(_us)
 Sleep for the specifed number of microseconds. More...
 
#define GZ_SPEED_OF_LIGHT   = 299792458.0
 Speed of light. More...
 
#define GZ_SYSTEM_TIME()   (std::chrono::system_clock::now())
 Get the system time. More...
 
#define GZ_SYSTEM_TIME_MS()
 Get the system time in milliseconds since epoch. More...
 
#define GZ_SYSTEM_TIME_NS()
 Get the system time in nanoseconds since epoch. More...
 
#define GZ_SYSTEM_TIME_S()
 Get the system time in seconds since epoch. More...
 
#define GZ_SYSTEM_TIME_US()
 Get the system time in microseconds since epoch. More...
 
#define GZ_US_TO_NANO   1000
 Nano seconds in one microsecond. More...
 

Typedefs

typedef std::runtime_error exception
 A runtime error. More...
 

Enumerations

enum  NodeTransformType { TRANSLATE , ROTATE , SCALE , MATRIX }
 Enumeration of the transform types. More...
 

Functions

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 return a full local path to the requested file, or and empty string if the file was not found in the callback. Callbacks will be called in the order they were added until a path is found. More...
 
void addSearchPathSuffix (const std::string &_suffix)
 add path suffix to common::SystemPaths More...
 
bool env (const std::string &_name, std::string &_value)
 Find the environment variable '_name' and return its value. More...
 
bool env (const std::string &_name, std::string &_value, bool _allowEmpty)
 Find the environment variable '_name' and return its value. More...
 
std::string findFile (const std::string &_file)
 search for file in common::SystemPaths More...
 
std::string findFile (const std::string &_file, bool _searchLocalPath)
 search for file in common::SystemPaths More...
 
std::string findFilePath (const std::string &_file)
 search for a file in common::SystemPaths More...
 
constexpr uint64_t hash64 (std::string_view _key)
 fnv1a algorithm for 64-bit platforms. More...
 
std::string logPath ()
 Get the log path. More...
 
std::string lowercase (const char *_in)
 Transforms a string to its lowercase equivalent. More...
 
std::string lowercase (const std::string &_in)
 Transforms a string to its lowercase equivalent. More...
 
void ltrim (std::string &_s)
 In place left trim. More...
 
std::string ltrimmed (std::string _s)
 Copying left trim. More...
 
std::string replaceAll (const std::string &_orig, const std::string &_key, const std::string &_replacement)
 Replace all occurances of _key with _replacement. More...
 
void replaceAll (std::string &_result, const std::string &_orig, const std::string &_key, const std::string &_replacement)
 Replace all occurances of _key with _replacement. More...
 
void rtrim (std::string &_s)
 In place right trim. More...
 
std::string rtrimmed (std::string _s)
 Copying right trim. More...
 
bool setenv (const std::string &_name, const std::string &_value)
 Set the environment variable '_name'. More...
 
template<typename T >
std::string sha1 (const T &_buffer)
 Compute the SHA1 hash of an array of bytes. More...
 
template<typename T >
std::string sha1 (const T &_buffer)
 
std::string sha1 (void const *_buffer, std::size_t _byteCount)
 Compute the SHA1 hash of an array of bytes. Use std::string sha1(const T &_buffer) instead of this function. More...
 
std::vector< std::stringsplit (const std::string &_str, const std::string &_delim)
 Splits a string into tokens. More...
 
common::SystemPaths * systemPaths ()
 Get a pointer to the global system paths that is used by all the findFile functions. The returned instance has global shared state for a given process. Care should be taken when manipulating global system paths Caller should not assume ownership of the pointer. More...
 
std::string systemTimeISO ()
 Please use systemTimeIso() as this function will be deprecated in Gazebo Common 4. Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.NS. More...
 
std::string systemTimeIso ()
 Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.NS. More...
 
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. More...
 
void trim (std::string &_s)
 In place trim from both ends. More...
 
std::string trimmed (std::string _s)
 Copying trim from both ends. More...
 
bool unsetenv (const std::string &_name)
 Unset the environment variable '_name'. More...
 
std::string uuid ()
 Get a UUID. More...
 

Macro Definition Documentation

◆ GZ_ASSERT

#define GZ_ASSERT (   _expr,
  _msg 
)    assert((_msg, _expr))

This macro defines the standard way of launching an exception inside Gazebo.

◆ GZ_HOMEDIR

#define GZ_HOMEDIR   "HOME"

◆ GZ_MS_TO_NANO

#define GZ_MS_TO_NANO   1000000

Nano seconds in one millisecond.

◆ GZ_NANO_TO_SEC

#define GZ_NANO_TO_SEC   1e-9

Seconds in one nano second.

◆ GZ_SEC_TO_NANO

#define GZ_SEC_TO_NANO   1000000000

Nano seconds in one second.

◆ GZ_SLEEP_MS

#define GZ_SLEEP_MS (   _ms)
Value:

Sleep for the specifed number of milliseconds.

◆ GZ_SLEEP_NS

#define GZ_SLEEP_NS (   _ns)
Value:

Sleep for the specifed number of nanoseconds.

◆ GZ_SLEEP_S

#define GZ_SLEEP_S (   _s)
Value:

Sleep for the specifed number of seconds.

◆ GZ_SLEEP_US

#define GZ_SLEEP_US (   _us)
Value:

Sleep for the specifed number of microseconds.

◆ GZ_SPEED_OF_LIGHT

#define GZ_SPEED_OF_LIGHT   = 299792458.0

Speed of light.

◆ GZ_SYSTEM_TIME

#define GZ_SYSTEM_TIME ( )    (std::chrono::system_clock::now())

Get the system time.

◆ GZ_SYSTEM_TIME_MS

#define GZ_SYSTEM_TIME_MS ( )
Value:
(\
std::chrono::duration_cast<std::chrono::milliseconds>(\
std::chrono::system_clock::now().time_since_epoch()).count())

Get the system time in milliseconds since epoch.

◆ GZ_SYSTEM_TIME_NS

#define GZ_SYSTEM_TIME_NS ( )
Value:
(\
std::chrono::duration_cast<std::chrono::nanoseconds>(\
std::chrono::system_clock::now().time_since_epoch()).count())

Get the system time in nanoseconds since epoch.

◆ GZ_SYSTEM_TIME_S

#define GZ_SYSTEM_TIME_S ( )
Value:
(std::chrono::duration_cast<std::chrono::seconds>(\
std::chrono::system_clock::now().time_since_epoch()).count())

Get the system time in seconds since epoch.

◆ GZ_SYSTEM_TIME_US

#define GZ_SYSTEM_TIME_US ( )
Value:
(\
std::chrono::duration_cast<std::chrono::microseconds>(\
std::chrono::system_clock::now().time_since_epoch()).count())

Get the system time in microseconds since epoch.

◆ GZ_US_TO_NANO

#define GZ_US_TO_NANO   1000

Nano seconds in one microsecond.

Function Documentation

◆ sha1()

std::string sha1 ( const T &  _buffer)
td> const T &  _buffer)

Compute the SHA1 hash of an array of bytes.

Parameters
[in]_bufferInput sequence. The permitted data types for this function are std::string and any STL container.
Returns
The string representation (40 character) of the SHA1 hash.