|
13 | 13 |
|
14 | 14 | namespace llvm { |
15 | 15 |
|
16 | | -/// Common bits for \a raw_ostream_proxy_adaptor<>, split out to dedup in |
17 | | -/// template instantions. |
18 | | -class raw_ostream_proxy_adaptor_base { |
19 | | -protected: |
20 | | - raw_ostream_proxy_adaptor_base(const raw_ostream_proxy_adaptor_base &) = |
21 | | - delete; |
22 | | - |
23 | | - explicit raw_ostream_proxy_adaptor_base(raw_ostream &OS) |
24 | | - : OS(&OS), PreferredBufferSize(OS.GetBufferSize()) { |
25 | | - // Drop OS's buffer to make this->flush() forward. This proxy will add a |
26 | | - // buffer in its place. |
27 | | - OS.SetUnbuffered(); |
28 | | - } |
29 | | - |
30 | | - ~raw_ostream_proxy_adaptor_base() { |
31 | | - assert(!OS && "Derived objects should call resetProxiedOS()"); |
32 | | - } |
33 | | - |
34 | | - /// Stop proxying the stream, taking the derived object by reference as \p |
35 | | - /// ThisProxyOS. Updates \p ThisProxyOS to stop buffering before setting \a |
36 | | - /// OS to \c nullptr, ensuring that future writes crash immediately. |
37 | | - void resetProxiedOS(raw_ostream &ThisProxyOS) { |
38 | | - ThisProxyOS.SetUnbuffered(); |
39 | | - OS = nullptr; |
40 | | - } |
41 | | - |
42 | | - bool hasProxiedOS() const { return OS; } |
43 | | - raw_ostream &getProxiedOS() const { |
44 | | - assert(OS && "raw_ostream_proxy_adaptor use after reset"); |
45 | | - return *OS; |
46 | | - } |
47 | | - size_t getPreferredBufferSize() const { return PreferredBufferSize; } |
48 | | - |
49 | | -private: |
50 | | - raw_ostream *OS; |
51 | | - |
52 | | - /// Caches the value of OS->GetBufferSize() at construction time. |
53 | | - size_t PreferredBufferSize; |
54 | | -}; |
55 | | - |
56 | 16 | /// Adaptor to create a stream class that proxies another \a raw_ostream. |
57 | 17 | /// |
58 | 18 | /// Use \a raw_ostream_proxy_adaptor<> directly to implement an abstract |
|
0 commit comments