Clingo
Loading...
Searching...
No Matches
CppClingo::Util::OutputBuffer Class Reference

Create an output buffer that bears some similarities with C++'s iostreams. More...

#include <print.hh>

Public Member Functions

 OutputBuffer (FILE *out=nullptr)
 Construt the buffer with an optional file handle.
 
void flush ()
 Flush the buffer.
 
void endl ()
 Flush the buffer if it has a predefined minimum size.
 
auto size () const -> size_t
 Get the number of bytes currently stored in the buffer.
 
auto empty () const -> bool
 Check if the buffer is currently emtpy.
 
auto view () const -> std::string_view
 Get a string view of the current buffer content.
 
auto str () const -> std::string
 Get a string with the current buffer content.
 
auto c_str () -> char const *
 Get a C string with the current buffer content.
 
auto reset () -> OutputBuffer &
 Empty the buffer.
 
auto release () -> std::vector< char >
 Empty the buffer and return a vector with the previous content.
 
void append (char const *str)
 Append a string to the buffer.
 
void append (std::string_view str)
 Append a string to the buffer.
 
void append (char c)
 Append a char to the buffer.
 
void pop ()
 Pop a char from the buffer.
 
template<std::integral T>
void append (T num)
 Append an integral to the buffer.
 
auto reserve (std::ptrdiff_t n) -> std::span< char >
 Append n bytes at the end of the buffer.
 
void trim_zero (std::ptrdiff_t len)
 Trim trailing zeros.
 

Friends

template<std::integral T>
auto operator<< (OutputBuffer &out, T num) -> OutputBuffer &
 Append the given integral to the buffer.
 
auto operator<< (OutputBuffer &out, char c) -> OutputBuffer &
 Append the given char to the buffer.
 
auto operator<< (OutputBuffer &out, std::string_view str) -> OutputBuffer &
 Append the given string to the buffer.
 
auto operator<< (OutputBuffer &out, double value) -> OutputBuffer &
 Append the given double to the buffer.
 
auto operator<< (OutputBuffer &out, char const *str) -> OutputBuffer &
 Append the given string to the buffer.
 

Detailed Description

Create an output buffer that bears some similarities with C++'s iostreams.

The buffer can optionally be constructed with a file handle for output. Function endl() can be called to output and discard the buffer's content at key points; its content will only be written if the buffer has at least some fixed predefined size. Function flush() should be called to output the current buffer content and flush the file.

Member Function Documentation

◆ endl()

void CppClingo::Util::OutputBuffer::endl ( )
inline

Flush the buffer if it has a predefined minimum size.

This function is a noop if there is no associated file.

◆ flush()

void CppClingo::Util::OutputBuffer::flush ( )
inline

Flush the buffer.

This function is a noop if there is no associated file.

◆ reserve()

auto CppClingo::Util::OutputBuffer::reserve ( std::ptrdiff_t  n) -> std::span<char>
inline

Append n bytes at the end of the buffer.

The returned span should be filled by the calling code.

◆ trim_zero()

void CppClingo::Util::OutputBuffer::trim_zero ( std::ptrdiff_t  len)
inline

Trim trailing zeros.

Note
Workaround for mp_int_string_len providing too high length values.

The documentation for this class was generated from the following file: