QuantumLibrary
quantum_buffer_impl.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 //NOTE: DO NOT INCLUDE DIRECTLY
17 
18 //##############################################################################################
19 //#################################### IMPLEMENTATIONS #########################################
20 //##############################################################################################
21 
22 namespace Bloomberg {
23 namespace quantum {
24 
25 template <class T, class ALLOCATOR>
26 Buffer<T,ALLOCATOR>::Buffer(const ALLOCATOR& allocator) :
27  _buffer(allocator),
28  _isClosed(false)
29 {}
30 
31 template <class T, class ALLOCATOR>
32 template <class V>
34 {
35  if (_isClosed)
36  {
37  return BufferStatus::Closed;
38  }
39  _buffer.push_back(std::forward<V>(value));
40  return BufferStatus::DataPosted;
41 }
42 
43 template <class T, class ALLOCATOR>
45 {
46  if (_buffer.empty())
47  {
48  return _isClosed ? BufferStatus::Closed : BufferStatus::DataPending;
49  }
50  value = std::move(_buffer.front());
51  _buffer.pop_front();
52  return BufferStatus::DataReceived;
53 }
54 
55 template <class T, class ALLOCATOR>
57 {
58  _isClosed = true;
59 }
60 
61 template <class T, class ALLOCATOR>
63 {
64  return _isClosed;
65 }
66 
67 template <class T, class ALLOCATOR>
69 {
70  return _buffer.size();
71 }
72 
73 template <class T, class ALLOCATOR>
75 {
76  return _buffer.empty();
77 }
78 
79 }}
Definition: quantum_buffer_impl.h:22
Buffer(const ALLOCATOR &alloc=ALLOCATOR())
Constructor.
Definition: quantum_buffer_impl.h:26
size_t size() const
Indicates the number of values stored in the buffer.
Definition: quantum_buffer_impl.h:68
Container which allows buffered access to a series of values. Values are pushed-in (written) by a pro...
Definition: quantum_buffer.h:49
bool empty() const
Helper function equivalent to size() == 0;.
Definition: quantum_buffer_impl.h:74
BufferStatus
Defines the result of the operation on the buffer object.
Definition: quantum_buffer.h:32