/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Containers/StaticRingBuffer.h
83 строки
3 KB
C-Core
Fixed cross platform serialization issues with visual scripts (#1408)
18 окт 2024, 09:33
Не верифицирован
18 окт 2024, 09:33
f1c37c8
Код
Авторство
О чём код?
#pragma once #include <Foundation/Containers/StaticArray.h> /// \brief A ring-buffer container that will use a static array of a given capacity to cycle through elements. /// /// If you need a dynamic ring-buffer, use an ezDeque. template <typename T, ezUInt32 Capacity> class ezStaticRingBuffer { public: static_assert(Capacity > 1, "ORLY?"); /// \brief Constructs an empty ring-buffer. ezStaticRingBuffer(); // [tested] /// \brief Copies the content from rhs into this ring-buffer. ezStaticRingBuffer(const ezStaticRingBuffer<T, Capacity>& rhs); // [tested] /// \brief Destructs all remaining elements. ~ezStaticRingBuffer(); // [tested] /// \brief Copies the content from rhs into this ring-buffer. void operator=(const ezStaticRingBuffer<T, Capacity>& rhs); // [tested] /// \brief Compares two ring-buffers for equality. bool operator==(const ezStaticRingBuffer<T, Capacity>& rhs) const; // [tested] EZ_ADD_DEFAULT_OPERATOR_NOTEQUAL(const ezStaticRingBuffer<T, Capacity>&); /// \brief Appends an element at the end of the ring-buffer. Asserts that CanAppend() is true. void PushBack(const T& element); // [tested] /// \brief Appends an element at the end of the ring-buffer. Asserts that CanAppend() is true. void PushBack(T&& element); // [tested] /// \brief Accesses the latest element in the ring-buffer. T& PeekBack(); // [tested] /// \brief Accesses the latest element in the ring-buffer. const T& PeekBack() const; // [tested] /// \brief Removes the oldest element from the ring-buffer. void PopFront(ezUInt32 uiElements = 1); // [tested] /// \brief Accesses the oldest element in the ring-buffer. const T& PeekFront() const; // [tested] /// \brief Accesses the oldest element in the ring-buffer. T& PeekFront(); // [tested] /// \brief Accesses the n-th element in the ring-buffer. const T& operator[](ezUInt32 uiIndex) const; // [tested] /// \brief Accesses the n-th element in the ring-buffer. T& operator[](ezUInt32 uiIndex); // [tested] /// \brief Returns the number of elements that are currently in the ring-buffer. ezUInt32 GetCount() const; // [tested] /// \brief Returns true if the ring-buffer currently contains no elements. bool IsEmpty() const; // [tested] /// \brief Returns true, if the ring-buffer can store at least uiElements additional elements. bool CanAppend(ezUInt32 uiElements = 1); // [tested] /// \brief Destructs all elements in the ring-buffer. void Clear(); // [tested] private: T* GetStaticArray(); /// \brief The fixed size array. struct alignas(alignof(T)) { ezUInt8 m_Data[Capacity * sizeof(T)]; }; T* m_pElements; ezUInt32 m_uiCount; ezUInt32 m_uiFirstElement; }; #include <Foundation/Containers/Implementation/StaticRingBuffer_inl.h>