Mountain  1.0.0
Simple C++ 2D Game Framework
ts_queue.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mutex>
4 #include <queue>
5 
8 
9 namespace Mountain
10 {
16  template <typename T>
17  class TsQueue
18  {
19  public:
21  TsQueue() = default;
22 
24  ~TsQueue() = default;
25 
26  // Prevent copy construction because of the mutex
27  DELETE_COPY_MOVE_OPERATIONS(TsQueue)
28 
29 
30  T& Front();
32 
35  const T& Front() const;
36 
39  T& Back();
40 
43  const T& Back() const;
44 
47  void Push(const T& item);
48 
51  void Push(T&& item);
52 
55  bool Empty();
56 
59  size_t Count();
60 
63  T Pop();
64 
66  void Clear();
67 
68  private:
69  // Mutex guarding the queue
70  std::mutex m_QueueMutex;
71 
72  std::queue<T> m_Queue;
73  };
74 }
75 
76 #include "Mountain/utils/ts_queue.inl"
T & Front()
Gets a reference to the front item in the queue.
void Push(const T &item)
Pushes a new item on the back of the queue by copying it.
Thread-Safe Queue.
Definition: ts_queue.hpp:17
TsQueue()=default
Default constructs a TsQueue.
void Clear()
Clears the queue.
~TsQueue()=default
Default destructs the TsQueue.
size_t Count()
Get the number of items in the queue.
T Pop()
Pops the item on the front of the queue.
bool Empty()
Checks if the queue is empty.
T & Back()
Gets a reference to the back item in the queue.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22