fsfw/container/FIFOBase.tpp

94 lines
2.0 KiB
C++
Raw Permalink Normal View History

2020-08-27 20:19:27 +02:00
#ifndef FSFW_CONTAINER_FIFOBASE_TPP_
#define FSFW_CONTAINER_FIFOBASE_TPP_
2020-07-06 13:26:58 +02:00
2020-08-27 20:19:27 +02:00
#ifndef FSFW_CONTAINER_FIFOBASE_H_
2020-07-06 13:26:58 +02:00
#error Include FIFOBase.h before FIFOBase.tpp!
#endif
template<typename T>
inline FIFOBase<T>::FIFOBase(T* values, const size_t maxCapacity):
maxCapacity(maxCapacity), values(values){};
2020-07-06 13:26:58 +02:00
template<typename T>
inline ReturnValue_t FIFOBase<T>::insert(T value) {
if (full()) {
return FULL;
} else {
values[writeIndex] = value;
writeIndex = next(writeIndex);
++currentSize;
return HasReturnvaluesIF::RETURN_OK;
}
2020-07-06 13:26:58 +02:00
};
template<typename T>
inline ReturnValue_t FIFOBase<T>::retrieve(T* value) {
if (empty()) {
return EMPTY;
} else {
if (value == nullptr){
return HasReturnvaluesIF::RETURN_FAILED;
}
*value = values[readIndex];
readIndex = next(readIndex);
--currentSize;
return HasReturnvaluesIF::RETURN_OK;
}
2020-07-06 13:26:58 +02:00
};
template<typename T>
inline ReturnValue_t FIFOBase<T>::peek(T* value) {
if(empty()) {
return EMPTY;
} else {
if (value == nullptr){
return HasReturnvaluesIF::RETURN_FAILED;
}
*value = values[readIndex];
return HasReturnvaluesIF::RETURN_OK;
}
2020-07-06 13:26:58 +02:00
};
template<typename T>
inline ReturnValue_t FIFOBase<T>::pop() {
T value;
return this->retrieve(&value);
2020-07-06 13:26:58 +02:00
};
template<typename T>
inline bool FIFOBase<T>::empty() {
return (currentSize == 0);
2020-07-06 13:26:58 +02:00
};
template<typename T>
inline bool FIFOBase<T>::full() {
return (currentSize == maxCapacity);
2020-07-06 13:26:58 +02:00
}
template<typename T>
inline size_t FIFOBase<T>::size() {
return currentSize;
2020-07-06 13:26:58 +02:00
}
template<typename T>
inline size_t FIFOBase<T>::next(size_t current) {
++current;
if (current == maxCapacity) {
current = 0;
}
return current;
2020-07-06 13:26:58 +02:00
}
2020-07-06 23:08:31 +02:00
template<typename T>
inline size_t FIFOBase<T>::getMaxCapacity() const {
return maxCapacity;
2020-07-06 23:08:31 +02:00
}
2020-07-28 13:13:40 +02:00
template<typename T>
2020-09-01 12:53:53 +02:00
inline void FIFOBase<T>::setContainer(T *data) {
this->values = data;
2020-07-28 13:13:40 +02:00
}
2020-07-06 13:26:58 +02:00
#endif