HerkuleXLib  1.1
Arduino library to drive HerkuleX DRS-0101 and DRS-0201
Public Member Functions | Private Attributes | List of all members
HkxMaybe< T > Class Template Reference

Class to manage optional parameters. More...

#include <HkxCommunication.h>

Public Member Functions

 HkxMaybe ()
 Default constructor. More...
 
 HkxMaybe (hkxMaybeHasNoValue noValue)
 Empty constructor. More...
 
 HkxMaybe (T value)
 Copy value constructor. More...
 
 HkxMaybe (T *addressValue)
 Pointer value constructor. More...
 
 ~HkxMaybe ()
 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 HkxMaybe< T >

Class to manage optional parameters.

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

Constructor & Destructor Documentation

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

Default constructor.

The default constructor of HkxMaybe creates an empty parameter.

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

Empty constructor.

The empty constructor of HkxMaybe using HKX_NO_VALUE in order to simplify the writing of the code.

A function

foo(HkxMaybe<int> parameter)

can be called with an empty parameter.

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

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

Copy value constructor.

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

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

Pointer value constructor.

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

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

Default destructor.

The destructor delete the pointed value.

Member Function Documentation

template<typename T>
T& HkxMaybe< 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 HkxMaybe< 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 HkxMaybe< 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 HkxMaybe< T >::_empty
private

If empty => parameter to considered

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

Value of the parameter (if not empty)


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