0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
clanguml::common::optional_ref< T > Class Template Reference

Simple optional reference type. More...

Detailed Description

template<typename T>
class clanguml::common::optional_ref< T >

Simple optional reference type.

This class template provides a convenient way around the std::optional limitation of not allowing references. This is useful for storing references to diagram elements in various views, and writing methods which return can return an empty value if the diagram does not contain something.

This is not an owning type - it will not accept an rvalue - the actual value must be stored somewhere else as lvalue or some kind of smart pointer.

Note
Probably unsafe - do not use at home.
Template Parameters
TType of reference

Definition at line 117 of file types.h.

#include <types.h>

Public Types

using optional_type = T
 

Public Member Functions

 optional_ref ()=default
 
 optional_ref (T *value)
 
 optional_ref (const T *value)
 
 optional_ref (T &value)
 
 optional_ref (const T &value)
 
 optional_ref (optional_ref &right)
 
template<typename V , typename = std::enable_if< std::is_base_of_v<optional_type, typename V::optional_type> || std::is_same_v<optional_type, typename V::optional_type>>>
 optional_ref (const V &t)
 
template<typename V , typename = std::enable_if< std::is_base_of_v<optional_type, typename V::optional_type> || std::is_same_v<optional_type, typename V::optional_type>>>
 optional_ref (V &&t)
 
template<typename V , typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
 optional_ref (const std::reference_wrapper< V > &t)
 
optional_refoperator= (const optional_ref &right)
 
optional_refoperator= (optional_ref &&right) noexcept
 
bool has_value () const noexcept
 
 operator bool () const noexcept
 
const T & value () const
 
T & value ()
 
T & operator* ()
 
const T & operator* () const
 
void reset ()
 
T * get () const
 

Private Attributes

T * value_ {nullptr}
 

Member Typedef Documentation

◆ optional_type

template<typename T >
using clanguml::common::optional_ref< T >::optional_type = T

Definition at line 119 of file types.h.

Constructor & Destructor Documentation

◆ optional_ref() [1/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( )
default

◆ optional_ref() [2/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( T *  value)
inline

Definition at line 123 of file types.h.

124 : value_{value}
125 {
126 }

◆ optional_ref() [3/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( const T *  value)
inline

Definition at line 128 of file types.h.

129 : value_{value}
130 {
131 }

◆ optional_ref() [4/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( T &  value)
inline

Definition at line 133 of file types.h.

134 : value_{&value}
135 {
136 }

◆ optional_ref() [5/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( const T &  value)
inline

Definition at line 138 of file types.h.

139 : value_{&value}
140 {
141 }

◆ optional_ref() [6/9]

template<typename T >
clanguml::common::optional_ref< T >::optional_ref ( optional_ref< T > &  right)
inline

Definition at line 143 of file types.h.

144 : value_{right.get()}
145 {
146 }

◆ optional_ref() [7/9]

template<typename T >
template<typename V , typename = std::enable_if< std::is_base_of_v<optional_type, typename V::optional_type> || std::is_same_v<optional_type, typename V::optional_type>>>
clanguml::common::optional_ref< T >::optional_ref ( const V &  t)
inline

Definition at line 152 of file types.h.

153 : value_{t.get()}
154 {
155 }

◆ optional_ref() [8/9]

template<typename T >
template<typename V , typename = std::enable_if< std::is_base_of_v<optional_type, typename V::optional_type> || std::is_same_v<optional_type, typename V::optional_type>>>
clanguml::common::optional_ref< T >::optional_ref ( V &&  t)
inline

Definition at line 161 of file types.h.

162 : value_{t.get()}
163 {
164 t.reset();
165 }

◆ optional_ref() [9/9]

template<typename T >
template<typename V , typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
clanguml::common::optional_ref< T >::optional_ref ( const std::reference_wrapper< V > &  t)
inline

Definition at line 169 of file types.h.

170 : value_{&t.get()}
171 {
172 }

Member Function Documentation

◆ get()

template<typename T >
T * clanguml::common::optional_ref< T >::get ( ) const
inline

Definition at line 223 of file types.h.

223{ return value_; }

◆ has_value()

template<typename T >
bool clanguml::common::optional_ref< T >::has_value ( ) const
inlinenoexcept

Definition at line 193 of file types.h.

193{ return value_ != nullptr; }

◆ operator bool()

template<typename T >
clanguml::common::optional_ref< T >::operator bool ( ) const
inlinenoexcept

Definition at line 195 of file types.h.

195{ return has_value(); }

◆ operator*() [1/2]

template<typename T >
T & clanguml::common::optional_ref< T >::operator* ( )
inline

Definition at line 209 of file types.h.

210 {
211 assert(value_ != nullptr);
212 return *value_;
213 }

◆ operator*() [2/2]

template<typename T >
const T & clanguml::common::optional_ref< T >::operator* ( ) const
inline

Definition at line 215 of file types.h.

216 {
217 assert(value_ != nullptr);
218 return *value_;
219 }

◆ operator=() [1/2]

template<typename T >
optional_ref & clanguml::common::optional_ref< T >::operator= ( const optional_ref< T > &  right)
inline

Definition at line 174 of file types.h.

175 {
176 if (this == &right)
177 return *this;
178
179 value_ = right.value_;
180 return *this;
181 }

◆ operator=() [2/2]

template<typename T >
optional_ref & clanguml::common::optional_ref< T >::operator= ( optional_ref< T > &&  right)
inlinenoexcept

Definition at line 183 of file types.h.

184 {
185 if (this == &right)
186 return *this;
187
188 value_ = right.value_;
189 right.reset();
190 return *this;
191 }

◆ reset()

template<typename T >
void clanguml::common::optional_ref< T >::reset ( )
inline

Definition at line 221 of file types.h.

221{ value_ = nullptr; }

◆ value() [1/2]

template<typename T >
T & clanguml::common::optional_ref< T >::value ( )
inline

Definition at line 203 of file types.h.

204 {
205 assert(value_ != nullptr);
206 return *value_;
207 }

◆ value() [2/2]

template<typename T >
const T & clanguml::common::optional_ref< T >::value ( ) const
inline

Definition at line 197 of file types.h.

198 {
199 assert(value_ != nullptr);
200 return *value_;
201 }

Member Data Documentation

◆ value_

template<typename T >
T* clanguml::common::optional_ref< T >::value_ {nullptr}
private

Definition at line 226 of file types.h.


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