some more doc for containers
This commit is contained in:
parent
a3903f80fb
commit
b7e3449b04
@ -6,10 +6,9 @@
|
|||||||
#include <framework/serialize/SerializeIF.h>
|
#include <framework/serialize/SerializeIF.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A List that stores its values in an array.
|
* @brief A List that stores its values in an array.
|
||||||
*
|
* @details The backend is an array that can be allocated
|
||||||
* The backend is an array that can be allocated by the class itself or supplied via ctor.
|
* by the class itself or supplied via ctor.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* @ingroup container
|
* @ingroup container
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Simple First-In-First-Out data structure
|
||||||
|
* @tparam T Entry Type
|
||||||
|
* @tparam capacity Maximum capacity
|
||||||
|
*/
|
||||||
template<typename T, uint8_t capacity>
|
template<typename T, uint8_t capacity>
|
||||||
class FIFO {
|
class FIFO {
|
||||||
private:
|
private:
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(HybridIterator other) {
|
bool operator==(HybridIterator other) {
|
||||||
return value == other->value;
|
return value == other.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(HybridIterator other) {
|
bool operator!=(HybridIterator other) {
|
||||||
|
@ -8,17 +8,24 @@
|
|||||||
#include <framework/globalfunctions/crc_ccitt.h>
|
#include <framework/globalfunctions/crc_ccitt.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index is the Type used for the list of indices.
|
||||||
|
*
|
||||||
|
* @tparam T Type which destribes the index. Needs to be a child of SerializeIF
|
||||||
|
* to be able to make it persistent
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Index: public SerializeIF{
|
class Index: public SerializeIF{
|
||||||
/**
|
/**
|
||||||
* Index is the Type used for the list of indices. The template parameter is the type which describes the index, it needs to be a child of SerializeIF to be able to make it persistent
|
*
|
||||||
*/
|
*/
|
||||||
static_assert(std::is_base_of<SerializeIF,T>::value,"Wrong Type for Index, Type must implement SerializeIF");
|
static_assert(std::is_base_of<SerializeIF,T>::value,
|
||||||
|
"Wrong Type for Index, Type must implement SerializeIF");
|
||||||
public:
|
public:
|
||||||
Index():blockStartAddress(0),size(0),storedPackets(0){}
|
Index():blockStartAddress(0),size(0),storedPackets(0){}
|
||||||
|
|
||||||
Index(uint32_t startAddress):blockStartAddress(startAddress),size(0),storedPackets(0){
|
Index(uint32_t startAddress):blockStartAddress(startAddress),
|
||||||
|
size(0),storedPackets(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBlockStartAddress(uint32_t newAddress) {
|
void setBlockStartAddress(uint32_t newAddress) {
|
||||||
@ -128,18 +135,26 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indexed Ring Memory Array is a class for a ring memory with indices.
|
||||||
|
* @details
|
||||||
|
* It assumes that the newest data comes in last
|
||||||
|
* It uses the currentWriteBlock as pointer to the current writing position
|
||||||
|
* The currentReadBlock must be set manually
|
||||||
|
* @tparam T
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class IndexedRingMemoryArray: public SerializeIF, public ArrayList<Index<T>, uint32_t>{
|
class IndexedRingMemoryArray: public SerializeIF, public ArrayList<Index<T>, uint32_t>{
|
||||||
/**
|
/**
|
||||||
* Indexed Ring Memory Array is a class for a ring memory with indices. It assumes that the newest data comes in last
|
*
|
||||||
* It uses the currentWriteBlock as pointer to the current writing position
|
|
||||||
* The currentReadBlock must be set manually
|
|
||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock, SerializeIF* additionalInfo,
|
IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock,
|
||||||
bool overwriteOld) :ArrayList<Index<T>,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld){
|
SerializeIF* additionalInfo, bool overwriteOld):
|
||||||
|
ArrayList<Index<T>,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),
|
||||||
|
indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),
|
||||||
|
lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld)
|
||||||
|
{
|
||||||
//Calculate the maximum number of indices needed for this blocksize
|
//Calculate the maximum number of indices needed for this blocksize
|
||||||
uint32_t maxNrOfIndices = floor(static_cast<double>(size)/static_cast<double>(bytesPerBlock));
|
uint32_t maxNrOfIndices = floor(static_cast<double>(size)/static_cast<double>(bytesPerBlock));
|
||||||
|
|
||||||
@ -148,6 +163,7 @@ public:
|
|||||||
if(additionalInfo!=NULL) {
|
if(additionalInfo!=NULL) {
|
||||||
serializedSize += additionalInfo->getSerializedSize();
|
serializedSize += additionalInfo->getSerializedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Size of current iterator type
|
//Size of current iterator type
|
||||||
Index<T> tempIndex;
|
Index<T> tempIndex;
|
||||||
serializedSize += tempIndex.getSerializedSize();
|
serializedSize += tempIndex.getSerializedSize();
|
||||||
@ -162,6 +178,7 @@ public:
|
|||||||
error << "IndexedRingMemory: Store is too small for index" << std::endl;
|
error << "IndexedRingMemory: Store is too small for index" << std::endl;
|
||||||
}
|
}
|
||||||
uint32_t useableSize = totalSize - serializedSize;
|
uint32_t useableSize = totalSize - serializedSize;
|
||||||
|
|
||||||
//Update the totalSize for calculations
|
//Update the totalSize for calculations
|
||||||
totalSize = useableSize;
|
totalSize = useableSize;
|
||||||
|
|
||||||
@ -182,8 +199,6 @@ public:
|
|||||||
error << "IndexedRingMemory: Invalid Number of Blocks: " << trueNumberOfBlocks;
|
error << "IndexedRingMemory: Invalid Number of Blocks: " << trueNumberOfBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Fill address into index
|
//Fill address into index
|
||||||
uint32_t address = trueStartAddress;
|
uint32_t address = trueStartAddress;
|
||||||
for (typename IndexedRingMemoryArray<T>::Iterator it = this->begin();it!=this->end();++it) {
|
for (typename IndexedRingMemoryArray<T>::Iterator it = this->begin();it!=this->end();++it) {
|
||||||
@ -193,7 +208,6 @@ public:
|
|||||||
address += bytesPerBlock;
|
address += bytesPerBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Initialize iterators
|
//Initialize iterators
|
||||||
currentWriteBlock = this->begin();
|
currentWriteBlock = this->begin();
|
||||||
currentReadBlock = this->begin();
|
currentReadBlock = this->begin();
|
||||||
@ -232,10 +246,10 @@ public:
|
|||||||
(*typeResetFnc)(it->modifyIndexType());
|
(*typeResetFnc)(it->modifyIndexType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Reading
|
* Reading
|
||||||
|
* @param it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void setCurrentReadBlock(typename IndexedRingMemoryArray<T>::Iterator it){
|
void setCurrentReadBlock(typename IndexedRingMemoryArray<T>::Iterator it){
|
||||||
currentReadBlock = it;
|
currentReadBlock = it;
|
||||||
currentReadBlockSizeCached = it->getSize();
|
currentReadBlockSizeCached = it->getSize();
|
||||||
@ -248,6 +262,7 @@ public:
|
|||||||
lastBlockToRead = currentWriteBlock;
|
lastBlockToRead = currentWriteBlock;
|
||||||
lastBlockToReadSize = currentWriteBlock->getSize();
|
lastBlockToReadSize = currentWriteBlock->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the last block to read to this iterator.
|
* Sets the last block to read to this iterator.
|
||||||
* Can be used to dump until block x
|
* Can be used to dump until block x
|
||||||
@ -292,8 +307,10 @@ public:
|
|||||||
uint32_t getCurrentReadAddress() const {
|
uint32_t getCurrentReadAddress() const {
|
||||||
return getAddressOfCurrentReadBlock() + currentReadSize;
|
return getAddressOfCurrentReadBlock() + currentReadSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds readSize to the current size and checks if the read has no more data left and advances the read block
|
* Adds readSize to the current size and checks if the read has no more data
|
||||||
|
* left and advances the read block.
|
||||||
* @param readSize The size that was read
|
* @param readSize The size that was read
|
||||||
* @return Returns true if the read can go on
|
* @return Returns true if the read can go on
|
||||||
*/
|
*/
|
||||||
@ -304,18 +321,22 @@ public:
|
|||||||
//the block has more data -> return true
|
//the block has more data -> return true
|
||||||
currentReadSize += readSize;
|
currentReadSize += readSize;
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
//Reached end of read -> return false
|
//Reached end of read -> return false
|
||||||
currentReadSize = lastBlockToReadSize;
|
currentReadSize = lastBlockToReadSize;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
//We are not in the last Block
|
//We are not in the last Block
|
||||||
if((currentReadSize + readSize)<currentReadBlockSizeCached) {
|
if((currentReadSize + readSize)<currentReadBlockSizeCached) {
|
||||||
//The current Block has more data
|
//The current Block has more data
|
||||||
currentReadSize += readSize;
|
currentReadSize += readSize;
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}
|
||||||
|
// TODO: Maybe some logic blocks should be extracted
|
||||||
|
else {
|
||||||
//The current block is written completely
|
//The current block is written completely
|
||||||
readNext();
|
readNext();
|
||||||
if(currentReadBlockSizeCached==0) {
|
if(currentReadBlockSizeCached==0) {
|
||||||
@ -421,13 +442,13 @@ public:
|
|||||||
T* modifyCurrentWriteBlockIndexType(){
|
T* modifyCurrentWriteBlockIndexType(){
|
||||||
return currentWriteBlock->modifyIndexType();
|
return currentWriteBlock->modifyIndexType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePreviousWriteSize(uint32_t size, uint32_t storedPackets){
|
void updatePreviousWriteSize(uint32_t size, uint32_t storedPackets){
|
||||||
typename IndexedRingMemoryArray<T>::Iterator it = getPreviousBlock(currentWriteBlock);
|
typename IndexedRingMemoryArray<T>::Iterator it = getPreviousBlock(currentWriteBlock);
|
||||||
it->addSize(size);
|
it->addSize(size);
|
||||||
it->addStoredPackets(storedPackets);
|
it->addStoredPackets(storedPackets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the block has enough space for sizeToWrite
|
* Checks if the block has enough space for sizeToWrite
|
||||||
* @param sizeToWrite The data to be written in the Block
|
* @param sizeToWrite The data to be written in the Block
|
||||||
@ -436,7 +457,10 @@ public:
|
|||||||
bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){
|
bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){
|
||||||
typename IndexedRingMemoryArray<T>::Iterator next = getNextWrite();
|
typename IndexedRingMemoryArray<T>::Iterator next = getNextWrite();
|
||||||
uint32_t addressOfNextBlock = next->getBlockStartAddress();
|
uint32_t addressOfNextBlock = next->getBlockStartAddress();
|
||||||
uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize;
|
uint32_t availableSize =
|
||||||
|
( ( addressOfNextBlock + totalSize ) -
|
||||||
|
(getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock()))
|
||||||
|
% totalSize;
|
||||||
return (sizeToWrite < availableSize);
|
return (sizeToWrite < availableSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -694,7 +718,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_ */
|
#endif /* FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_ */
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
/**
|
/**
|
||||||
* \ingroup container
|
* @brief Linked list data structure,
|
||||||
|
* each entry has a pointer to the next entry (singly)
|
||||||
|
* @ingroup container
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class LinkedElement {
|
class LinkedElement {
|
||||||
|
Loading…
Reference in New Issue
Block a user