Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
distortos/include/distortos/StaticRawFifoQueue.hpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (56 sloc)
1.58 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* \file | |
* \brief StaticRawFifoQueue class header | |
* | |
* \author Copyright (C) 2015-2022 Kamil Szczygiel https://distortec.com https://freddiechopin.info | |
* | |
* \par License | |
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not | |
* distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
*/ | |
#ifndef INCLUDE_DISTORTOS_STATICRAWFIFOQUEUE_HPP_ | |
#define INCLUDE_DISTORTOS_STATICRAWFIFOQUEUE_HPP_ | |
#include "RawFifoQueue.hpp" | |
#include "distortos/internal/memory/dummyDeleter.hpp" | |
#include <array> | |
namespace distortos | |
{ | |
/** | |
* \brief StaticRawFifoQueue class is a variant of RawFifoQueue that has automatic storage for queue's contents. | |
* | |
* \tparam ElementSize is the size of single queue element, bytes | |
* \tparam QueueSize is the maximum number of elements in queue | |
* | |
* \ingroup queues | |
*/ | |
template<size_t ElementSize, size_t QueueSize> | |
class StaticRawFifoQueue : public RawFifoQueue | |
{ | |
public: | |
/** | |
* \brief StaticRawFifoQueue's constructor | |
*/ | |
explicit StaticRawFifoQueue() : | |
RawFifoQueue{{storage_.data(), internal::dummyDeleter<uint8_t>}, ElementSize, QueueSize} | |
{ | |
} | |
/** | |
* \return maximum number of elements in queue | |
*/ | |
constexpr static size_t getCapacity() | |
{ | |
return QueueSize; | |
} | |
/** | |
* \return size of single queue element, bytes | |
*/ | |
constexpr static size_t getElementSize() | |
{ | |
return ElementSize; | |
} | |
private: | |
/// storage for queue's contents | |
std::array<uint8_t, ElementSize * QueueSize> storage_; | |
}; | |
} // namespace distortos | |
#endif // INCLUDE_DISTORTOS_STATICRAWFIFOQUEUE_HPP_ |