Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtextstream.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:header-decls-only
4
5#ifndef QTEXTSTREAM_H
6#define QTEXTSTREAM_H
7
8#include <QtCore/qiodevicebase.h>
9#include <QtCore/qchar.h>
10#include <QtCore/qstringconverter_base.h>
11
12#include <memory>
13
14#include <stdio.h>
15
16#if 0
17// the macros around the class name throw off syncqt:
18#pragma qt_class(QTextStream)
19#endif
20
21#ifdef Status
22#error qtextstream.h must be included before any header file that defines Status
23#endif
24
26
27class QIODevice;
28class QLocale;
29class QString;
30
31#if !QT_DEPRECATED_SINCE(6, 9)
32# define QT_NO_INHERITABLE_TEXT_STREAM
33#endif
34
35#ifdef QT_NO_INHERITABLE_TEXT_STREAM
36# define QT_TEXT_STREAM_FINAL final
37#else
38# define QT_TEXT_STREAM_FINAL
39#endif
40
42class Q_CORE_EXPORT QTextStream QT_TEXT_STREAM_FINAL : public QIODeviceBase
43{
44 Q_DECLARE_PRIVATE(QTextStream)
45
46public:
47 enum RealNumberNotation {
48 SmartNotation,
49 FixedNotation,
50 ScientificNotation
51 };
52 enum FieldAlignment {
53 AlignLeft,
54 AlignRight,
55 AlignCenter,
56 AlignAccountingStyle
57 };
58 enum Status {
59 Ok,
60 ReadPastEnd,
61 ReadCorruptData,
62 WriteFailed
63 };
64 enum NumberFlag {
65 ShowBase = 0x1,
66 ForcePoint = 0x2,
67 ForceSign = 0x4,
68 UppercaseBase = 0x8,
69 UppercaseDigits = 0x10
70 };
71 Q_DECLARE_FLAGS(NumberFlags, NumberFlag)
72
73 QTextStream();
74 explicit QTextStream(QIODevice *device);
75 explicit QTextStream(FILE *fileHandle, OpenMode openMode = ReadWrite);
76 explicit QTextStream(QString *string, OpenMode openMode = ReadWrite);
77 explicit QTextStream(QByteArray *array, OpenMode openMode = ReadWrite);
78 explicit QTextStream(const QByteArray &array, OpenMode openMode = ReadOnly);
79 QT6_ONLY(virtual)
80 ~QTextStream();
81
82 void setEncoding(QStringConverter::Encoding encoding);
83 QStringConverter::Encoding encoding() const;
84 void setAutoDetectUnicode(bool enabled);
85 bool autoDetectUnicode() const;
86 void setGenerateByteOrderMark(bool generate);
87 bool generateByteOrderMark() const;
88
89 void setLocale(const QLocale &locale);
90 QLocale locale() const;
91
92 void setDevice(QIODevice *device);
93 QIODevice *device() const;
94
95 void setString(QString *string, OpenMode openMode = ReadWrite);
96 QString *string() const;
97
98 Status status() const;
99 void setStatus(Status status);
100 void resetStatus();
101
102 bool atEnd() const;
103 void reset();
104 void flush();
105 bool seek(qint64 pos);
106 qint64 pos() const;
107
108 void skipWhiteSpace();
109
110 QString readLine(qint64 maxlen = 0);
111 bool readLineInto(QString *line, qint64 maxlen = 0);
112 QString readAll();
113 QString read(qint64 maxlen);
114
115 void setFieldAlignment(FieldAlignment alignment);
116 FieldAlignment fieldAlignment() const;
117
118 void setPadChar(QChar ch);
119 QChar padChar() const;
120
121 void setFieldWidth(int width);
122 int fieldWidth() const;
123
124 void setNumberFlags(NumberFlags flags);
125 NumberFlags numberFlags() const;
126
127 void setIntegerBase(int base);
128 int integerBase() const;
129
130 void setRealNumberNotation(RealNumberNotation notation);
131 RealNumberNotation realNumberNotation() const;
132
133 void setRealNumberPrecision(int precision);
134 int realNumberPrecision() const;
135
136 QTextStream &operator>>(QChar &ch);
137 QTextStream &operator>>(char &ch);
138 QTextStream &operator>>(char16_t &ch)
139 { QChar c; *this >> c; ch = c.unicode(); return *this; }
140 QTextStream &operator>>(signed short &i);
141 QTextStream &operator>>(unsigned short &i);
142 QTextStream &operator>>(signed int &i);
143 QTextStream &operator>>(unsigned int &i);
144 QTextStream &operator>>(signed long &i);
145 QTextStream &operator>>(unsigned long &i);
146 QTextStream &operator>>(qlonglong &i);
147 QTextStream &operator>>(qulonglong &i);
148 QTextStream &operator>>(float &f);
149 QTextStream &operator>>(double &f);
150 QTextStream &operator>>(QString &s);
151 QTextStream &operator>>(QByteArray &array);
152 QTextStream &operator>>(char *c);
153
154 QTextStream &operator<<(QChar ch);
155 QTextStream &operator<<(char ch);
156 QTextStream &operator<<(char16_t ch) { return *this << QChar(ch); }
157 QTextStream &operator<<(signed short i);
158 QTextStream &operator<<(unsigned short i);
159 QTextStream &operator<<(signed int i);
160 QTextStream &operator<<(unsigned int i);
161 QTextStream &operator<<(signed long i);
162 QTextStream &operator<<(unsigned long i);
163 QTextStream &operator<<(qlonglong i);
164 QTextStream &operator<<(qulonglong i);
165 QTextStream &operator<<(float f);
166 QTextStream &operator<<(double f);
167 QTextStream &operator<<(const QString &s);
168 QTextStream &operator<<(QStringView s);
169 QTextStream &operator<<(QLatin1StringView s);
170 QTextStream &operator<<(const QByteArray &array);
171 QTextStream &operator<<(const char *c);
172 QTextStream &operator<<(const void *ptr);
173
174 explicit operator bool() const noexcept { return status() == Ok; }
175
176private:
177 Q_DISABLE_COPY(QTextStream)
178 friend class QDebugStateSaverPrivate;
179 friend class QDebug;
180
181 std::unique_ptr<QTextStreamPrivate> d_ptr;
182};
183
184Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
185
186/*****************************************************************************
187 QTextStream manipulators
188 *****************************************************************************/
189
190typedef QTextStream & (*QTextStreamFunction)(QTextStream &);// manipulator function
191typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument
192typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument
193
194
195class Q_CORE_EXPORT QTextStreamManipulator
196{
197public:
198 constexpr QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {}
199 constexpr QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {}
200 void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
201
202private:
203 QTSMFI mf; // QTextStream member function
204 QTSMFC mc; // QTextStream member function
205 int arg; // member function argument
206 QChar ch;
207};
208
209inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
210{ return (*f)(s); }
211
212inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
213{ return (*f)(s); }
214
215inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
216{ m.exec(s); return s; }
217
218namespace Qt {
219Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
220Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
221Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
222Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
223
224Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
225Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
226Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
227Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
228Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
229Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
230
231Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
232Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
233Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
234Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
235
236Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
237Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
238
239Q_CORE_EXPORT QTextStream &left(QTextStream &s);
240Q_CORE_EXPORT QTextStream &right(QTextStream &s);
241Q_CORE_EXPORT QTextStream &center(QTextStream &s);
242
243Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
244Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
245Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
246
247Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
248
249Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
250
251} // namespace Qt
252
254{
255 QTSMFI func = &QTextStream::setFieldWidth;
256 return QTextStreamManipulator(func,width);
257}
258
260{
261 QTSMFC func = &QTextStream::setPadChar;
262 return QTextStreamManipulator(func, ch);
263}
264
266{
267 QTSMFI func = &QTextStream::setRealNumberPrecision;
268 return QTextStreamManipulator(func, precision);
269}
270
271QT_END_NAMESPACE
272
273#endif // QTEXTSTREAM_H
QFileSystemWatcherPathKey(const QFileSystemWatcherPathKey &other)
bool operator==(const QFileSystemWatcherPathKey &other) const
QFileSystemWatcherPathKey(const QString &other)
void directoryChanged(const QString &path, bool removed)
QHash< Qt::HANDLE, PathInfoHash > pathInfoForHandle
QHash< QFileSystemWatcherPathKey, QWindowsFileSystemWatcherEngine::PathInfo > PathInfoHash
bool operator!=(const QFileInfo &fileInfo) const
PathInfo & operator=(const QFileInfo &fileInfo)
QStringList addPaths(const QStringList &paths, QStringList *files, QStringList *directories) override
void driveLockForRemovalFailed(const QString &)
QStringList removePaths(const QStringList &paths, QStringList *files, QStringList *directories) override
void driveRemoved(const QString &)
void driveLockForRemovalFailed(const QString &)
void driveLockForRemoval(const QString &)
void driveRemoved(const QString &)
bool nativeEventFilter(const QByteArray &, void *messageIn, qintptr *) override
This method is called for every native event.
QWindowsRemovableDriveListener(QObject *parent=nullptr)
QT_FORWARD_DECLARE_CLASS(QTextStream)
Definition qcompare.h:76
static Qt::HANDLE createChangeNotification(const QString &path, uint flags)
static Iterator findByHDevNotify(Iterator i1, Iterator i2, HDEVNOTIFY hdevnotify)
static void stopDeviceNotification(QWindowsRemovableDriveListener::RemovableDriveEntry &e)
static QString pathFromEntry(const QWindowsRemovableDriveListener::RemovableDriveEntry &re)
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
Q_DECLARE_TYPEINFO(QFileSystemWatcherPathKey, Q_RELOCATABLE_TYPE)
QTextStream & operator>>(QTextStream &s, QTextStreamFunction f)
QTextStreamManipulator qSetPadChar(QChar ch)
QTextStreamManipulator qSetRealNumberPrecision(int precision)
#define QT_TEXT_STREAM_FINAL
Definition qtextstream.h:36
QTextStreamManipulator qSetFieldWidth(int width)
QTextStream & operator<<(QTextStream &s, QTextStreamFunction f)