Formatted text I/O with encoding awareness. More...
#include <textstream.h>
Public Types | |
| enum | Status { Ok , ReadPastEnd , WriteFailed } |
| Stream status codes. More... | |
| enum | FieldAlignment { Left , Right , Center } |
| Field alignment for padded output. More... | |
| enum | RealNumberNotation { SmartNotation , Fixed , Scientific } |
| Floating-point notation styles. More... | |
Public Member Functions | |
| TextStream (IODevice *device) | |
| Constructs a TextStream on an IODevice. | |
| TextStream (Buffer *buffer) | |
| Constructs a TextStream backed by a Buffer. | |
| TextStream (String *string) | |
| Constructs a TextStream backed by a String. | |
| TextStream (FILE *file) | |
| Constructs a TextStream wrapping a C stdio FILE. | |
| ~TextStream () | |
| Destructor. | |
| Status | status () const |
| Returns the current stream status. | |
| void | resetStatus () |
| Resets the stream status to Ok. | |
| bool | atEnd () const |
| Returns true if at the end of the stream. | |
| void | flush () |
| Flushes any buffered output to the underlying device. | |
| IODevice * | device () const |
| Returns the underlying IODevice. | |
| void | setEncoding (const String &encoding) |
| Sets the text encoding for read/write operations. | |
| String | encoding () const |
| Returns the current encoding name. | |
| void | setFieldWidth (int width) |
| Sets the minimum field width for formatted output. | |
| int | fieldWidth () const |
| Returns the current field width. | |
| void | setFieldAlignment (FieldAlignment align) |
| Sets the field alignment. | |
| FieldAlignment | fieldAlignment () const |
| Returns the current field alignment. | |
| void | setPadChar (char c) |
| Sets the padding character used for field width. | |
| char | padChar () const |
| Returns the current pad character. | |
| void | setIntegerBase (int base) |
| Sets the integer base for formatted output. | |
| int | integerBase () const |
| Returns the current integer base. | |
| void | setRealNumberPrecision (int precision) |
| Sets the number of decimal places for float/double output. | |
| int | realNumberPrecision () const |
| Returns the current real number precision. | |
| void | setRealNumberNotation (RealNumberNotation notation) |
| Sets the floating-point notation style. | |
| RealNumberNotation | realNumberNotation () const |
| Returns the current real number notation. | |
| TextStream & | operator<< (const String &val) |
| Writes a String. | |
| TextStream & | operator<< (const char *val) |
| Writes a C string. | |
| TextStream & | operator<< (char val) |
| Writes a single character. | |
| TextStream & | operator<< (int val) |
| Writes an int as formatted decimal text. | |
| TextStream & | operator<< (unsigned int val) |
| Writes an unsigned int as formatted decimal text. | |
| TextStream & | operator<< (int64_t val) |
| Writes an int64_t as formatted text. | |
| TextStream & | operator<< (uint64_t val) |
| Writes a uint64_t as formatted text. | |
| TextStream & | operator<< (float val) |
| Writes a float as formatted text. | |
| TextStream & | operator<< (double val) |
| Writes a double as formatted text. | |
| TextStream & | operator<< (bool val) |
| Writes "true" or "false". | |
| TextStream & | operator<< (const Variant &val) |
| Writes a Variant using its toString() representation. | |
| TextStream & | operator<< (TextStream &(*manip)(TextStream &)) |
| Writes a manipulator function. | |
| TextStream & | operator>> (String &val) |
| Reads a whitespace-delimited token into a String. | |
| TextStream & | operator>> (char &val) |
| Reads a single character. | |
| TextStream & | operator>> (int &val) |
| Reads an int from text. | |
| TextStream & | operator>> (int64_t &val) |
| Reads an int64_t from text. | |
| TextStream & | operator>> (double &val) |
| Reads a double from text. | |
| String | readLine () |
| Reads one line of text, consuming the trailing newline. | |
| String | readAll () |
| Reads all remaining text. | |
| String | read (size_t maxLength) |
| Reads up to maxLength characters. | |
Formatted text I/O with encoding awareness.
TextStream provides a Qt-style interface for reading and writing formatted text. It is used for human-readable output, config files, log formatting, and structured text parsing.
TextStream does not inherit from std::ostream. All operator<< and operator>> overloads are provided explicitly. This separation allows encoding-aware text handling and promeki-native formatting controls without the complexity of std::locale.
TextStream can be constructed from:
All constructors funnel through a single IODevice code path internally.
|
explicit |
Constructs a TextStream on an IODevice.
The device must already be open. The TextStream does not take ownership of the device.
| device | The IODevice to operate on. |
|
explicit |
Constructs a TextStream backed by a Buffer.
An internal BufferIODevice is created and opened for ReadWrite. The Buffer must outlive the TextStream.
| buffer | The Buffer to read from / write to. |
|
explicit |
Constructs a TextStream backed by a String.
An internal StringIODevice is created and opened for ReadWrite. The String must outlive the TextStream.
| string | The String to read from / write to. |
|
explicit |
Constructs a TextStream wrapping a C stdio FILE.
An internal FileIODevice is created with ReadWrite mode. The FILE must outlive the TextStream. The TextStream does not take ownership of the FILE (it will not be fclose'd).
| file | The FILE pointer to wrap. |
| bool TextStream::atEnd | ( | ) | const |
Returns true if at the end of the stream.
|
inline |
Returns the underlying IODevice.
|
inline |
Returns the current encoding name.
|
inline |
Returns the current field alignment.
|
inline |
Returns the current field width.
| void TextStream::flush | ( | ) |
Flushes any buffered output to the underlying device.
Calls IODevice::flush() on the underlying device. This allows devices that intercept writes (such as StreamStringIODevice) to act on incomplete data.
|
inline |
Returns the current integer base.
|
inline |
Returns the current pad character.
Reads up to maxLength characters.
| maxLength | Maximum number of characters to read. |
| String TextStream::readAll | ( | ) |
Reads all remaining text.
| String TextStream::readLine | ( | ) |
Reads one line of text, consuming the trailing newline.
The returned string does not include the trailing newline.
|
inline |
Returns the current real number notation.
|
inline |
Returns the current real number precision.
Sets the text encoding for read/write operations.
Supported values: "UTF-8" (default), "Latin-1".
| encoding | The encoding name. |
|
inline |
Sets the field alignment.
| align | The alignment mode. |
|
inline |
Sets the minimum field width for formatted output.
When a value's text representation is shorter than the field width, it is padded according to the current alignment and pad character.
| width | The minimum field width. |
|
inline |
Sets the integer base for formatted output.
Supported bases: 2, 8, 10 (default), 16.
| base | The integer base. |
Sets the padding character used for field width.
| c | The pad character (default: space). |
|
inline |
Sets the floating-point notation style.
| notation | The notation style. |
|
inline |
Sets the number of decimal places for float/double output.
| precision | The precision (default: 6). |
|
inline |
Returns the current stream status.