2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _TAVERAGE
|
|
|
|
#define _TAVERAGE
|
2022-10-02 21:53:28 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "rstl/optional_object.hpp"
|
|
|
|
#include "rstl/vector.hpp"
|
|
|
|
|
2022-10-21 01:32:04 +00:00
|
|
|
template < typename T >
|
|
|
|
T GetAverageValue(const T* ptr, int count); // TODO
|
|
|
|
|
2022-10-02 21:53:28 +00:00
|
|
|
template < typename T >
|
|
|
|
class TAverage : rstl::vector< T > {
|
|
|
|
public:
|
|
|
|
TAverage() {}
|
|
|
|
TAverage(int capacity, const T& value);
|
2022-10-21 01:32:04 +00:00
|
|
|
|
2022-10-03 15:03:57 +00:00
|
|
|
void AddValue(const T& value);
|
2022-10-04 00:00:46 +00:00
|
|
|
rstl::optional_object< T > GetAverage() const {
|
2022-10-21 01:32:04 +00:00
|
|
|
if (this->empty()) {
|
2022-10-04 00:00:46 +00:00
|
|
|
return rstl::optional_object_null();
|
|
|
|
} else {
|
2022-10-21 01:32:04 +00:00
|
|
|
return GetAverageValue(this->data(), this->size());
|
2022-10-04 00:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-02 21:53:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
TAverage< T >::TAverage(int capacity, const T& value) {
|
2022-10-21 01:32:04 +00:00
|
|
|
this->resize(capacity, value);
|
2022-10-02 21:53:28 +00:00
|
|
|
}
|
|
|
|
|
2022-10-03 15:03:57 +00:00
|
|
|
template < typename T >
|
|
|
|
void TAverage< T >::AddValue(const T& value) {
|
2022-10-21 01:32:04 +00:00
|
|
|
if (this->size() == this->capacity()) {
|
2022-10-04 00:00:46 +00:00
|
|
|
// TODO ?
|
2022-10-21 01:32:04 +00:00
|
|
|
this->x4_count -= 1;
|
2022-10-03 15:03:57 +00:00
|
|
|
}
|
2022-10-21 01:32:04 +00:00
|
|
|
this->insert(this->begin(), value);
|
2022-10-03 15:03:57 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _TAVERAGE
|