HerkuleXLib  1
Arduino library to drive HerkuleX DRS0101 and DRS0201
Public Member Functions | Private Attributes | List of all members
Maybe< T > Class Template Reference

Class to manage optionnal parameters. More...

#include <HkxCommunication.h>

Public Member Functions

 Maybe ()
 Default constructor. More...
 
 Maybe (hkxMaybeHasNoValue noValue)
 Empty constructor. More...
 
 Maybe (T value)
 Copy value constructor. More...
 
 Maybe (T *addressValue)
 Pointer value constructor. More...
 
 ~Maybe ()
 Default destructor. More...
 
bool isEmpty () const
 Check if empty. More...
 
T & getValue () const
 Get the value. More...
 
void setValue (T value)
 Set the value. More...
 

Private Attributes

const bool _empty
 
T *const _value
 

Detailed Description

template<typename T>
class Maybe< T >

Class to manage optionnal parameters.

This class manages the optionnal parameters of the functions in order to avoid null pointer approach.

Constructor & Destructor Documentation

template<typename T>
Maybe< T >::Maybe ( )
inline

Default constructor.

The default constructor of Maybe creates an empty parameter.

template<typename T>
Maybe< T >::Maybe ( hkxMaybeHasNoValue  noValue)
inline

Empty constructor.

The empty constructor of Maybe using HKX_NO_VALUE in order to simplify the writting of the code.

A function

foo(Maybe<int> parameter)

can be called with an empty parameter.

foo(Maybe<int>())

This constructor allow the simpler implementation thanks to the implicite conversion.

foo(HKX_NO_VALUE)
Parameters
[in]noValue: this parameter can only have the value HKX_NO_VALUE.
template<typename T>
Maybe< T >::Maybe ( value)
inline

Copy value constructor.

This constructor is used for input optionnal parameters of function. Its value is copied and then cannot be returned when using implicite conversion.

Parameters
[in]value: value of any type.
template<typename T>
Maybe< T >::Maybe ( T *  addressValue)
inline

Pointer value constructor.

This constructor is used for output optionnal parameters of function. Its value is pointed and then can be returned when using implicite conversion.

Parameters
[in]addressValue: address of the value (any type).
template<typename T>
Maybe< T >::~Maybe ( )
inline

Default destructor.

The destructor delete the pointed value.

Member Function Documentation

template<typename T>
T& Maybe< T >::getValue ( ) const
inline

Get the value.

Get the value of the parameter if it has one.

Returns
nothing if the parameter is empty.
a copy of the value if the parameter has one.
template<typename T>
bool Maybe< T >::isEmpty ( ) const
inline

Check if empty.

Check if the parameter is empty or if it contains a value.

Returns
true if the parameter is empty.
false if the parameter contains a value.
template<typename T>
void Maybe< T >::setValue ( value)
inline

Set the value.

Set the value of the parameter if it is not empty. This member shall be use only when it was created with the pointer value constructor (for output optionnal parameter).

Parameters
[in]value: value to copy to the pointed value if the parameter is not empty.

Member Data Documentation

template<typename T>
const bool Maybe< T >::_empty
private

If empty => parameter to considered

template<typename T>
T* const Maybe< T >::_value
private

Value of the parameter (if not empty)


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