TSDuck v3.36-3298
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::Variable< T > Class Template Reference

A template class which defines a variable which can be either initialized or uninitialized. More...

#include <tsVariable.h>

Public Member Functions

 Variable () noexcept
 Default constructor, the variable is uninitialized.
 
 Variable (const T &obj)
 Constructor from a T instance, the variable is initialized.
 
 Variable (const Variable< T > &other)
 Copy constructor.
 
 Variable (Variable< T > &&other)
 Move constructor.
 
virtual ~Variable ()
 Virtual destructor.
 
void clear ()
 Clear the value.
 
bool identical (const Variable< T > &other) const
 Identity.
 
bool operator!= (const T &obj) const
 Unequality operator with a T instance.
 
bool operator!= (const Variable< T > &other) const
 Unequality operator.
 
Variable< T > & operator= (const T &obj)
 Assignment operator from a T object.
 
Variable< T > & operator= (const Variable< T > &other)
 Assignment operator.
 
Variable< T > & operator= (Variable< T > &&other)
 Move assignment operator.
 
bool operator== (const T &obj) const
 Equality operator with a T instance.
 
bool operator== (const Variable< T > &other) const
 Equality operator.
 
bool set () const
 Check the presence of a value.
 
bool setDefault (const T &def)
 Set a value if the variable is currently unset.
 
Tvalue ()
 Access the T value inside the variable.
 
const Tvalue () const
 Access the constant T value inside the variable.
 
T value (const T &def) const
 Get a copy of the T value inside the variable or a default value.
 

Detailed Description

template<typename T>
class ts::Variable< T >

A template class which defines a variable which can be either initialized or uninitialized.

Template Parameters
TA type or class which describes the content of the variable. The basic requirement on T is the availability of a copy constructor and operators for assignment and equality.

Constructor & Destructor Documentation

◆ Variable() [1/3]

template<typename T >
ts::Variable< T >::Variable ( const Variable< T > &  other)

Copy constructor.

This object is in the same state as other. If other is initialized, this object becomes initialized with the same T value.

Parameters
[in]otherAnother instance from which to build this object.

◆ Variable() [2/3]

template<typename T >
ts::Variable< T >::Variable ( Variable< T > &&  other)

Move constructor.

Parameters
[in,out]otherAnother instance from which to build this object.

◆ Variable() [3/3]

template<typename T >
ts::Variable< T >::Variable ( const T obj)
inline

Constructor from a T instance, the variable is initialized.

Parameters
[in]objThe initial value for the variable.

Member Function Documentation

◆ operator=() [1/3]

template<typename T >
ts::Variable< T > & ts::Variable< T >::operator= ( const Variable< T > &  other)

Assignment operator.

This object is in the same state as other. If other is initialized, this object becomes initialized with the same T value.

Parameters
[in]otherAnother instance from which to assign this object.
Returns
A reference to this object.

◆ operator=() [2/3]

template<typename T >
ts::Variable< T > & ts::Variable< T >::operator= ( Variable< T > &&  other)

Move assignment operator.

Parameters
[in,out]otherAnother instance from which to assign this object.
Returns
A reference to this object.

◆ operator=() [3/3]

template<typename T >
ts::Variable< T > & ts::Variable< T >::operator= ( const T obj)

Assignment operator from a T object.

This object becomes initialized if it was not already.

Parameters
[in]objValue from which to assign this object.
Returns
A reference to this object.

◆ set()

template<typename T >
bool ts::Variable< T >::set ( ) const
inline

Check the presence of a value.

Returns
True if the variable is initialized, false otherwise.

◆ setDefault()

template<typename T >
bool ts::Variable< T >::setDefault ( const T def)

Set a value if the variable is currently unset.

Do nothing if the variable is already initialized.

Parameters
[in]defA default T value if the variable is uninitialized.
Returns
True if the variable was not initialized and the default value was set, false if the variable was already initialized.

◆ clear()

template<typename T >
void ts::Variable< T >::clear ( )

Clear the value.

This object becomes uninitialized if it was not already.

◆ value() [1/3]

template<typename T >
const T & ts::Variable< T >::value ( ) const

Access the constant T value inside the variable.

Returns
A constant reference to the T value inside the variable.
Exceptions
UninitializedVariableIf the variable is uninitialized.

◆ value() [2/3]

template<typename T >
T & ts::Variable< T >::value ( )

Access the T value inside the variable.

Returns
A reference to the T value inside the variable.
Exceptions
UninitializedVariableIf the variable is uninitialized.

◆ value() [3/3]

template<typename T >
T ts::Variable< T >::value ( const T def) const

Get a copy of the T value inside the variable or a default value.

Parameters
[in]defA default T value if the variable is uninitialized.
Returns
A copy the T value inside the variable if the variable is initialized, def otherwise.

◆ operator==() [1/2]

template<typename T >
bool ts::Variable< T >::operator== ( const Variable< T > &  other) const

Equality operator.

Parameters
[in]otherAn other instance to compare with.
Returns
True if both instances are initialized and contain equal values.

◆ operator!=() [1/2]

template<typename T >
bool ts::Variable< T >::operator!= ( const Variable< T > &  other) const

Unequality operator.

Parameters
[in]otherAn other instance to compare with.
Returns
True if any instance is uninitialized or both are initialized with unequal values.

◆ operator==() [2/2]

template<typename T >
bool ts::Variable< T >::operator== ( const T obj) const

Equality operator with a T instance.

Parameters
[in]objAn object to compare with.
Returns
True if this object is initialized and its value is equal to obj.

◆ operator!=() [2/2]

template<typename T >
bool ts::Variable< T >::operator!= ( const T obj) const

Unequality operator with a T instance.

Parameters
[in]objAn object to compare with.
Returns
True if this object is uninitialized or its value is not equal to obj.

◆ identical()

template<typename T >
bool ts::Variable< T >::identical ( const Variable< T > &  other) const

Identity.

Parameters
[in]otherAn other instance to compare with.
Returns
True if both instances are initialized and contain equal values or if both instance and not initialized.

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