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/stats/Maximum.h
2018-10-25 11:50:12 +02:00

54 lines
1.0 KiB
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 STATS_MAXIMUM_H
#define STATS_MAXIMUM_H
#include "../../Assertions.h"
#include <limits>
namespace Stats {
template <typename Scalar> class Maximum {
private:
const Scalar START = std::numeric_limits<Scalar>::lowest();
Scalar curMax;
public:
/** ctor */
Maximum() : curMax(START) {
;
}
/** is a valid maximum available? */
inline bool isValid() const {
return curMax != START;
}
/** add a new value */
inline void add(const Scalar val) {
if (val > curMax) {curMax = val;}
}
/** get the current value */
inline Scalar get() const {
Assert::notEqual(curMax, START, "add() values first!");
return curMax;
}
};
}
#endif // STATS_MAXIMUM_H