QuantumLibrary
quantum_buffer.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 #ifndef BLOOMBERG_QUANTUM_FUTURE_ITERATOR_H
17 #define BLOOMBERG_QUANTUM_FUTURE_ITERATOR_H
18 
19 #include <iostream>
20 #include <deque>
21 #include <quantum/quantum_future_state.h>
22 #include <quantum/quantum_traits.h>
23 
24 namespace Bloomberg {
25 namespace quantum {
26 
27 //==============================================================================================
28 // enum BufferStatus
29 //==============================================================================================
32 enum class BufferStatus
33 {
34  DataReceived,
35  DataPosted,
36  DataPending,
37  Closed
38 };
39 
40 //==============================================================================================
41 // class Buffer
42 //==============================================================================================
48 template <class T, class ALLOCATOR>
49 class Buffer
50 {
51 public:
52  using ValueType = T;
53 
55  Buffer(const ALLOCATOR& alloc = ALLOCATOR());
56 
61  template <class V = T>
62  BufferStatus push(V&& value);
63 
67  BufferStatus pull(T& value);
68 
71  void close();
72 
74  bool isClosed() const;
75 
78  size_t size() const;
79 
82  bool empty() const;
83 
84 private:
85  std::deque<T,ALLOCATOR> _buffer;
86  bool _isClosed;
87 };
88 
89 }}
90 
91 #include <quantum/impl/quantum_buffer_impl.h>
92 
93 #endif //BLOOMBERG_QUANTUM_FUTURE_ITERATOR_H
Buffer is closed. Push operations are not allowed. Pull operations are allowed until buffer is emtpy.
Definition: quantum_buffer_impl.h:22
Buffer(const ALLOCATOR &alloc=ALLOCATOR())
Constructor.
Definition: quantum_buffer_impl.h:26
Data has been successfully read from the buffer.
size_t size() const
Indicates the number of values stored in the buffer.
Definition: quantum_buffer_impl.h:68
Data has been successfully written to the buffer.
void close()
Close the buffer. Once this method is called, push operations are no longer permitted....
Definition: quantum_buffer_impl.h:56
BufferStatus pull(T &value)
Pulls the next value from the buffer. This decreases the size of the buffer by one.
Definition: quantum_buffer_impl.h:44
BufferStatus push(V &&value)
Pushes a value at the end of the buffer. This increases the size of the buffer by one.
Definition: quantum_buffer_impl.h:33
Buffer is empty and more data is on the way.
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
bool isClosed() const
Indicates if the buffer is closed.
Definition: quantum_buffer_impl.h:62
T ValueType
Type definition for the contained value.
Definition: quantum_buffer.h:52