Evo C++ Library v0.5.1
Public Types | Public Member Functions | List of all members
Nullable< T > Class Template Reference

#include <evo/type.h>

Inheritance diagram for Nullable< T >:
Inheritance graph
[legend]

Detailed Description

template<class T>
class evo::Nullable< T >

Nullable primitive base type.

Public Types

typedef void EvoNullableType
 Identify as nullable type. More...
 

Public Member Functions

 Nullable ()
 Constructor. More...
 
 Nullable (const Nullable< T > &src)
 Copy constructor. More...
 
 Nullable (ValNull)
 Constructor to explicitly set as null. More...
 
 Nullable (T num)
 Constructor to init with num. More...
 
int compare (const Nullable< T > &val) const
 Comparison. More...
 
int compare (T val) const
 Comparison. More...
 
T & denull ()
 Clears null flag and returns value reference. More...
 
bool null () const
 Get whether null. More...
 
 operator SafeBoolType () const
 Safe (explicit) evaluation as bool type. More...
 
bool operator! () const
 Negation operator returns whether null or 0. More...
 
bool operator!= (const Nullable< T > &val) const
 Inequality operator. More...
 
bool operator!= (T val) const
 Inequality operator. More...
 
const T & operator* () const
 Dereference for explicit conversion to underlying type (const). More...
 
T & operator* ()
 Dereference for explicit conversion to underlying type. More...
 
bool operator< (const Nullable< T > &val) const
 Less than operator. More...
 
bool operator< (T val) const
 Less than operator. More...
 
bool operator<= (const Nullable< T > &val) const
 Less than or equal operator. More...
 
bool operator<= (T val) const
 Less than or equal operator. More...
 
Nullable< T > & operator= (const Nullable< T > &src)
 Assignment/Copy operator. More...
 
Nullable< T > & operator= (T value)
 Constructor to init with value. More...
 
Nullable< T > & operator= (ValNull)
 Assignment operator to set as null. More...
 
bool operator== (const Nullable< T > &val) const
 Equality operator. More...
 
bool operator== (T val) const
 Equality operator. More...
 
bool operator> (const Nullable< T > &val) const
 Greater than operator. More...
 
bool operator> (T val) const
 Greater than operator. More...
 
bool operator>= (const Nullable< T > &val) const
 Greater than or equal operator. More...
 
bool operator>= (T val) const
 Greater than or equal operator. More...
 
Nullable< T > & set ()
 Set as null. More...
 
Nullable< T > & set (const Nullable< T > &src)
 Set as copy of given value. More...
 
Nullable< T > & set (T src)
 Set as given value. More...
 
bool valid () const
 Get whether valid (not null). More...
 
const T & value () const
 Get underlying value (const). More...
 
T & value ()
 Get underlying value. More...
 

Member Typedef Documentation

◆ EvoNullableType

typedef void EvoNullableType

Identify as nullable type.

Constructor & Destructor Documentation

◆ Nullable() [1/4]

Nullable ( )
inline

Constructor.

◆ Nullable() [2/4]

Nullable ( const Nullable< T > &  src)
inline

Copy constructor.

Parameters
srcSource to copy

◆ Nullable() [3/4]

Nullable ( ValNull  )
inline

Constructor to explicitly set as null.

  • Use param vNULL

◆ Nullable() [4/4]

Nullable ( num)
inline

Constructor to init with num.

Parameters
numNumber to use

Member Function Documentation

◆ compare() [1/2]

int compare ( const Nullable< T > &  val) const
inline

Comparison.

Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ compare() [2/2]

int compare ( val) const
inline

Comparison.

  • If null, the result is always -1 as null compares as less than any non-null value
Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ denull()

T& denull ( )
inline

Clears null flag and returns value reference.

  • Value is unchanged, POD types default to 0 when null
  • Useful for updating the underlying value by reference
  • Note: Nullable<bool> template specialization returns by value instead of reference
Returns
Whether valid

◆ null()

bool null ( ) const
inline

Get whether null.

Returns
Whether null

◆ operator SafeBoolType()

operator SafeBoolType ( ) const
inlineinherited

Safe (explicit) evaluation as bool type.

  • This is called when object is directly evaluated as a bool, and is equivalent to: !operator!()
  • See SafeBool

◆ operator!()

bool operator! ( ) const
inline

Negation operator returns whether null or 0.

Returns
Whether null or 0

◆ operator!=() [1/2]

bool operator!= ( const Nullable< T > &  val) const
inline

Inequality operator.

Parameters
valValue to compare to
Returns
Whether inequal

◆ operator!=() [2/2]

bool operator!= ( val) const
inline

Inequality operator.

  • If null, the result is always true as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether inequal, true if null

◆ operator*() [1/2]

const T& operator* ( ) const
inline

Dereference for explicit conversion to underlying type (const).

Alternative to value().

Returns
Underlying type value

◆ operator*() [2/2]

T& operator* ( )
inline

Dereference for explicit conversion to underlying type.

Alternative to value().

Returns
Underlying type value

◆ operator<() [1/2]

bool operator< ( const Nullable< T > &  val) const
inline

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<() [2/2]

bool operator< ( val) const
inline

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<=() [1/2]

bool operator<= ( const Nullable< T > &  val) const
inline

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator<=() [2/2]

bool operator<= ( val) const
inline

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator=() [1/3]

Nullable<T>& operator= ( const Nullable< T > &  src)
inline

Assignment/Copy operator.

Parameters
srcSource to copy
Returns
This

◆ operator=() [2/3]

Nullable<T>& operator= ( value)
inline

Constructor to init with value.

Parameters
valueNumber to use
Returns
This

◆ operator=() [3/3]

Nullable<T>& operator= ( ValNull  )
inline

Assignment operator to set as null.

  • Use param vNULL to set as null
Returns
This

◆ operator==() [1/2]

bool operator== ( const Nullable< T > &  val) const
inline

Equality operator.

Parameters
valValue to compare to
Returns
Whether equal

◆ operator==() [2/2]

bool operator== ( val) const
inline

Equality operator.

  • If null, the result is always false as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether equal, false if null

◆ operator>() [1/2]

bool operator> ( const Nullable< T > &  val) const
inline

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>() [2/2]

bool operator> ( val) const
inline

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>=() [1/2]

bool operator>= ( const Nullable< T > &  val) const
inline

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ operator>=() [2/2]

bool operator>= ( val) const
inline

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ set() [1/3]

Nullable<T>& set ( )
inline

Set as null.

Returns
This

◆ set() [2/3]

Nullable<T>& set ( const Nullable< T > &  src)
inline

Set as copy of given value.

Parameters
srcSource to copy
Returns
This

◆ set() [3/3]

Nullable<T>& set ( src)
inline

Set as given value.

Parameters
srcSource to set
Returns
This

◆ valid()

bool valid ( ) const
inline

Get whether valid (not null).

Returns
Whether valid

◆ value() [1/2]

const T& value ( ) const
inline

Get underlying value (const).

Alternative to operator*().

Returns
Whether valid

◆ value() [2/2]

T& value ( )
inline

Get underlying value.

Alternative to operator*().

Returns
Whether valid

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