Gazebo Common

API Reference

6.0.1
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

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

Macros

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

Typedefs

typedef std::runtime_error exception
 A runtime error.
 

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.
 
void addSearchPathSuffix (const std::string &_suffix)
 add path suffix to common::SystemPaths
 
bool env (const std::string &_name, std::string &_value)
 Find the environment variable '_name' and return its value.
 
bool env (const std::string &_name, std::string &_value, bool _allowEmpty)
 Find the environment variable '_name' and return its value.
 
std::string findFile (const std::string &_file)
 search for file in common::SystemPaths
 
std::string findFile (const std::string &_file, bool _searchLocalPath)
 search for file in common::SystemPaths
 
std::string findFilePath (const std::string &_file)
 search for a file in common::SystemPaths
 
constexpr uint64_t hash64 (std::string_view _key)
 fnv1a algorithm for 64-bit platforms.
 
std::string logPath ()
 Get the log path.
 
std::string lowercase (const char *_in)
 Transforms a string to its lowercase equivalent.
 
std::string lowercase (const std::string &_in)
 Transforms a string to its lowercase equivalent.
 
void ltrim (std::string &_s)
 In place left trim.
 
std::string ltrimmed (std::string _s)
 Copying left trim.
 
std::string replaceAll (const std::string &_orig, const std::string &_key, const std::string &_replacement)
 Replace all occurances of _key with _replacement.
 
void replaceAll (std::string &_result, const std::string &_orig, const std::string &_key, const std::string &_replacement)
 Replace all occurances of _key with _replacement.
 
void rtrim (std::string &_s)
 In place right trim.
 
std::string rtrimmed (std::string _s)
 Copying right trim.
 
bool setenv (const std::string &_name, const std::string &_value)
 Set the environment variable '_name'.
 
template<typename T >
std::string sha1 (const T &_buffer)
 Compute the SHA1 hash of an array of bytes.
 
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.
 
std::vector< std::stringsplit (const std::string &_str, const std::string &_delim)
 Splits a string into tokens.
 
common::SystemPathssystemPaths ()
 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.
 
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.
 
std::string systemTimeIso ()
 Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.NS.
 
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.
 
void trim (std::string &_s)
 In place trim from both ends.
 
std::string trimmed (std::string _s)
 Copying trim from both ends.
 
bool unsetenv (const std::string &_name)
 Unset the environment variable '_name'.
 
std::string uuid ()
 Get a UUID.
 

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()

template<typename T >
std::string sha1 ( const T &  _buffer)

References sha1().

Referenced by sha1().