WPILibC++  2018.4.1-20180925013224-1203-g32ec07e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
raw_uv_ostream.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_RAW_UV_OSTREAM_H_
9 #define WPIUTIL_WPI_RAW_UV_OSTREAM_H_
10 
11 #include "wpi/ArrayRef.h"
12 #include "wpi/SmallVector.h"
13 #include "wpi/raw_ostream.h"
14 #include "wpi/uv/Buffer.h"
15 
16 namespace wpi {
17 
23 class raw_uv_ostream : public raw_ostream {
24  public:
32  : m_bufs(bufs),
33  m_alloc([=]() { return uv::Buffer::Allocate(allocSize); }) {
34  SetUnbuffered();
35  }
36 
43  std::function<uv::Buffer()> alloc)
44  : m_bufs(bufs), m_alloc(alloc) {
45  SetUnbuffered();
46  }
47 
48  ~raw_uv_ostream() override = default;
49 
53  ArrayRef<uv::Buffer> bufs() { return m_bufs; }
54 
55  void flush() = delete;
56 
57  private:
58  void write_impl(const char* data, size_t len) override;
59  uint64_t current_pos() const override;
60 
62  std::function<uv::Buffer()> m_alloc;
63 
64  // How much allocated space is left in the current buffer.
65  size_t m_left = 0;
66 };
67 
68 } // namespace wpi
69 
70 #endif // WPIUTIL_WPI_RAW_UV_OSTREAM_H_
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
ArrayRef< uv::Buffer > bufs()
Returns an ArrayRef to the buffers.
Definition: raw_uv_ostream.h:53
void SetUnbuffered()
Set the stream to be unbuffered.
Definition: raw_ostream.h:128
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
raw_uv_ostream(SmallVectorImpl< uv::Buffer > &bufs, size_t allocSize)
Construct a new raw_uv_ostream.
Definition: raw_uv_ostream.h:31
raw_ostream style output to a SmallVector of uv::Buffer buffers.
Definition: raw_uv_ostream.h:23
Data buffer.
Definition: Buffer.h:27
raw_uv_ostream(SmallVectorImpl< uv::Buffer > &bufs, std::function< uv::Buffer()> alloc)
Construct a new raw_uv_ostream.
Definition: raw_uv_ostream.h:42