Vector BLF: ObjectQueue.h Source File

Vector BLF

Loading...
Searching...
No Matches
ObjectQueue.h
1// SPDX-FileCopyrightText: 2013-2021 Tobias Lorenz <tobias.lorenz@gmx.net>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include <Vector/BLF/platform.h>
8
9#include <condition_variable>
10#include <limits>
11#include <mutex>
12#include <queue>
13
14#include <Vector/BLF/ObjectHeaderBase.h>
15#include <Vector/BLF/LogContainer.h>
16
17#include <Vector/BLF/vector_blf_export.h>
18
19namespace Vector {
20namespace BLF {
21
25template <typename T>
26 class VECTOR_BLF_EXPORT ObjectQueue final {
27 public:
28 ~ObjectQueue();
29
35 T * read();
36
38 uint32_t tellg() const;
39
47 void write(T * obj);
48
50 uint32_t tellp() const;
51
53 bool good() const;
54
56 bool eof() const;
57
59 void abort();
60
62 void setFileSize(uint32_t fileSize);
63
65 void setBufferSize(uint32_t bufferSize);
66
68 std::condition_variable tellgChanged {};
69
71 std::condition_variable tellpChanged {};
72
73 private:
75 bool m_abort {};
76
78 std::queue<T *> m_queue {};
79
81 uint32_t m_tellg {};
82
84 uint32_t m_tellp {};
85
87 uint32_t m_bufferSize {std::numeric_limits<uint32_t>::max()};
88
90 uint32_t m_fileSize {std::numeric_limits<uint32_t>::max()};
91
93 std::ios_base::iostate m_rdstate {std::ios_base::goodbit};
94
96 mutable std::mutex m_mutex {};
97};
98
99/* explicit template instantiation */
100extern template class ObjectQueue<ObjectHeaderBase>;
101
102}
103}
Vector::BLF::ObjectQueue
Definition ObjectQueue.h:26
Vector::BLF::ObjectQueue::abort
void abort()
Definition ObjectQueue.cpp:117
Vector::BLF::ObjectQueue::read
T * read()
Definition ObjectQueue.cpp:25
Vector::BLF::ObjectQueue::setBufferSize
void setBufferSize(uint32_t bufferSize)
Definition ObjectQueue.cpp:142
Vector::BLF::ObjectQueue::tellgChanged
std::condition_variable tellgChanged
Definition ObjectQueue.h:68
Vector::BLF::ObjectQueue::tellpChanged
std::condition_variable tellpChanged
Definition ObjectQueue.h:71
Vector::BLF::ObjectQueue::tellg
uint32_t tellg() const
Definition ObjectQueue.cpp:59
Vector::BLF::ObjectQueue::write
void write(T *obj)
Definition ObjectQueue.cpp:67
Vector::BLF::ObjectQueue::eof
bool eof() const
Definition ObjectQueue.cpp:109
Vector::BLF::ObjectQueue::tellp
uint32_t tellp() const
Definition ObjectQueue.cpp:93
Vector::BLF::ObjectQueue::setFileSize
void setFileSize(uint32_t fileSize)
Definition ObjectQueue.cpp:130
Vector::BLF::ObjectQueue::good
bool good() const
Definition ObjectQueue.cpp:101