14 #ifndef LLVM_SUPPORT_RAW_OSTREAM_H
15 #define LLVM_SUPPORT_RAW_OSTREAM_H
19 #include "llvm/Support/DataTypes.h"
20 #include <system_error>
23 class format_object_base;
24 class FormattedString;
25 class FormattedNumber;
26 template <
typename T>
class SmallVectorImpl;
61 char *OutBufStart, *OutBufEnd, *OutBufCur;
84 : BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
86 OutBufStart = OutBufEnd = OutBufCur =
nullptr;
105 SetBufferAndMode(
new char[Size], Size, InternalBuffer);
111 if (BufferMode != Unbuffered && OutBufStart ==
nullptr)
115 return OutBufEnd - OutBufStart;
123 SetBufferAndMode(
nullptr, 0, Unbuffered);
127 return OutBufCur - OutBufStart;
135 if (OutBufCur != OutBufStart)
140 if (OutBufCur >= OutBufEnd)
147 if (OutBufCur >= OutBufEnd)
154 if (OutBufCur >= OutBufEnd)
162 size_t Size = Str.
size();
165 if (Size > (
size_t)(OutBufEnd - OutBufCur))
169 memcpy(OutBufCur, Str.
data(), Size);
184 return write(Str.data(), Str.length());
188 return write(Str.data(), Str.size());
197 return this->operator<<(static_cast<unsigned long>(
N));
201 return this->operator<<(static_cast<long>(
N));
278 virtual void write_impl(
const char *Ptr,
size_t Size) = 0;
281 virtual void handle();
285 virtual uint64_t current_pos()
const = 0;
292 SetBufferAndMode(BufferStart, Size, ExternalBuffer);
307 void SetBufferAndMode(
char *BufferStart,
size_t Size, BufferKind Mode);
311 void flush_nonempty();
315 void copy_to_buffer(
const char *Ptr,
size_t Size);
322 virtual void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t Offset) = 0;
327 void pwrite(
const char *Ptr,
size_t Size, uint64_t Offset) {
329 uint64_t Pos =
tell();
333 assert(Size + Offset <= Pos &&
"We don't support extending the stream");
335 pwrite_impl(Ptr, Size, Offset);
355 bool UseAtomicWrites;
359 bool SupportsSeeking;
362 void write_impl(
const char *Ptr,
size_t Size)
override;
364 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t Offset)
override;
368 uint64_t current_pos()
const override {
return pos; }
371 size_t preferred_buffer_size()
const override;
374 void error_detected() { Error =
true; }
404 uint64_t
seek(uint64_t off);
413 UseAtomicWrites = Value;
417 bool bg=
false)
override;
457 raw_ostream &
nulls();
469 void write_impl(
const char *Ptr,
size_t Size)
override;
473 uint64_t current_pos()
const override {
return OS.size(); }
492 void write_impl(
const char *Ptr,
size_t Size)
override;
494 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t Offset)
override;
498 uint64_t current_pos()
const override;
527 void write_impl(
const char *Ptr,
size_t size)
override;
528 void pwrite_impl(
const char *Ptr,
size_t Size, uint64_t Offset)
override;
532 uint64_t current_pos()
const override;
bool has_colors() const override
This function determines if this stream is displayed and supports colors.
bool is_displayed() const override
This function determines if this stream is connected to a "tty" or "console" window.
void SetUseAtomicWrites(bool Value)
Set the stream to attempt to use atomic writes for individual output routines where possible...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
const char * getBufferStart() const
Return the beginning of the current stream buffer, or 0 if the stream is unbuffered.
size_t size() const
size - Get the string size.
raw_string_ostream(std::string &O)
buffer_ostream(raw_ostream &OS)
A raw_ostream that discards all output.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
~raw_string_ostream() override
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward. ...
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
raw_svector_ostream(SmallVectorImpl< char > &O, unsigned)
A raw_ostream that writes to an SmallVector or SmallString.
raw_ostream & operator<<(const std::string &Str)
raw_ostream & operator<<(const char *Str)
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
raw_ostream & operator<<(int N)
void SetBuffer(char *BufferStart, size_t Size)
Use the provided buffer as the raw_ostream buffer.
uint64_t tell() const
tell - Return the current offset with the file.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
~raw_fd_ostream() override
virtual bool is_displayed() const
This function determines if this stream is connected to a "tty" or "console" window.
raw_ostream & operator<<(char C)
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
raw_ostream & resetColor() override
Resets the colors to terminal defaults.
void resync()
This is called when the SmallVector we're appending to is changed outside of the raw_svector_ostream'...
void SetUnbuffered()
Set the stream to be unbuffered.
raw_ostream & operator<<(unsigned char C)
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
virtual raw_ostream & reverseColor()
Reverses the forground and background colors.
~raw_svector_ostream() override
raw_fd_ostream(StringRef Filename, std::error_code &EC, sys::fs::OpenFlags Flags)
Open the specified file for writing.
raw_ostream(bool unbuffered=false)
void SetBufferSize(size_t Size)
Set the stream to be buffered, using the specified buffer size.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
~raw_null_ostream() override
raw_ostream & write(unsigned char C)
size_t GetBufferSize() const
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '', ' ', '"', and anything that doesn't satisfy std::isprint into an escape...
Color
A "color", which is either even or odd.
virtual size_t preferred_buffer_size() const
Return an efficient buffer size for the underlying output mechanism.
raw_ostream & operator<<(unsigned int N)
void SetBuffered()
Set the stream to be buffered, with an automatically determined buffer size.
StringRef str()
Flushes the stream contents to the target vector and return a StringRef for the vector contents...
raw_pwrite_stream(bool Unbuffered=false)
A raw_ostream that writes to a file descriptor.
raw_ostream & operator<<(StringRef Str)
void close()
Manually flush the stream and close the file.
An abstract base class for streams implementations that also support a pwrite operation.
A raw_ostream that writes to an std::string.
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
LLVM Value Representation.
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
raw_ostream & changeColor(enum Colors colors, bool bold=false, bool bg=false) override
Changes the foreground color of text that will be output from this point forward. ...
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
raw_ostream & operator<<(signed char C)
raw_ostream & reverseColor() override
Reverses the forground and background colors.
size_t GetNumBytesInBuffer() const
void clear_error()
Set the flag read by has_error() to false.