11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
19PROMEKI_NAMESPACE_BEGIN
80 enum RealNumberNotation {
94 explicit TextStream(IODevice *device);
104 explicit TextStream(Buffer *buffer);
114 explicit TextStream(String *
string);
125 explicit TextStream(FILE *file);
138 Status status()
const {
return _status; }
143 void resetStatus() { _status = Ok; }
164 IODevice *device()
const {
return _device; }
177 void setEncoding(
const String &encoding);
183 String encoding()
const {
return _encoding; }
198 void setFieldWidth(
int width) { _fieldWidth = width; }
204 int fieldWidth()
const {
return _fieldWidth; }
210 void setFieldAlignment(FieldAlignment align) { _fieldAlignment = align; }
216 FieldAlignment fieldAlignment()
const {
return _fieldAlignment; }
222 void setPadChar(
char c) { _padChar = c; }
228 char padChar()
const {
return _padChar; }
237 void setIntegerBase(
int base) { _integerBase = base; }
243 int integerBase()
const {
return _integerBase; }
249 void setRealNumberPrecision(
int precision) { _realNumberPrecision = precision; }
255 int realNumberPrecision()
const {
return _realNumberPrecision; }
261 void setRealNumberNotation(RealNumberNotation notation) { _realNumberNotation = notation; }
267 RealNumberNotation realNumberNotation()
const {
return _realNumberNotation; }
274 TextStream &operator<<(
const String &val);
276 TextStream &operator<<(
const char *val);
278 TextStream &operator<<(
char val);
280 TextStream &operator<<(
int val);
282 TextStream &operator<<(
unsigned int val);
284 TextStream &operator<<(int64_t val);
286 TextStream &operator<<(uint64_t val);
288 TextStream &operator<<(
float val);
290 TextStream &operator<<(
double val);
292 TextStream &operator<<(
bool val);
294 TextStream &operator<<(
const Variant &val);
297 TextStream &operator<<(TextStream &(*manip)(TextStream &));
304 TextStream &operator>>(String &val);
306 TextStream &operator>>(
char &val);
308 TextStream &operator>>(
int &val);
310 TextStream &operator>>(int64_t &val);
312 TextStream &operator>>(
double &val);
338 String read(
size_t maxLength);
345 void writeString(
const String &str);
352 String applyPadding(
const String &str);
359 bool readChar(
char &ch);
369 void unreadChar(
char ch);
374 void skipWhitespace();
382 IODevice *_device =
nullptr;
383 IODevice::UPtr _ownedDevice;
386 String _encoding{
"UTF-8"};
390 FieldAlignment _fieldAlignment = Right;
392 int _integerBase = 10;
393 int _realNumberPrecision = 6;
394 RealNumberNotation _realNumberNotation = SmartNotation;
405inline TextStream &endl(TextStream &s) {
412inline TextStream &flush(TextStream &s) {
418inline TextStream &hex(TextStream &s) {
419 s.setIntegerBase(16);
424inline TextStream &dec(TextStream &s) {
425 s.setIntegerBase(10);
430inline TextStream &oct(TextStream &s) {
436inline TextStream &bin(TextStream &s) {
442inline TextStream &fixed(TextStream &s) {
443 s.setRealNumberNotation(TextStream::Fixed);
448inline TextStream &scientific(TextStream &s) {
449 s.setRealNumberNotation(TextStream::Scientific);
454inline TextStream &left(TextStream &s) {
455 s.setFieldAlignment(TextStream::Left);
460inline TextStream &right(TextStream &s) {
461 s.setFieldAlignment(TextStream::Right);
466inline TextStream ¢er(TextStream &s) {
467 s.setFieldAlignment(TextStream::Center);
481template <
typename T>
class Atomic;
482template <
typename A,
typename B>
class Pair;
483template <
typename T>
class Span;
495template <
typename T>
inline TextStream &operator<<(TextStream &s,
const Atomic<T> &a) {
509template <
typename A,
typename B>
inline TextStream &operator<<(TextStream &s,
const Pair<A, B> &p) {
510 s <<
"(" << p.first() <<
", " << p.second() <<
")";
524template <
typename T>
inline TextStream &operator<<(TextStream &s,
const Span<T> &span) {
526 for (
size_t i = 0; i < span.size(); ++i) {
527 if (i != 0) s <<
", ";