ManaPlus
Public Member Functions | Private Attributes
Catch::Option< T > Class Template Reference

#include <catch.hpp>

Public Member Functions

 Option ()
 
 Option (T const &_value)
 
 Option (Option const &_other)
 
 ~Option ()
 
Optionoperator= (Option const &_other)
 
Optionoperator= (T const &_value)
 
void reset ()
 
T & operator* ()
 
T const & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
valueOr (T const &defaultValue) const
 
bool some () const
 
bool none () const
 
bool operator! () const
 
 operator SafeBool::type () const
 

Private Attributes

T * nullableValue
 
char storage [sizeof(T)]
 

Detailed Description

template<typename T>
class Catch::Option< T >

Definition at line 2730 of file catch.hpp.

Constructor & Destructor Documentation

◆ Option() [1/3]

template<typename T >
Catch::Option< T >::Option ( )
inline

Definition at line 2732 of file catch.hpp.

2732 : nullableValue( CATCH_NULL ) {}
#define CATCH_NULL
Definition: catch.hpp:299
T * nullableValue
Definition: catch.hpp:2782

◆ Option() [2/3]

template<typename T >
Catch::Option< T >::Option ( T const &  _value)
inline

Definition at line 2733 of file catch.hpp.

2734  : nullableValue( new( storage ) T( _value ) )
2735  {}
char storage[sizeof(T)]
Definition: catch.hpp:2783

◆ Option() [3/3]

template<typename T >
Catch::Option< T >::Option ( Option< T > const &  _other)
inline

Definition at line 2736 of file catch.hpp.

2737  : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
2738  {}

◆ ~Option()

template<typename T >
Catch::Option< T >::~Option ( )
inline

Definition at line 2740 of file catch.hpp.

2740  {
2741  reset();
2742  }
void reset()
Definition: catch.hpp:2758

Member Function Documentation

◆ none()

template<typename T >
bool Catch::Option< T >::none ( ) const
inline

Definition at line 2774 of file catch.hpp.

2774 { return nullableValue == CATCH_NULL; }

References CATCH_NULL.

◆ operator SafeBool::type()

template<typename T >
Catch::Option< T >::operator SafeBool::type ( ) const
inline

Definition at line 2777 of file catch.hpp.

2777  {
2778  return SafeBool::makeSafe( some() );
2779  }
bool some() const
Definition: catch.hpp:2773
static type makeSafe(bool value)
Definition: catch.hpp:345

References Catch::SafeBool::makeSafe().

◆ operator!()

template<typename T >
bool Catch::Option< T >::operator! ( ) const
inline

Definition at line 2776 of file catch.hpp.

2776 { return nullableValue == CATCH_NULL; }

References CATCH_NULL.

◆ operator*() [1/2]

template<typename T >
T& Catch::Option< T >::operator* ( )
inline

Definition at line 2764 of file catch.hpp.

2764 { return *nullableValue; }

◆ operator*() [2/2]

template<typename T >
T const& Catch::Option< T >::operator* ( ) const
inline

Definition at line 2765 of file catch.hpp.

2765 { return *nullableValue; }

◆ operator->() [1/2]

template<typename T >
T* Catch::Option< T >::operator-> ( )
inline

Definition at line 2766 of file catch.hpp.

2766 { return nullableValue; }

◆ operator->() [2/2]

template<typename T >
const T* Catch::Option< T >::operator-> ( ) const
inline

Definition at line 2767 of file catch.hpp.

2767 { return nullableValue; }

◆ operator=() [1/2]

template<typename T >
Option& Catch::Option< T >::operator= ( Option< T > const &  _other)
inline

Definition at line 2744 of file catch.hpp.

2744  {
2745  if( &_other != this ) {
2746  reset();
2747  if( _other )
2748  nullableValue = new( storage ) T( *_other );
2749  }
2750  return *this;
2751  }

◆ operator=() [2/2]

template<typename T >
Option& Catch::Option< T >::operator= ( T const &  _value)
inline

Definition at line 2752 of file catch.hpp.

2752  {
2753  reset();
2754  nullableValue = new( storage ) T( _value );
2755  return *this;
2756  }

◆ reset()

template<typename T >
void Catch::Option< T >::reset ( )
inline

Definition at line 2758 of file catch.hpp.

2758  {
2759  if( nullableValue )
2760  nullableValue->~T();
2762  }

References CATCH_NULL.

◆ some()

template<typename T >
bool Catch::Option< T >::some ( ) const
inline

Definition at line 2773 of file catch.hpp.

2773 { return nullableValue != CATCH_NULL; }

References CATCH_NULL.

◆ valueOr()

template<typename T >
T Catch::Option< T >::valueOr ( T const &  defaultValue) const
inline

Definition at line 2769 of file catch.hpp.

2769  {
2770  return nullableValue ? *nullableValue : defaultValue;
2771  }

Field Documentation

◆ nullableValue

template<typename T >
T* Catch::Option< T >::nullableValue
private

Definition at line 2782 of file catch.hpp.

◆ storage

template<typename T >
char Catch::Option< T >::storage[sizeof(T)]
private

Definition at line 2783 of file catch.hpp.


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