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 QT_WARNING_PUSH
80 #if defined(__has_warning)
81 # if __has_warning("-Wunnecessary-virtual-specifier")
82 QT_WARNING_DISABLE_CLANG("-Wunnecessary-virtual-specifier")
83 # endif
84 #endif
85 QT6_ONLY(virtual)
86 ~QTextStream();
87 QT_WARNING_POP
88
89 void setEncoding(QStringConverter::Encoding encoding);
90 QStringConverter::Encoding encoding() const;
91 void setAutoDetectUnicode(bool enabled);
92 bool autoDetectUnicode() const;
93 void setGenerateByteOrderMark(bool generate);
94 bool generateByteOrderMark() const;
95
96 void setLocale(const QLocale &locale);
97 QLocale locale() const;
98
99 void setDevice(QIODevice *device);
100 QIODevice *device() const;
101
102 void setString(QString *string, OpenMode openMode = ReadWrite);
103 QString *string() const;
104
105 Status status() const;
106 void setStatus(Status status);
107 void resetStatus();
108
109 bool atEnd() const;
110 void reset();
111 void flush();
112 bool seek(qint64 pos);
113 qint64 pos() const;
114
115 void skipWhiteSpace();
116
117 QString readLine(qint64 maxlen = 0);
118 bool readLineInto(QString *line, qint64 maxlen = 0);
119 QString readAll();
120 QString read(qint64 maxlen);
121
122 void setFieldAlignment(FieldAlignment alignment);
123 FieldAlignment fieldAlignment() const;
124
125 void setPadChar(QChar ch);
126 QChar padChar() const;
127
128 void setFieldWidth(int width);
129 int fieldWidth() const;
130
131 void setNumberFlags(NumberFlags flags);
132 NumberFlags numberFlags() const;
133
134 void setIntegerBase(int base);
135 int integerBase() const;
136
137 void setRealNumberNotation(RealNumberNotation notation);
138 RealNumberNotation realNumberNotation() const;
139
140 void setRealNumberPrecision(int precision);
141 int realNumberPrecision() const;
142
143 QTextStream &operator>>(QChar &ch);
144 QTextStream &operator>>(char &ch);
145 QTextStream &operator>>(char16_t &ch)
146 { QChar c; *this >> c; ch = c.unicode(); return *this; }
147 QTextStream &operator>>(signed short &i);
148 QTextStream &operator>>(unsigned short &i);
149 QTextStream &operator>>(signed int &i);
150 QTextStream &operator>>(unsigned int &i);
151 QTextStream &operator>>(signed long &i);
152 QTextStream &operator>>(unsigned long &i);
153 QTextStream &operator>>(qlonglong &i);
154 QTextStream &operator>>(qulonglong &i);
155 QTextStream &operator>>(float &f);
156 QTextStream &operator>>(double &f);
157 QTextStream &operator>>(QString &s);
158 QTextStream &operator>>(QByteArray &array);
159#if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 12)
160 QT_DEPRECATED_VERSION_X_6_12("Use the QByteArray overload: this function cannot be used safely.")
161 QTextStream &operator>>(char *c);
162#endif
163
164 QTextStream &operator<<(QChar ch);
165 QTextStream &operator<<(char ch);
166 QTextStream &operator<<(char16_t ch) { return *this << QChar(ch); }
167 QTextStream &operator<<(signed short i);
168 QTextStream &operator<<(unsigned short i);
169 QTextStream &operator<<(signed int i);
170 QTextStream &operator<<(unsigned int i);
171 QTextStream &operator<<(signed long i);
172 QTextStream &operator<<(unsigned long i);
173 QTextStream &operator<<(qlonglong i);
174 QTextStream &operator<<(qulonglong i);
175 QTextStream &operator<<(float f);
176 QTextStream &operator<<(double f);
177 QTextStream &operator<<(const QString &s);
178 QTextStream &operator<<(QStringView s);
179 QTextStream &operator<<(QLatin1StringView s);
180 QTextStream &operator<<(const QByteArray &array);
181 QTextStream &operator<<(const char *c);
182 QTextStream &operator<<(const void *ptr);
183
184 explicit operator bool() const noexcept { return status() == Ok; }
185
186private:
187 Q_DISABLE_COPY(QTextStream)
188 friend class QDebugStateSaverPrivate;
189 friend class QDebug;
190
191 std::unique_ptr<QTextStreamPrivate> d_ptr;
192};
193
194Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
195
196/*****************************************************************************
197 QTextStream manipulators
198 *****************************************************************************/
199
200typedef QTextStream & (*QTextStreamFunction)(QTextStream &);// manipulator function
201typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument
202typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument
203
204
205class Q_CORE_EXPORT QTextStreamManipulator
206{
207public:
208 constexpr QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {}
209 constexpr QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {}
210 void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
211
212private:
213 QTSMFI mf; // QTextStream member function
214 QTSMFC mc; // QTextStream member function
215 int arg; // member function argument
216 QChar ch;
217};
218
219inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
220{ return (*f)(s); }
221
222inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
223{ return (*f)(s); }
224
225inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
226{ m.exec(s); return s; }
227
228namespace Qt {
229Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
230Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
231Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
232Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
233
234Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
235Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
236Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
237Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
238Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
239Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
240
241Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
242Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
243Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
244Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
245
246Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
247Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
248
249Q_CORE_EXPORT QTextStream &left(QTextStream &s);
250Q_CORE_EXPORT QTextStream &right(QTextStream &s);
251Q_CORE_EXPORT QTextStream &center(QTextStream &s);
252
253Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
254Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
255Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
256
257Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
258
259Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
260
261} // namespace Qt
262
264{
265 QTSMFI func = &QTextStream::setFieldWidth;
266 return QTextStreamManipulator(func,width);
267}
268
270{
271 QTSMFC func = &QTextStream::setPadChar;
272 return QTextStreamManipulator(func, ch);
273}
274
276{
277 QTSMFI func = &QTextStream::setRealNumberPrecision;
278 return QTextStreamManipulator(func, precision);
279}
280
281QT_END_NAMESPACE
282
283#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)
Combined button and popup list for selecting options.
Definition qcompare.h:111
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)