RTI Connext Modern C++ API  Version 6.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dds::core::safe_enum< def, inner > Class Template Reference

<<value-type>> Provides a safe, scoped enumeration based on def::type More...

#include <SafeEnumeration.hpp>

Inherits def.

Public Types

typedef inner inner_enum
 

Public Member Functions

 safe_enum ()
 Initializes the enumeration to zero.
 
 safe_enum (inner_enum v)
 Copy constructor.
 
inner_enum underlying () const
 Retrieves the actual enum value.
 
bool operator== (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 
bool operator!= (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 
bool operator< (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 
bool operator<= (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 
bool operator> (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 
bool operator>= (const safe_enum &s) const
 Applies operator to underlying enumeration value.
 

Friends

void swap (safe_enum &left, safe_enum &right) OMG_NOEXCEPT
 Swaps the enumeration values.
 

Related Functions

(Note that these are not member functions.)

template<typename def , typename inner >
std::ostream & operator<< (std::ostream &out, const safe_enum< def, inner > &the_enum)
 Applies operator<< to the underlying enum.
 

Detailed Description

template<typename def, typename inner = typename def::type>
class dds::core::safe_enum< def, inner >

<<value-type>> Provides a safe, scoped enumeration based on def::type

The purpose of this class is to provide a C++11-style enum class, where the enumeration constants are scoped.

Template Parameters
defA struct containing the actual enumeration, def::type

See for example dds::core::policy::ReliabilityKind. The actual enumeration is in dds::core::policy::ReliabilityKind_def, but the application only needs to use the former:

ReliabilityKind kind = ReliabilityKind::RELIABLE;

A safe_enum can be converted to and from an integer.

To convert to an integer, use the member function underlying():

ReliabilityKind reliability = ReliabilityKind::RELIABLE;
int reliability_as_int = reliability.underlying();

To convert from an integer, static_cast it to the member type inner_enum:

int reliability_as_int = 2;
ReliabilityKind reliability = static_cast<ReliabilityKind::inner_enum>(reliability_as_int);

Member Typedef Documentation

template<typename def, typename inner = typename def::type>
typedef inner dds::core::safe_enum< def, inner >::inner_enum

The underlying enum type

To convert from an integer, static_cast it to the member type inner_enum:

int reliability_as_int = 2;
ReliabilityKind reliability = static_cast<ReliabilityKind::inner_enum>(reliability_as_int);

Constructor & Destructor Documentation

template<typename def, typename inner = typename def::type>
dds::core::safe_enum< def, inner >::safe_enum ( )
inline

Initializes the enumeration to zero.

Note
Zero may not be a valid enumerator. It's best to assign a valid enumerator whenever possible:
Reliability reliability = Reliability::RELIABLE;
template<typename def, typename inner = typename def::type>
dds::core::safe_enum< def, inner >::safe_enum ( inner_enum  v)
inline

Copy constructor.

Member Function Documentation

template<typename def, typename inner = typename def::type>
inner_enum dds::core::safe_enum< def, inner >::underlying ( ) const
inline

Retrieves the actual enum value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator== ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator!= ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator< ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator<= ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator> ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

template<typename def, typename inner = typename def::type>
bool dds::core::safe_enum< def, inner >::operator>= ( const safe_enum< def, inner > &  s) const
inline

Applies operator to underlying enumeration value.

Friends And Related Function Documentation

template<typename def, typename inner = typename def::type>
void swap ( safe_enum< def, inner > &  left,
safe_enum< def, inner > &  right 
)
friend

Swaps the enumeration values.

template<typename def , typename inner >
std::ostream & operator<< ( std::ostream &  out,
const safe_enum< def, inner > &  the_enum 
)
related

Applies operator<< to the underlying enum.


RTI Connext Modern C++ API Version 6.0.1 Copyright © Sat Nov 23 2019 Real-Time Innovations, Inc