making code better with "const"

This commit is contained in:
rusefi 2019-01-15 21:03:45 -05:00
parent 86a0d67d70
commit 36cb5e3238
1 changed files with 14 additions and 14 deletions

View File

@ -37,14 +37,14 @@ class cyclic_buffer
public: public:
void add(T value); void add(T value);
T get(int index); T get(int index) const;
T sum(int length); T sum(int length) const;
T maxValue(int length); T maxValue(int length) const;
T minValue(int length); T minValue(int length) const;
void setSize(int size); void setSize(int size);
bool contains(T value); bool contains(T value) const;
int getSize(); int getSize() const;
int getCount(); int getCount() const;
void clear(); void clear();
volatile T elements[maxSize]; volatile T elements[maxSize];
volatile int currentIndex; volatile int currentIndex;
@ -115,7 +115,7 @@ void cyclic_buffer<T, maxSize>::add(T value) {
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
bool cyclic_buffer<T, maxSize>::contains(T value) { bool cyclic_buffer<T, maxSize>::contains(T value) const {
for (int i = 0; i < currentIndex ; i++) { for (int i = 0; i < currentIndex ; i++) {
if (elements[i] == value) { if (elements[i] == value) {
return TRUE; return TRUE;
@ -131,17 +131,17 @@ void cyclic_buffer<T, maxSize>::setSize(int size) {
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
int cyclic_buffer<T, maxSize>::getSize() { int cyclic_buffer<T, maxSize>::getSize() const {
return size; return size;
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
int cyclic_buffer<T, maxSize>::getCount() { int cyclic_buffer<T, maxSize>::getCount() const {
return count; return count;
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
T cyclic_buffer<T, maxSize>::get(int index) { T cyclic_buffer<T, maxSize>::get(int index) const {
while (index < 0) { while (index < 0) {
index += size; index += size;
} }
@ -152,7 +152,7 @@ T cyclic_buffer<T, maxSize>::get(int index) {
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
T cyclic_buffer<T, maxSize>::maxValue(int length) { T cyclic_buffer<T, maxSize>::maxValue(int length) const {
if (length > count) { if (length > count) {
// not enough data in buffer // not enough data in buffer
length = count; length = count;
@ -173,7 +173,7 @@ T cyclic_buffer<T, maxSize>::maxValue(int length) {
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
T cyclic_buffer<T, maxSize>::minValue(int length) { T cyclic_buffer<T, maxSize>::minValue(int length) const {
if (length > count) { if (length > count) {
length = count; length = count;
} }
@ -193,7 +193,7 @@ T cyclic_buffer<T, maxSize>::minValue(int length) {
} }
template<typename T, size_t maxSize> template<typename T, size_t maxSize>
T cyclic_buffer<T, maxSize>::sum(int length) { T cyclic_buffer<T, maxSize>::sum(int length) const {
if (length > count) { if (length > count) {
length = count; length = count;
} }