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 QTextStream &operator>>(char *c);
160
161 QTextStream &operator<<(QChar ch);
162 QTextStream &operator<<(char ch);
163 QTextStream &operator<<(char16_t ch) { return *this << QChar(ch); }
164 QTextStream &operator<<(signed short i);
165 QTextStream &operator<<(unsigned short i);
166 QTextStream &operator<<(signed int i);
167 QTextStream &operator<<(unsigned int i);
168 QTextStream &operator<<(signed long i);
169 QTextStream &operator<<(unsigned long i);
170 QTextStream &operator<<(qlonglong i);
171 QTextStream &operator<<(qulonglong i);
172 QTextStream &operator<<(float f);
173 QTextStream &operator<<(double f);
174 QTextStream &operator<<(const QString &s);
175 QTextStream &operator<<(QStringView s);
176 QTextStream &operator<<(QLatin1StringView s);
177 QTextStream &operator<<(const QByteArray &array);
178 QTextStream &operator<<(const char *c);
179 QTextStream &operator<<(const void *ptr);
180
181 explicit operator bool() const noexcept { return status() == Ok; }
182
183private:
184 Q_DISABLE_COPY(QTextStream)
185 friend class QDebugStateSaverPrivate;
186 friend class QDebug;
187
188 std::unique_ptr<QTextStreamPrivate> d_ptr;
189};
190
191Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
192
193/*****************************************************************************
194 QTextStream manipulators
195 *****************************************************************************/
196
197typedef QTextStream & (*QTextStreamFunction)(QTextStream &);// manipulator function
198typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument
199typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument
200
201
202class Q_CORE_EXPORT QTextStreamManipulator
203{
204public:
205 constexpr QTextStreamManipulator(QTSMFI m, int a) noexcept : mf(m), mc(nullptr), arg(a), ch() {}
206 constexpr QTextStreamManipulator(QTSMFC m, QChar c) noexcept : mf(nullptr), mc(m), arg(-1), ch(c) {}
207 void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
208
209private:
210 QTSMFI mf; // QTextStream member function
211 QTSMFC mc; // QTextStream member function
212 int arg; // member function argument
213 QChar ch;
214};
215
216inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
217{ return (*f)(s); }
218
219inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
220{ return (*f)(s); }
221
222inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
223{ m.exec(s); return s; }
224
225namespace Qt {
226Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
227Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
228Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
229Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
230
231Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
232Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
233Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
234Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
235Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
236Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
237
238Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
239Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
240Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
241Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
242
243Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
244Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
245
246Q_CORE_EXPORT QTextStream &left(QTextStream &s);
247Q_CORE_EXPORT QTextStream &right(QTextStream &s);
248Q_CORE_EXPORT QTextStream &center(QTextStream &s);
249
250Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
251Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
252Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
253
254Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
255
256Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
257
258} // namespace Qt
259
261{
262 QTSMFI func = &QTextStream::setFieldWidth;
263 return QTextStreamManipulator(func,width);
264}
265
267{
268 QTSMFC func = &QTextStream::setPadChar;
269 return QTextStreamManipulator(func, ch);
270}
271
273{
274 QTSMFI func = &QTextStream::setRealNumberPrecision;
275 return QTextStreamManipulator(func, precision);
276}
277
278QT_END_NAMESPACE
279
280#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)