1 // This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
2 // the main distribution directory for license terms and copyright or visit
3 // https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
4 
5 #pragma once
6 
7 #include <deque>
8 #include <vector>
9 
10 #include "caf/message.hpp"
11 
12 namespace caf {
13 
14 /// Grants access to an output stream buffer.
15 template <class T>
16 class downstream {
17 public:
18   // -- member types -----------------------------------------------------------
19 
20   /// A queue of items for temporary storage before moving them into chunks.
21   using queue_type = std::deque<T>;
22 
23   // -- constructors, destructors, and assignment operators --------------------
24 
downstream(queue_type & q)25   downstream(queue_type& q) : buf_(q) {
26     // nop
27   }
28 
29   // -- queue access -----------------------------------------------------------
30 
31   template <class... Ts>
push(Ts &&...xs)32   void push(Ts&&... xs) {
33     buf_.emplace_back(std::forward<Ts>(xs)...);
34   }
35 
36   template <class Iterator, class Sentinel>
append(Iterator first,Sentinel last)37   void append(Iterator first, Sentinel last) {
38     buf_.insert(buf_.end(), first, last);
39   }
40 
41   // @private
buf()42   queue_type& buf() {
43     return buf_;
44   }
45 
46 protected:
47   queue_type& buf_;
48 };
49 
50 } // namespace caf
51