Ignition Common

API Reference

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

Go to the source code of this file.

Namespaces

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

Macros

#define IGN_ASSERT(_expr, _msg)   assert((_msg, _expr))
 This macro defines the standard way of launching an exception inside ignition. More...
 
#define IGN_HOMEDIR   "HOME"
 
#define IGN_MS_TO_NANO   1000000
 Nano seconds in one millisecond. More...
 
#define IGN_NANO_TO_SEC   1e-9
 Seconds in one nano second. More...
 
#define IGN_SEC_TO_NANO   1000000000
 Nano seconds in one second. More...
 
#define IGN_SLEEP_MS(_ms)
 Sleep for the specifed number of milliseconds. More...
 
#define IGN_SLEEP_NS(_ns)
 Sleep for the specifed number of nanoseconds. More...
 
#define IGN_SLEEP_S(_s)
 Sleep for the specifed number of seconds. More...
 
#define IGN_SLEEP_US(_us)
 Sleep for the specifed number of microseconds. More...
 
#define IGN_SPEED_OF_LIGHT   = 299792458.0
 Speed of light. More...
 
#define IGN_SYSTEM_TIME()   (std::chrono::system_clock::now())
 Get the system time. More...
 
#define IGN_SYSTEM_TIME_MS()
 Get the system time in milliseconds since epoch. More...
 
#define IGN_SYSTEM_TIME_NS()
 Get the system time in nanoseconds since epoch. More...
 
#define IGN_SYSTEM_TIME_S()
 Get the system time in seconds since epoch. More...
 
#define IGN_SYSTEM_TIME_US()
 Get the system time in microseconds since epoch. More...
 
#define IGN_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 std::string &_in)
 Transforms a string to its lowercase equivalent. More...
 
std::string lowercase (const char *_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...
 
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...
 
std::string replaceAll (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...
 
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...
 
template<typename T >
std::string sha1 (const T &_buffer)
 Compute the SHA1 hash of an array of bytes. 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 Ignition 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

◆ IGN_ASSERT

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

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

◆ IGN_HOMEDIR

#define IGN_HOMEDIR   "HOME"

◆ IGN_MS_TO_NANO

#define IGN_MS_TO_NANO   1000000

Nano seconds in one millisecond.

◆ IGN_NANO_TO_SEC

#define IGN_NANO_TO_SEC   1e-9

Seconds in one nano second.

◆ IGN_SEC_TO_NANO

#define IGN_SEC_TO_NANO   1000000000

Nano seconds in one second.

◆ IGN_SLEEP_MS

#define IGN_SLEEP_MS (   _ms)
Value:

Sleep for the specifed number of milliseconds.

◆ IGN_SLEEP_NS

#define IGN_SLEEP_NS (   _ns)
Value:

Sleep for the specifed number of nanoseconds.

◆ IGN_SLEEP_S

#define IGN_SLEEP_S (   _s)
Value:

Sleep for the specifed number of seconds.

◆ IGN_SLEEP_US

#define IGN_SLEEP_US (   _us)
Value:

Sleep for the specifed number of microseconds.

◆ IGN_SPEED_OF_LIGHT

#define IGN_SPEED_OF_LIGHT   = 299792458.0

Speed of light.

◆ IGN_SYSTEM_TIME

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

Get the system time.

◆ IGN_SYSTEM_TIME_MS

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

Get the system time in milliseconds since epoch.

◆ IGN_SYSTEM_TIME_NS

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

Get the system time in nanoseconds since epoch.

◆ IGN_SYSTEM_TIME_S

#define IGN_SYSTEM_TIME_S ( )
Value:

Get the system time in seconds since epoch.

◆ IGN_SYSTEM_TIME_US

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

Get the system time in microseconds since epoch.

◆ IGN_US_TO_NANO

#define IGN_US_TO_NANO   1000

Nano seconds in one microsecond.

Function Documentation

◆ sha1()

std::string sha1 ( 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.

References ignition::common::sha1().

Referenced by sha1().