2022-10-02 21:53:28 +00:00
|
|
|
#ifndef _TAVERAGE_HPP
|
|
|
|
#define _TAVERAGE_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "rstl/optional_object.hpp"
|
|
|
|
#include "rstl/vector.hpp"
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
class TAverage : rstl::vector< T > {
|
|
|
|
public:
|
|
|
|
TAverage() {}
|
|
|
|
TAverage(int capacity, const T& value);
|
2022-10-03 15:03:57 +00:00
|
|
|
void AddValue(const T& value);
|
2022-10-02 21:53:28 +00:00
|
|
|
rstl::optional_object< T > GetAverage() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
TAverage< T >::TAverage(int capacity, const T& value) {
|
|
|
|
resize(capacity, value);
|
|
|
|
}
|
|
|
|
|
2022-10-03 15:03:57 +00:00
|
|
|
template < typename T >
|
|
|
|
void TAverage< T >::AddValue(const T& value) {
|
|
|
|
push_back(value);
|
|
|
|
for (int i = size() - 1; i > 0; --i) {
|
|
|
|
operator[](i) = operator[](i - 1);
|
|
|
|
}
|
|
|
|
operator[](0) = value;
|
|
|
|
}
|
|
|
|
|
2022-10-02 21:53:28 +00:00
|
|
|
#endif
|