Antkeeper  0.0.1
Public Types | Public Member Functions | List of all members
math::moving_average< T > Class Template Reference

Calculates a moving average. More...

#include <moving-average.hpp>

Public Types

using sample_type = T
 Type of value to average. More...
 

Public Member Functions

sample_type operator() (sample_type value) noexcept
 Adds a sample to the moving average. More...
 
void reset () noexcept
 Resets the moving average. More...
 
void reserve (std::size_t capacity)
 Changes the sample capacity of the moving average. More...
 
void resize (std::size_t size)
 Changes the current number of samples of the moving average. More...
 
constexpr sample_typedata () const noexcept
 Returns a pointer to the sample data. More...
 
sample_type average () const noexcept
 Returns the current moving average value. More...
 
sample_type sum () const noexcept
 Returns the sum of all current samples. More...
 
std::size_t size () const noexcept
 Returns the current number of samples. More...
 
constexpr std::size_t capacity () const noexcept
 Returns the maximum number of samples. More...
 
constexpr bool empty () const noexcept
 Return true if there are currently no samples in the average, false otherwise. More...
 
constexpr bool full () const noexcept
 Return true if the number of samples in the average has reached its capacity, false otherwise. More...
 
 moving_average (std::size_t capacity)
 Constructs a moving average. More...
 
 moving_average () noexcept=default
 Constructs a moving average. More...
 

Detailed Description

template<class T>
class math::moving_average< T >

Calculates a moving average.

Template Parameters
TSample value type.

Definition at line 35 of file moving-average.hpp.

Member Typedef Documentation

◆ sample_type

template<class T >
using math::moving_average< T >::sample_type = T

Type of value to average.

Definition at line 39 of file moving-average.hpp.

Constructor & Destructor Documentation

◆ moving_average() [1/2]

template<class T >
math::moving_average< T >::moving_average ( std::size_t  capacity)
inlineexplicit

Constructs a moving average.

Parameters
capacitySample capacity.

Definition at line 47 of file moving-average.hpp.

◆ moving_average() [2/2]

template<class T >
math::moving_average< T >::moving_average ( )
defaultnoexcept

Constructs a moving average.

Parameters
capacitySample capacity.

Member Function Documentation

◆ average()

template<class T >
sample_type math::moving_average< T >::average ( ) const
inlinenoexcept

Returns the current moving average value.

Definition at line 122 of file moving-average.hpp.

◆ capacity()

template<class T >
constexpr std::size_t math::moving_average< T >::capacity ( ) const
inlineconstexprnoexcept

Returns the maximum number of samples.

Definition at line 140 of file moving-average.hpp.

◆ data()

template<class T >
constexpr sample_type* math::moving_average< T >::data ( ) const
inlineconstexprnoexcept

Returns a pointer to the sample data.

Definition at line 116 of file moving-average.hpp.

◆ empty()

template<class T >
constexpr bool math::moving_average< T >::empty ( ) const
inlineconstexprnoexcept

Return true if there are currently no samples in the average, false otherwise.

Definition at line 146 of file moving-average.hpp.

◆ full()

template<class T >
constexpr bool math::moving_average< T >::full ( ) const
inlineconstexprnoexcept

Return true if the number of samples in the average has reached its capacity, false otherwise.

Definition at line 152 of file moving-average.hpp.

◆ operator()()

template<class T >
sample_type math::moving_average< T >::operator() ( sample_type  value)
inlinenoexcept

Adds a sample to the moving average.

If the moving average has reached its sample capacity, the oldest sample will be discarded.

Parameters
valueSample value.
Returns
Current average value.

Definition at line 60 of file moving-average.hpp.

◆ reserve()

template<class T >
void math::moving_average< T >::reserve ( std::size_t  capacity)
inline

Changes the sample capacity of the moving average.

Parameters
capacitySample capacity.

Definition at line 96 of file moving-average.hpp.

◆ reset()

template<class T >
void math::moving_average< T >::reset ( )
inlinenoexcept

Resets the moving average.

Definition at line 84 of file moving-average.hpp.

◆ resize()

template<class T >
void math::moving_average< T >::resize ( std::size_t  size)
inline

Changes the current number of samples of the moving average.

Parameters
sizeNumber of samples

Definition at line 106 of file moving-average.hpp.

◆ size()

template<class T >
std::size_t math::moving_average< T >::size ( ) const
inlinenoexcept

Returns the current number of samples.

Definition at line 134 of file moving-average.hpp.

◆ sum()

template<class T >
sample_type math::moving_average< T >::sum ( ) const
inlinenoexcept

Returns the sum of all current samples.

Definition at line 128 of file moving-average.hpp.


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