Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-26 09:50:48

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     QT_WARNING_PUSH
0080     #if defined(__has_warning)
0081     #  if __has_warning("-Wunnecessary-virtual-specifier")
0082          QT_WARNING_DISABLE_CLANG("-Wunnecessary-virtual-specifier")
0083     #  endif
0084     #endif
0085     QT6_ONLY(virtual)
0086     ~QTextStream();
0087     QT_WARNING_POP
0088 
0089     void setEncoding(QStringConverter::Encoding encoding);
0090     QStringConverter::Encoding encoding() const;
0091     void setAutoDetectUnicode(bool enabled);
0092     bool autoDetectUnicode() const;
0093     void setGenerateByteOrderMark(bool generate);
0094     bool generateByteOrderMark() const;
0095 
0096     void setLocale(const QLocale &locale);
0097     QLocale locale() const;
0098 
0099     void setDevice(QIODevice *device);
0100     QIODevice *device() const;
0101 
0102     void setString(QString *string, OpenMode openMode = ReadWrite);
0103     QString *string() const;
0104 
0105     Status status() const;
0106     void setStatus(Status status);
0107     void resetStatus();
0108 
0109     bool atEnd() const;
0110     void reset();
0111     void flush();
0112     bool seek(qint64 pos);
0113     qint64 pos() const;
0114 
0115     void skipWhiteSpace();
0116 
0117     QString readLine(qint64 maxlen = 0);
0118     bool readLineInto(QString *line, qint64 maxlen = 0);
0119     QString readAll();
0120     QString read(qint64 maxlen);
0121 
0122     void setFieldAlignment(FieldAlignment alignment);
0123     FieldAlignment fieldAlignment() const;
0124 
0125     void setPadChar(QChar ch);
0126     QChar padChar() const;
0127 
0128     void setFieldWidth(int width);
0129     int fieldWidth() const;
0130 
0131     void setNumberFlags(NumberFlags flags);
0132     NumberFlags numberFlags() const;
0133 
0134     void setIntegerBase(int base);
0135     int integerBase() const;
0136 
0137     void setRealNumberNotation(RealNumberNotation notation);
0138     RealNumberNotation realNumberNotation() const;
0139 
0140     void setRealNumberPrecision(int precision);
0141     int realNumberPrecision() const;
0142 
0143     QTextStream &operator>>(QChar &ch);
0144     QTextStream &operator>>(char &ch);
0145     QTextStream &operator>>(char16_t &ch)
0146     { QChar c; *this >> c; ch = c.unicode(); return *this; }
0147     QTextStream &operator>>(signed short &i);
0148     QTextStream &operator>>(unsigned short &i);
0149     QTextStream &operator>>(signed int &i);
0150     QTextStream &operator>>(unsigned int &i);
0151     QTextStream &operator>>(signed long &i);
0152     QTextStream &operator>>(unsigned long &i);
0153     QTextStream &operator>>(qlonglong &i);
0154     QTextStream &operator>>(qulonglong &i);
0155     QTextStream &operator>>(float &f);
0156     QTextStream &operator>>(double &f);
0157     QTextStream &operator>>(QString &s);
0158     QTextStream &operator>>(QByteArray &array);
0159     QTextStream &operator>>(char *c);
0160 
0161     QTextStream &operator<<(QChar ch);
0162     QTextStream &operator<<(char ch);
0163     QTextStream &operator<<(char16_t ch) { return *this << QChar(ch); }
0164     QTextStream &operator<<(signed short i);
0165     QTextStream &operator<<(unsigned short i);
0166     QTextStream &operator<<(signed int i);
0167     QTextStream &operator<<(unsigned int i);
0168     QTextStream &operator<<(signed long i);
0169     QTextStream &operator<<(unsigned long i);
0170     QTextStream &operator<<(qlonglong i);
0171     QTextStream &operator<<(qulonglong i);
0172     QTextStream &operator<<(float f);
0173     QTextStream &operator<<(double f);
0174     QTextStream &operator<<(const QString &s);
0175     QTextStream &operator<<(QStringView s);
0176     QTextStream &operator<<(QLatin1StringView s);
0177     QTextStream &operator<<(const QByteArray &array);
0178     QTextStream &operator<<(const char *c);
0179     QTextStream &operator<<(const void *ptr);
0180 
0181     explicit operator bool() const noexcept { return status() == Ok; }
0182 
0183 private:
0184     Q_DISABLE_COPY(QTextStream)
0185     friend class QDebugStateSaverPrivate;
0186     friend class QDebug;
0187 
0188     std::unique_ptr<QTextStreamPrivate> d_ptr;
0189 };
0190 
0191 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
0192 
0193 /*****************************************************************************
0194   QTextStream manipulators
0195  *****************************************************************************/
0196 
0197 typedef QTextStream & (*QTextStreamFunction)(QTextStream &);// manipulator function
0198 typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument
0199 typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument
0200 
0201 
0202 class Q_CORE_EXPORT QTextStreamManipulator
0203 {
0204 public:
0205     constexpr QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {}
0206     constexpr QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {}
0207     void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
0208 
0209 private:
0210     QTSMFI mf;                                        // QTextStream member function
0211     QTSMFC mc;                                        // QTextStream member function
0212     int arg;                                          // member function argument
0213     QChar ch;
0214 };
0215 
0216 inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
0217 { return (*f)(s); }
0218 
0219 inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
0220 { return (*f)(s); }
0221 
0222 inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
0223 { m.exec(s); return s; }
0224 
0225 namespace Qt {
0226 Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
0227 Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
0228 Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
0229 Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
0230 
0231 Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
0232 Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
0233 Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
0234 Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
0235 Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
0236 Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
0237 
0238 Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
0239 Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
0240 Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
0241 Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
0242 
0243 Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
0244 Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
0245 
0246 Q_CORE_EXPORT QTextStream &left(QTextStream &s);
0247 Q_CORE_EXPORT QTextStream &right(QTextStream &s);
0248 Q_CORE_EXPORT QTextStream &center(QTextStream &s);
0249 
0250 Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
0251 Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
0252 Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
0253 
0254 Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
0255 
0256 Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
0257 
0258 } // namespace Qt
0259 
0260 inline QTextStreamManipulator qSetFieldWidth(int width)
0261 {
0262     QTSMFI func = &QTextStream::setFieldWidth;
0263     return QTextStreamManipulator(func,width);
0264 }
0265 
0266 inline QTextStreamManipulator qSetPadChar(QChar ch)
0267 {
0268     QTSMFC func = &QTextStream::setPadChar;
0269     return QTextStreamManipulator(func, ch);
0270 }
0271 
0272 inline QTextStreamManipulator qSetRealNumberPrecision(int precision)
0273 {
0274     QTSMFI func = &QTextStream::setRealNumberPrecision;
0275     return QTextStreamManipulator(func, precision);
0276 }
0277 
0278 QT_END_NAMESPACE
0279 
0280 #endif // QTEXTSTREAM_H