Queue< T > Class Template Reference

#include <queue.h>

详细描述

template<typename T>
class maxon::Queue< T >

A Queue that holds elements of type T, stored in a circular buffer. Supports access from both ends.

Public Types

using  ValueType = T

公共成员函数

  Queue ()=default
  Queue (const Queue &)=delete
Queue operator= (const Queue &)=delete
  Queue ( Queue && src )
Queue operator= ( Queue && src )
Int   GetCount () const
Bool   IsEmpty () const
Bool   IsPopulated () const
可选 < T & >  Peek ()
可选 < const T & >  Peek () const
可选 < T & >  PeekBack ()
可选 < const T & >  PeekBack () const
ResultMem   Push (T value)
ResultMem   PushFront (T value)
template<typename ... ARGS>
ResultMem   Emplace (ARGS &&... args)
template<typename ... ARGS>
ResultMem   EmplaceFront (ARGS &&... args)
可选 < T >  Pop ()
可选 < T >  PopBack ()
Bool   Truncate ()
Bool   TruncateBack ()
void  Flush ()
void  重置 ()
Block < T >  AlignAsBlock ()
  ~Queue ()
Result < void >  CopyFrom (const Queue & src )
ResultMem   EnsureCapacity ( Int requestedSize)

私有成员函数

void  Linearize ()
Bool   IsAtFullCapacity () const
Int   CalcNewCapacity ( Int targetSize) const
Bool   Grow ( Int targetSize=0)
Result < void >  CopyDataToNewBuffer (T *destPtr) const
void  MoveDataToNewBuffer (T *destPtr)
void  PushToHead (T &&value)
void  PushToTail (T &&value)
template<typename ... ARGS>
void  EmplaceAtHead (ARGS &&... args)
template<typename ... ARGS>
void  EmplaceAtTail (ARGS &&... args)
PopFromTail ()
PopFromHead ()
void  TruncateTail ()
void  TruncateHead ()

Static Private Member Functions

static MAXON_ATTRIBUTE_FORCE_INLINE void  IncrementIndex ( Int &index, Int capacity)
static MAXON_ATTRIBUTE_FORCE_INLINE void  DecrementIndex ( Int &index, Int capacity)

Private Attributes

AutoMem < T >  _data
Int   _headIndex
Int   _tailIndex
Int   _count
Int   _capacity

Static Private Attributes

static const Int   GROW_INIT
static const Int   GROW_FACTOR

Member Typedef Documentation

◆  ValueType

using ValueType = T

构造函数 & 析构函数文档编制

◆  Queue() [1/3]

Queue ( )
default

Default constructor. Creates an empty queue.

◆  Queue() [2/3]

Queue ( const Queue < T > &  )
delete

Deleted copy constructor.

◆  Queue() [3/3]

Queue ( Queue < T > &&  src )

Move constructor.

◆  ~Queue()

~ Queue ( )

The destructor resets the queue.

成员函数文档编制

◆  operator=() [1/2]

Queue & operator= ( const Queue < T > &  )
delete

Deleted copy assignment.

◆  operator=() [2/2]

Queue & operator= ( Queue < T > &&  src )

Move assignment.

◆  GetCount()

Int GetCount ( ) const

Returns the number of elements in the queue.

◆  IsEmpty()

Bool IsEmpty ( ) const

Checks if the queue contains no elements.

◆  IsPopulated()

Bool IsPopulated ( ) const

Checks if the queue contains any elements.

◆  Peek() [1/2]

可选 <T&> Peek ( )

Returns a reference to the element at the front of the queue without removing it, or NO_VALUE if the queue was empty.

◆  Peek() [2/2]

可选 <const T&> Peek ( ) const

◆  PeekBack() [1/2]

可选 <T&> PeekBack ( )

Returns a reference to the element at the back of the queue without removing it, or NO_VALUE if the queue was empty.

◆  PeekBack() [2/2]

可选 <const T&> PeekBack ( ) const

◆  Push()

ResultMem Push ( value )

Pushes an element to the back of the queue.

◆  PushFront()

ResultMem PushFront ( value )

Pushes an element to the front of the queue.

◆  Emplace()

ResultMem Emplace ( ARGS &&...  args )

Constructs an element in-place at the back of the queue with the given arguments as constructor arguments.

◆  EmplaceFront()

ResultMem EmplaceFront ( ARGS &&...  args )

Constructs an element in-place at the front of the queue with the given arguments.

◆  Pop()

可选 <T> Pop ( )

Returns the element at the front of the queue and removes it, or NO_VALUE if the queue was empty.

◆  PopBack()

可选 <T> PopBack ( )

Returns the element at the back of the queue and removes it, or NO_VALUE if the queue was empty.

◆  Truncate()

Bool Truncate ( )

Removes the element at the front of the queue without returning it. Returns true if the operation succeeded, or false if the queue was empty.

◆  TruncateBack()

Bool TruncateBack ( )

Removes the element at the back of the queue without returning it. Returns true if the operation succeeded, or false if the queue was empty.

◆  Flush()

void Flush ( )

Removes all elements from the queue by calling their destructors, but does not de-allocate the memory yet.

◆  Reset()

void Reset ( )

Removes all elements from the queue by calling their destructors and frees the allocated memory.

◆  AlignAsBlock()

Block <T> AlignAsBlock ( )

Linearizes the internal data storage and returns the elements as a block, from front to back.

◆  CopyFrom()

Result <void> CopyFrom ( const Queue < T > &  src )

Copies the queue.

◆  EnsureCapacity()

ResultMem EnsureCapacity ( Int   requestedSize )

Ensures that the queue can hold requestedSize items without allocating additional memory. Can be used for optimization to pre-allocate a sufficiently large internal buffer instead of growing on-demand.

◆  IncrementIndex()

static MAXON_ATTRIBUTE_FORCE_INLINE void IncrementIndex ( Int index ,
Int   capacity  
)
static private

◆  DecrementIndex()

static MAXON_ATTRIBUTE_FORCE_INLINE void DecrementIndex ( Int index ,
Int   capacity  
)
static private

◆  Linearize()

void Linearize ( )
private

◆  IsAtFullCapacity()

Bool IsAtFullCapacity ( ) const
private

◆  CalcNewCapacity()

Int CalcNewCapacity ( Int   targetSize ) const
private

◆  Grow()

Bool Grow ( Int   targetSize = 0 )
private

◆  CopyDataToNewBuffer()

Result <void> CopyDataToNewBuffer ( T *  destPtr ) const
private

◆  MoveDataToNewBuffer()

void MoveDataToNewBuffer ( T *  destPtr )
private

◆  PushToHead()

void PushToHead ( T &&  value )
private

◆  PushToTail()

void PushToTail ( T &&  value )
private

◆  EmplaceAtHead()

void EmplaceAtHead ( ARGS &&...  args )
private

◆  EmplaceAtTail()

void EmplaceAtTail ( ARGS &&...  args )
private

◆  PopFromTail()

T PopFromTail ( )
private

◆  PopFromHead()

T PopFromHead ( )
private

◆  TruncateTail()

void TruncateTail ( )
private

◆  TruncateHead()

void TruncateHead ( )
private

Member Data Documentation

◆  GROW_INIT

const Int GROW_INIT
static private

◆  GROW_FACTOR

const Int GROW_FACTOR
static private

◆  _data

AutoMem <T> _data
private

◆  _headIndex

Int _headIndex
private

◆  _tailIndex

Int _tailIndex
private

◆  _count

Int _count
private

◆  _capacity

Int _capacity
private