Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1018 B

  1. // -----------------------------------------------------------------------------
  2. // Aggregator base class
  3. // -----------------------------------------------------------------------------
  4. #pragma once
  5. #include <vector>
  6. class AggregatorBase {
  7. public:
  8. AggregatorBase() {
  9. _data = new std::vector<double>();
  10. }
  11. ~AggregatorBase() {
  12. if (_data) delete _data;
  13. }
  14. virtual void add(double value) {
  15. _data->push_back(value);
  16. }
  17. virtual unsigned char count() {
  18. return _data->size();
  19. }
  20. virtual void reset() {
  21. _data->clear();
  22. }
  23. virtual double max() {
  24. double max = 0;
  25. for (unsigned char i = 1; i < _data->size(); i++) {
  26. if (max < _data->at(i)) max = _data->at(i);
  27. }
  28. return max;
  29. }
  30. virtual double result() {
  31. return 0;
  32. }
  33. protected:
  34. std::vector<double> *_data;
  35. };