OpenDDS  Snapshot(2023/04/28-20:55)
Public Member Functions | Private Attributes | List of all members
OpenDDS::XTypes::Optional< T > Class Template Reference

#include <TypeObject.h>

Collaboration diagram for OpenDDS::XTypes::Optional< T >:
Collaboration graph
[legend]

Public Member Functions

 Optional ()
 
 Optional (const T &v)
 
 ~Optional ()
 
 Optional (const Optional &rhs)
 
Optionaloperator= (const Optional &rhs)
 
bool operator== (const Optional &other) const
 
bool operator!= (const Optional &other) const
 
 operator bool () const
 
bool has_value () const
 
T & value ()
 
const T & value () const
 

Private Attributes

bool present_
 
union {
   ACE_CDR::LongDouble   max_alignment
 
   unsigned char   value_ [sizeof(T)]
 
}; 
 

Detailed Description

template<typename T>
class OpenDDS::XTypes::Optional< T >

Definition at line 67 of file TypeObject.h.

Constructor & Destructor Documentation

◆ Optional() [1/3]

template<typename T>
OpenDDS::XTypes::Optional< T >::Optional ( )
inline

Definition at line 69 of file TypeObject.h.

70  : present_(false)
71  , value_()
72  {}
unsigned char value_[sizeof(T)]
Definition: TypeObject.h:145

◆ Optional() [2/3]

template<typename T>
OpenDDS::XTypes::Optional< T >::Optional ( const T &  v)
inline

Definition at line 74 of file TypeObject.h.

75  : present_(true)
76  {
77  new(value_) T(v);
78  }
unsigned char value_[sizeof(T)]
Definition: TypeObject.h:145

◆ ~Optional()

template<typename T>
OpenDDS::XTypes::Optional< T >::~Optional ( )
inline

Definition at line 80 of file TypeObject.h.

80  {
81  if (present_) {
82  value().~T();
83  }
84  }

◆ Optional() [3/3]

template<typename T>
OpenDDS::XTypes::Optional< T >::Optional ( const Optional< T > &  rhs)
inline

Definition at line 86 of file TypeObject.h.

87  : present_(false)
88  , value_()
89  {
90  *this = rhs;
91  }
unsigned char value_[sizeof(T)]
Definition: TypeObject.h:145

Member Function Documentation

◆ has_value()

template<typename T>
bool OpenDDS::XTypes::Optional< T >::has_value ( ) const
inline

Definition at line 129 of file TypeObject.h.

129  {
130  return present_;
131  }

◆ operator bool()

template<typename T>
OpenDDS::XTypes::Optional< T >::operator bool ( ) const
inline

Definition at line 125 of file TypeObject.h.

125  {
126  return present_;
127  }

◆ operator!=()

template<typename T>
bool OpenDDS::XTypes::Optional< T >::operator!= ( const Optional< T > &  other) const
inline

Definition at line 120 of file TypeObject.h.

121  {
122  return !(*this == other);
123  }

◆ operator=()

template<typename T>
Optional& OpenDDS::XTypes::Optional< T >::operator= ( const Optional< T > &  rhs)
inline

Definition at line 93 of file TypeObject.h.

93  {
94  if (this != &rhs) {
95  if (present_) {
96  if (rhs.present_) {
97  value() = rhs.value();
98  } else {
99  value().~T();
100  }
101  } else {
102  if (rhs.present_) {
103  new(value_) T(rhs.value());
104  }
105  }
106  present_ = rhs.present_;
107  }
108  return *this;
109  }
unsigned char value_[sizeof(T)]
Definition: TypeObject.h:145

◆ operator==()

template<typename T>
bool OpenDDS::XTypes::Optional< T >::operator== ( const Optional< T > &  other) const
inline

Definition at line 111 of file TypeObject.h.

112  {
113  if (present_) {
114  return present_ == other.present_ && value() == other.value();
115  }
116 
117  return present_ == other.present_;
118  }

◆ value() [1/2]

template<typename T>
T& OpenDDS::XTypes::Optional< T >::value ( void  )
inline

◆ value() [2/2]

template<typename T>
const T& OpenDDS::XTypes::Optional< T >::value ( void  ) const
inline

Definition at line 137 of file TypeObject.h.

137  {
138  return reinterpret_cast<const T&>(value_);
139  }
unsigned char value_[sizeof(T)]
Definition: TypeObject.h:145

Member Data Documentation

◆ @23

union { ... }

◆ max_alignment

template<typename T>
ACE_CDR::LongDouble OpenDDS::XTypes::Optional< T >::max_alignment

Definition at line 144 of file TypeObject.h.

◆ present_

template<typename T>
bool OpenDDS::XTypes::Optional< T >::present_
private

◆ value_

template<typename T>
unsigned char OpenDDS::XTypes::Optional< T >::value_[sizeof(T)]

Definition at line 145 of file TypeObject.h.


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