mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-22 15:49:57 -05:00
Extract range_t to utility header.
This commit is contained in:
parent
c761d3aaa8
commit
018b54c711
@ -23,30 +23,14 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace portapack {
|
||||
namespace persistent_memory {
|
||||
|
||||
/* TODO: This is widely applicable. Factor this to somewhere useful. */
|
||||
template<class T>
|
||||
struct range_t {
|
||||
const T minimum;
|
||||
const T maximum;
|
||||
|
||||
const T& clip(const T& value) const {
|
||||
return std::max(std::min(value, maximum), minimum);
|
||||
}
|
||||
|
||||
void reset_if_outside(T& value, const T& reset_value) const {
|
||||
if( (value < minimum ) ||
|
||||
(value > maximum ) ) {
|
||||
value = reset_value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using tuned_frequency_range_t = range_t<rf::Frequency>;
|
||||
constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max };
|
||||
constexpr rf::Frequency tuned_frequency_reset_value { 858750000 };
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <type_traits>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
|
||||
@ -70,6 +71,23 @@ inline float magnitude_squared(const std::complex<float> c) {
|
||||
return r2 + i2;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct range_t {
|
||||
const T minimum;
|
||||
const T maximum;
|
||||
|
||||
const T& clip(const T& value) const {
|
||||
return std::max(std::min(value, maximum), minimum);
|
||||
}
|
||||
|
||||
void reset_if_outside(T& value, const T& reset_value) const {
|
||||
if( (value < minimum ) ||
|
||||
(value > maximum ) ) {
|
||||
value = reset_value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace std {
|
||||
|
||||
/*! Stephan T Lavavej (STL!) implementation of make_unique, which has been accepted into the C++14 standard.
|
||||
|
Loading…
x
Reference in New Issue
Block a user