Vector BLF
ObjectQueue.h
1 /*
2  * Copyright (C) 2013 Tobias Lorenz.
3  * Contact: tobias.lorenz@gmx.net
4  *
5  * This file is part of Tobias Lorenz's Toolkit.
6  *
7  * Commercial License Usage
8  * Licensees holding valid commercial licenses may use this file in
9  * accordance with the commercial license agreement provided with the
10  * Software or, alternatively, in accordance with the terms contained in
11  * a written agreement between you and Tobias Lorenz.
12  *
13  * GNU General Public License 3.0 Usage
14  * Alternatively, this file may be used under the terms of the GNU
15  * General Public License version 3.0 as published by the Free Software
16  * Foundation and appearing in the file LICENSE.GPL included in the
17  * packaging of this file. Please review the following information to
18  * ensure the GNU General Public License version 3.0 requirements will be
19  * met: http://www.gnu.org/copyleft/gpl.html.
20  */
21 
22 #pragma once
23 
24 #include <Vector/BLF/platform.h>
25 
26 #include <condition_variable>
27 #include <limits>
28 #include <mutex>
29 #include <queue>
30 
31 #include <Vector/BLF/ObjectHeaderBase.h>
32 #include <Vector/BLF/LogContainer.h>
33 
34 #include <Vector/BLF/vector_blf_export.h>
35 
36 namespace Vector {
37 namespace BLF {
38 
42 template <typename T>
43 class VECTOR_BLF_EXPORT ObjectQueue {
44  public:
45  explicit ObjectQueue() = default;
46  virtual ~ObjectQueue();
47 
53  virtual T * read();
54 
56  virtual DWORD tellg() const;
57 
65  void write(T * obj);
66 
68  virtual DWORD tellp() const;
69 
71  virtual bool good() const;
72 
74  virtual bool eof() const;
75 
77  virtual void abort();
78 
80  virtual void setFileSize(DWORD fileSize);
81 
83  virtual void setBufferSize(DWORD bufferSize);
84 
86  std::condition_variable tellgChanged;
87 
89  std::condition_variable tellpChanged;
90 
91  private:
93  bool m_abort {};
94 
96  std::queue<T *> m_queue {};
97 
99  DWORD m_tellg {};
100 
102  DWORD m_tellp {};
103 
105  DWORD m_bufferSize {std::numeric_limits<DWORD>::max()};
106 
108  DWORD m_fileSize {std::numeric_limits<DWORD>::max()};
109 
111  std::ios_base::iostate m_rdstate {std::ios_base::goodbit};
112 
114  mutable std::mutex m_mutex {};
115 };
116 
117 /* explicit template instantiation */
118 extern template class ObjectQueue<ObjectHeaderBase>;
119 
120 }
121 }
Definition: ObjectQueue.h:43
std::condition_variable tellgChanged
Definition: ObjectQueue.h:86
std::condition_variable tellpChanged
Definition: ObjectQueue.h:89