Gazebo Common

API Reference

7.4.0
EnumIface< T > Class Template Reference

Enum interface. Use this interface to convert an enum to a string, and set an enum from a string. More...

#include <EnumIface.hh>

Public Member Functions

 EnumIface (T _start, T _end, const std::vector< std::string > &_names)
 Constructor.
 
Begin ()
 Get the beginning enum value.
 
End ()
 Get the end enum value.
 
void Set (T &_e, const std::string &_str)
 Set an enum from a string. This function requires a valid string, and an array of names for the enum must exist.
 
std::string Str (T const &_e)
 Convert enum value to string.
 

Public Attributes

std::vector< std::stringnames
 
range [2]
 

Detailed Description

template<typename T>
class gz::common::EnumIface< T >

Enum interface. Use this interface to convert an enum to a string, and set an enum from a string.

Constructor & Destructor Documentation

◆ EnumIface()

template<typename T >
EnumIface ( _start,
_end,
const std::vector< std::string > &  _names 
)
inline

Constructor.

Parameters
[in]_startStarting enum value.
[in]_endEnding enum value.
[in]_namesName of each enum value.

References EnumIface< T >::range.

Member Function Documentation

◆ Begin()

template<typename T >
T Begin ( )
inline

Get the beginning enum value.

Returns
Enum value that marks the beginning of the enum list.

References EnumIface< T >::range.

◆ End()

template<typename T >
T End ( )
inline

Get the end enum value.

Returns
Enum value that marks the end of the enum list.

References EnumIface< T >::range.

◆ Set()

template<typename T >
void Set ( T &  _e,
const std::string _str 
)
inline

Set an enum from a string. This function requires a valid string, and an array of names for the enum must exist.

Parameters
[in]_strString value to convert to enum value.
[in]_eEnum variable to set.
See also
EnumIterator

References std::begin(), std::distance(), std::end(), std::find(), and EnumIface< T >::names.

◆ Str()

template<typename T >
std::string Str ( T const &  _e)
inline

Convert enum value to string.

Parameters
[in]_eEnum value to convert.
Returns
String representation of the enum. An empty string is returned if _e is invalid, or the names for the enum have not been set.

References EnumIface< T >::names, and vector< T >::size().

Member Data Documentation

◆ names

template<typename T >
std::vector<std::string> names

◆ range

template<typename T >
T range[2]

The documentation for this class was generated from the following file: