FIFOQueue: Support copying from another queue (pop -> push)

This commit is contained in:
Connor McLaughlin 2019-10-26 17:41:29 +10:00
parent 3ded9d46c1
commit 27674c2dc9

View file

@ -1,6 +1,7 @@
#pragma once
#include "YBaseLib/Assert.h"
#include "types.h"
#include <algorithm>
#include <cstring>
#include <type_traits>
@ -17,6 +18,8 @@ public:
constexpr u32 GetCapacity() const { return CAPACITY; }
u32 GetSize() const { return m_size; }
u32 GetSpace() const { return CAPACITY - m_size; }
u32 GetContiguousSpace() const { return (m_tail >= m_head) ? (CAPACITY - m_tail) : (m_head - m_tail); }
u32 GetContiguousSize() const { return std::min<u32>(CAPACITY - m_head, m_size); }
bool IsEmpty() const { return m_size == 0; }
bool IsFull() const { return m_size == CAPACITY; }
@ -131,6 +134,16 @@ public:
}
}
template<u32 CAPACITY>
void PushFromQueue(FIFOQueue<T, CAPACITY>* other_queue)
{
while (!other_queue->IsEmpty() && !IsFull())
{
T& dest = PushAndGetReference();
dest = std::move(other_queue->Pop());
}
}
protected:
FIFOQueue() = default;