Turi Create  4.0
resizing_array_sink.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_RESIZING_COUNTING_SINK
7 #define TURI_RESIZING_COUNTING_SINK
8 
9 #include <core/util/charstream.hpp>
10 
11 namespace turi {
12 
13  typedef charstream_impl::resizing_array_sink<false> resizing_array_sink;
14 
15  /**
16  Wraps a resizing array sink.
17  */
19  private:
20  resizing_array_sink* ras;
21  public:
22 
23 
24  typedef resizing_array_sink::char_type char_type;
25  typedef resizing_array_sink::category category;
26 
27  inline resizing_array_sink_ref(resizing_array_sink& ref): ras(&ref) { }
28 
30  ras(other.ras) { }
31 
32  inline size_t size() const { return ras->size(); }
33  inline char* c_str() { return ras->c_str(); }
34 
35  inline void clear() { ras->clear(); }
36  /** the optimal buffer size is 0. */
37  inline std::streamsize optimal_buffer_size() const {
38  return ras->optimal_buffer_size();
39  }
40 
41  inline void relinquish() { ras->relinquish(); }
42 
43  inline void advance(std::streamsize n) { ras->advance(n); }
44 
45 
46  inline std::streamsize write(const char* s, std::streamsize n) {
47  return ras->write(s, n);
48  }
49  };
50 
51 }
52 #endif
std::streamsize optimal_buffer_size() const