making code better with "const"

This commit is contained in:
rusefi 2019-01-15 21:03:45 -05:00
parent 0ffa05a911
commit 0a89fcca33
1 changed files with 14 additions and 14 deletions

View File

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