This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/Delay.h
2018-10-25 11:50:12 +02:00

58 lines
963 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef DELAY_H
#define DELAY_H
#include <cstdint>
#include <vector>
template <typename T> class Delay {
private:
size_t size;
/** up to "size" elements */
std::vector<T> values;
public:
/** ctor */
Delay(const int size) : size(size) {;}
/** add a new value */
void add(const T val) {
// add new value
values.push_back(val);
// remove old ones
while(values.size() > size) {
values.erase(values.begin());
}
}
/** get the delayed value */
T get() const {
return values.front();
}
/** delay output valid? */
bool isValid() const {
return values.size() == size;
}
};
#endif // DELAY_H