Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-04 09:53:28

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