Vince's CSV Parser
Loading...
Searching...
No Matches
single_thread_deque.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <deque>
8#include <utility>
9
10namespace csv {
11 namespace internals {
12 template<typename T>
14 public:
15 SingleThreadDeque(size_t notify_size = 100) : _notify_size(notify_size) {}
16
18 this->data = other.data;
19 this->_notify_size = other._notify_size;
20 this->_is_empty = other._is_empty;
21 this->_is_waitable = other._is_waitable;
22 }
23
24 SingleThreadDeque(const std::deque<T>& source) : SingleThreadDeque() {
25 this->data = source;
26 this->_is_empty = source.empty();
27 }
28
29 bool empty() const noexcept {
30 return this->_is_empty;
31 }
32
33 T& front() noexcept {
34 return this->data.front();
35 }
36
37 T& operator[](size_t n) {
38 return this->data[n];
39 }
40
41 void push_back(T&& item) {
42 this->data.push_back(std::move(item));
43 this->_is_empty = false;
44 }
45
46 T pop_front() noexcept {
47 T item = std::move(data.front());
48 data.pop_front();
49
50 if (this->data.empty()) {
51 this->_is_empty = true;
52 }
53
54 return item;
55 }
56
57 bool is_waitable() const noexcept {
58 return this->_is_waitable;
59 }
60
61 void wait() {
62 // No-op in single-thread mode.
63 }
64
65 size_t size() const noexcept {
66 return this->data.size();
67 }
68
69 typename std::deque<T>::iterator begin() noexcept {
70 return this->data.begin();
71 }
72
73 typename std::deque<T>::iterator end() noexcept {
74 return this->data.end();
75 }
76
77 void notify_all() {
78 this->_is_waitable = true;
79 }
80
81 void kill_all() {
82 this->_is_waitable = false;
83 }
84
85 private:
86 bool _is_empty = true;
87 bool _is_waitable = false;
88 size_t _notify_size;
89 std::deque<T> data;
90 };
91 }
92}
The all encompassing namespace.