Gazebo Utils

API Reference

1.5.1
ignition::utils Namespace Reference

Classes

class  ImplPtr
 The ImplPtr class provides a convenient away to achieve the Rule of Zero while keeping all the benefits of PIMPL. This saves us from writing an enormous amount of boilerplate code for each class. More...
 
class  NeverDestroyed
 

Typedefs

template<class T , class Deleter = void (*)(T*)>
using UniqueImplPtr = std::unique_ptr< T, Deleter >
 This is an alternative to ImplPtr<T> which serves the same purpose, except it only provide move semantics (i.e. it does not allow copying). This should be used in cases where it is not safe (or not possible) to copy the underlying state of an implementation class. More...
 

Functions

bool env (const std::string &_name, std::string &_value, bool _allowEmpty=false)
 Find the environment variable '_name' and return its value. More...
 
template<class T , typename... Args>
ImplPtr< T > MakeImpl (Args &&..._args)
 Pass this to the constructor of an ImplPtr object to easily initialize it. All the arguments passed into this function will be perfectly forwarded to the implementation class that gets created. More...
 
template<class T , typename... Args>
UniqueImplPtr< T > MakeUniqueImpl (Args &&..._args)
 Pass this to the constructor of a UniqueImplPtr object to easily initialize it. All the arguments passed into this function will be perfectly forwarded to the implementation class that gets created. More...
 
bool setenv (const std::string &_name, const std::string &_value)
 Set the environment variable '_name'. More...
 
bool unsetenv (const std::string &_name)
 Unset the environment variable '_name'. More...
 

Typedef Documentation

◆ UniqueImplPtr

using UniqueImplPtr = std::unique_ptr<T, Deleter>

This is an alternative to ImplPtr<T> which serves the same purpose, except it only provide move semantics (i.e. it does not allow copying). This should be used in cases where it is not safe (or not possible) to copy the underlying state of an implementation class.

Note that when creating an implementation class that is unsafe to copy, you should explicitly delete its copy constructor (unless one of its members has an explicitly deleted copy constructor). Doing so will force you to use UniqueImplPtr instead of ImplPtr, and it will signal to future developers or maintainers that the implementation class is not meant to be copiable.

Use MakeUniqueImpl<T>() to construct UniqueImplPtr objects.

Function Documentation

◆ env()

bool ignition::utils::env ( const std::string _name,
std::string _value,
bool  _allowEmpty = false 
)

Find the environment variable '_name' and return its value.

Note: This function is not thread-safe and should not be called concurrently with setenv or unsetenv

Parameters
[in]_nameName of the environment variable.
[out]_valueValue if the variable was found.
[in]_allowEmptyAllow set-but-empty variables. (Unsupported on Windows)
Returns
True if the variable was found or false otherwise.

◆ MakeImpl()

ImplPtr<T> ignition::utils::MakeImpl ( Args &&...  _args)

Pass this to the constructor of an ImplPtr object to easily initialize it. All the arguments passed into this function will be perfectly forwarded to the implementation class that gets created.

E.g.:

MyClass::MyClass(Arg1 arg1, Arg2 arg2, Arg3 arg3)
: dataPtr(utils::MakeImpl<Implementation>(arg1, arg2, arg3))
{
// Do nothing
}
Template Parameters
TThe typename of the implementation class. This must be set explicitly.
ArgsThe argument types. These will be inferred automatically.
Parameters
[in]_argsThe arguments to be forwarded to the implementation class.
Returns
A new ImplPtr<T>. Passing this along to a class's ImplPtr object's constructor will efficiently move this newly created object into it.

◆ MakeUniqueImpl()

UniqueImplPtr<T> ignition::utils::MakeUniqueImpl ( Args &&...  _args)

Pass this to the constructor of a UniqueImplPtr object to easily initialize it. All the arguments passed into this function will be perfectly forwarded to the implementation class that gets created.

E.g.:

MyClass::MyClass(Arg1 arg1, Arg2 arg2, Arg3 arg3)
: dataPtr(utils::MakeUniqueImpl<Implementation>(arg1, arg2, arg3))
{
// Do nothing
}
Template Parameters
TThe typename of the implementation class. This must be set explicitly.
ArgsThe argument types. These will be inferred automatically.
Parameters
[in]_argsThe arguments to be forwarded to the implementation class.
Returns
A new UniqueImplPtr<T>. Passing this along to a class's UniqueImplPtr object's constructor will efficiently move this newly created object into it.

◆ setenv()

bool ignition::utils::setenv ( const std::string _name,
const std::string _value 
)

Set the environment variable '_name'.

Note: On Windows setting an empty string (_value=="") is the equivalent of unsetting the variable. Note: This function is not thread-safe and should not be called concurrently with env or unsetenv

Parameters
[in]_nameName of the environment variable.
[in]_valueValue of the variable to be set.
Returns
True if the variable was set or false otherwise.

◆ unsetenv()

bool ignition::utils::unsetenv ( const std::string _name)

Unset the environment variable '_name'.

Note: This function is not thread-safe and should not be called concurrently with env or setenv

Parameters
[in]_nameName of the environment variable.
Returns
True if the variable was unset or false otherwise.
UniqueImplPtr< T > MakeUniqueImpl(Args &&..._args)
Pass this to the constructor of a UniqueImplPtr object to easily initialize it. All the arguments pas...
ImplPtr< T > MakeImpl(Args &&..._args)
Pass this to the constructor of an ImplPtr object to easily initialize it. All the arguments passed i...