Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 09:29:15

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