Turi Create  4.0
output_iterator.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_SFRAME_OUTPUT_ITERATOR_HPP
7 #define TURI_SFRAME_OUTPUT_ITERATOR_HPP
8 #include <iterator>
9 
10 namespace turi {
11 class sframe_rows;
12 
13 /**
14  * \internal
15  * An output iterator that accepts a stream of values writing them to
16  * an SFrame.
17  */
18 template <typename T, typename ConstRefFunction, typename MoveFunction, typename SFrameRowsFunction>
21 public:
22  typedef std::output_iterator_tag iterator_category;
23  typedef void value_type;
24  typedef void difference_type;
25  typedef void pointer;
26  typedef void reference;
27 
28  explicit sframe_function_output_iterator() {}
29 
30  explicit sframe_function_output_iterator(const ConstRefFunction& f,
31  const MoveFunction& f2,
32  const SFrameRowsFunction& f3)
33  : m_f(f), m_f2(f2), m_f3(f3) {}
34 
35  struct output_proxy {
36  output_proxy(const ConstRefFunction& f,
37  const MoveFunction& f2,
38  const SFrameRowsFunction& f3) : m_f(f), m_f2(f2), m_f3(f3) { }
39 
40  output_proxy& operator=(const T& value) {
41  m_f(value);
42  return *this;
43  }
44 
45  output_proxy& operator=(T&& value) {
46  m_f2(std::move(value));
47  return *this;
48  }
49 
50  output_proxy& operator=(const sframe_rows& value) {
51  m_f3(value);
52  return *this;
53  }
54 
55  const ConstRefFunction& m_f;
56  const MoveFunction& m_f2;
57  const SFrameRowsFunction& m_f3;
58  };
59  output_proxy operator*() { return output_proxy(m_f, m_f2, m_f3); }
60  self& operator++() { return *this; }
61  self& operator++(int) { return *this; }
62 private:
63  ConstRefFunction m_f;
64  MoveFunction m_f2;
65  SFrameRowsFunction m_f3;
66 };
67 
68 } // namespace turi
69 
70 #endif // TURI_SFRAME_OUTPUT_ITERATOR_HPP