Warning, file /include/QtCore/qtextstream.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QTEXTSTREAM_H
0005 #define QTEXTSTREAM_H
0006
0007 #include <QtCore/qiodevicebase.h>
0008 #include <QtCore/qchar.h>
0009 #include <QtCore/qscopedpointer.h>
0010 #include <QtCore/qstringconverter_base.h>
0011
0012 #include <stdio.h>
0013
0014 #if 0
0015
0016 #pragma qt_class(QTextStream)
0017 #endif
0018
0019 #ifdef Status
0020 #error qtextstream.h must be included before any header file that defines Status
0021 #endif
0022
0023 QT_BEGIN_NAMESPACE
0024
0025 class QIODevice;
0026 class QLocale;
0027 class QString;
0028
0029 #if !QT_DEPRECATED_SINCE(6, 9)
0030 # define QT_NO_INHERITABLE_TEXT_STREAM
0031 #endif
0032
0033 #ifdef QT_NO_INHERITABLE_TEXT_STREAM
0034 # define QT_TEXT_STREAM_FINAL final
0035 #else
0036 # define QT_TEXT_STREAM_FINAL
0037 #endif
0038
0039 class QTextStreamPrivate;
0040 class Q_CORE_EXPORT QTextStream QT_TEXT_STREAM_FINAL : public QIODeviceBase
0041 {
0042 Q_DECLARE_PRIVATE(QTextStream)
0043
0044 public:
0045 enum RealNumberNotation {
0046 SmartNotation,
0047 FixedNotation,
0048 ScientificNotation
0049 };
0050 enum FieldAlignment {
0051 AlignLeft,
0052 AlignRight,
0053 AlignCenter,
0054 AlignAccountingStyle
0055 };
0056 enum Status {
0057 Ok,
0058 ReadPastEnd,
0059 ReadCorruptData,
0060 WriteFailed
0061 };
0062 enum NumberFlag {
0063 ShowBase = 0x1,
0064 ForcePoint = 0x2,
0065 ForceSign = 0x4,
0066 UppercaseBase = 0x8,
0067 UppercaseDigits = 0x10
0068 };
0069 Q_DECLARE_FLAGS(NumberFlags, NumberFlag)
0070
0071 QTextStream();
0072 explicit QTextStream(QIODevice *device);
0073 explicit QTextStream(FILE *fileHandle, OpenMode openMode = ReadWrite);
0074 explicit QTextStream(QString *string, OpenMode openMode = ReadWrite);
0075 explicit QTextStream(QByteArray *array, OpenMode openMode = ReadWrite);
0076 explicit QTextStream(const QByteArray &array, OpenMode openMode = ReadOnly);
0077 QT6_ONLY(virtual)
0078 ~QTextStream();
0079
0080 void setEncoding(QStringConverter::Encoding encoding);
0081 QStringConverter::Encoding encoding() const;
0082 void setAutoDetectUnicode(bool enabled);
0083 bool autoDetectUnicode() const;
0084 void setGenerateByteOrderMark(bool generate);
0085 bool generateByteOrderMark() const;
0086
0087 void setLocale(const QLocale &locale);
0088 QLocale locale() const;
0089
0090 void setDevice(QIODevice *device);
0091 QIODevice *device() const;
0092
0093 void setString(QString *string, OpenMode openMode = ReadWrite);
0094 QString *string() const;
0095
0096 Status status() const;
0097 void setStatus(Status status);
0098 void resetStatus();
0099
0100 bool atEnd() const;
0101 void reset();
0102 void flush();
0103 bool seek(qint64 pos);
0104 qint64 pos() const;
0105
0106 void skipWhiteSpace();
0107
0108 QString readLine(qint64 maxlen = 0);
0109 bool readLineInto(QString *line, qint64 maxlen = 0);
0110 QString readAll();
0111 QString read(qint64 maxlen);
0112
0113 void setFieldAlignment(FieldAlignment alignment);
0114 FieldAlignment fieldAlignment() const;
0115
0116 void setPadChar(QChar ch);
0117 QChar padChar() const;
0118
0119 void setFieldWidth(int width);
0120 int fieldWidth() const;
0121
0122 void setNumberFlags(NumberFlags flags);
0123 NumberFlags numberFlags() const;
0124
0125 void setIntegerBase(int base);
0126 int integerBase() const;
0127
0128 void setRealNumberNotation(RealNumberNotation notation);
0129 RealNumberNotation realNumberNotation() const;
0130
0131 void setRealNumberPrecision(int precision);
0132 int realNumberPrecision() const;
0133
0134 QTextStream &operator>>(QChar &ch);
0135 QTextStream &operator>>(char &ch);
0136 QTextStream &operator>>(char16_t &ch)
0137 { QChar c; *this >> c; ch = c.unicode(); return *this; }
0138 QTextStream &operator>>(signed short &i);
0139 QTextStream &operator>>(unsigned short &i);
0140 QTextStream &operator>>(signed int &i);
0141 QTextStream &operator>>(unsigned int &i);
0142 QTextStream &operator>>(signed long &i);
0143 QTextStream &operator>>(unsigned long &i);
0144 QTextStream &operator>>(qlonglong &i);
0145 QTextStream &operator>>(qulonglong &i);
0146 QTextStream &operator>>(float &f);
0147 QTextStream &operator>>(double &f);
0148 QTextStream &operator>>(QString &s);
0149 QTextStream &operator>>(QByteArray &array);
0150 QTextStream &operator>>(char *c);
0151
0152 QTextStream &operator<<(QChar ch);
0153 QTextStream &operator<<(char ch);
0154 QTextStream &operator<<(char16_t ch) { return *this << QChar(ch); }
0155 QTextStream &operator<<(signed short i);
0156 QTextStream &operator<<(unsigned short i);
0157 QTextStream &operator<<(signed int i);
0158 QTextStream &operator<<(unsigned int i);
0159 QTextStream &operator<<(signed long i);
0160 QTextStream &operator<<(unsigned long i);
0161 QTextStream &operator<<(qlonglong i);
0162 QTextStream &operator<<(qulonglong i);
0163 QTextStream &operator<<(float f);
0164 QTextStream &operator<<(double f);
0165 QTextStream &operator<<(const QString &s);
0166 QTextStream &operator<<(QStringView s);
0167 QTextStream &operator<<(QLatin1StringView s);
0168 QTextStream &operator<<(const QByteArray &array);
0169 QTextStream &operator<<(const char *c);
0170 QTextStream &operator<<(const void *ptr);
0171
0172 private:
0173 Q_DISABLE_COPY(QTextStream)
0174 friend class QDebugStateSaverPrivate;
0175 friend class QDebug;
0176
0177 QScopedPointer<QTextStreamPrivate> d_ptr;
0178 };
0179
0180 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
0181
0182
0183
0184
0185
0186 typedef QTextStream & (*QTextStreamFunction)(QTextStream &);
0187 typedef void (QTextStream::*QTSMFI)(int);
0188 typedef void (QTextStream::*QTSMFC)(QChar);
0189
0190
0191 class Q_CORE_EXPORT QTextStreamManipulator
0192 {
0193 public:
0194 constexpr QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {}
0195 constexpr QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {}
0196 void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
0197
0198 private:
0199 QTSMFI mf;
0200 QTSMFC mc;
0201 int arg;
0202 QChar ch;
0203 };
0204
0205 inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
0206 { return (*f)(s); }
0207
0208 inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
0209 { return (*f)(s); }
0210
0211 inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
0212 { m.exec(s); return s; }
0213
0214 namespace Qt {
0215 Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
0216 Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
0217 Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
0218 Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
0219
0220 Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
0221 Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
0222 Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
0223 Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
0224 Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
0225 Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
0226
0227 Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
0228 Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
0229 Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
0230 Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
0231
0232 Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
0233 Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
0234
0235 Q_CORE_EXPORT QTextStream &left(QTextStream &s);
0236 Q_CORE_EXPORT QTextStream &right(QTextStream &s);
0237 Q_CORE_EXPORT QTextStream ¢er(QTextStream &s);
0238
0239 Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
0240 Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
0241 Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
0242
0243 Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
0244
0245 Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
0246
0247 }
0248
0249 inline QTextStreamManipulator qSetFieldWidth(int width)
0250 {
0251 QTSMFI func = &QTextStream::setFieldWidth;
0252 return QTextStreamManipulator(func,width);
0253 }
0254
0255 inline QTextStreamManipulator qSetPadChar(QChar ch)
0256 {
0257 QTSMFC func = &QTextStream::setPadChar;
0258 return QTextStreamManipulator(func, ch);
0259 }
0260
0261 inline QTextStreamManipulator qSetRealNumberPrecision(int precision)
0262 {
0263 QTSMFI func = &QTextStream::setRealNumberPrecision;
0264 return QTextStreamManipulator(func, precision);
0265 }
0266
0267 QT_END_NAMESPACE
0268
0269 #endif