Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-common-io.h
Go to the documentation of this file.
1#ifndef QX_IO_COMMON_H
2#define QX_IO_COMMON_H
3
4// Shared Lib Support
5#include "qx/io/qx_io_export.h"
6
7// Qt Includes
8#include <QFlags>
9#include <QChar>
10#include <QFile>
11#include <QSaveFile>
12#include <QDirIterator>
13#include <QCryptographicHash>
14
15//Intra-component Includes
16#include "qx/io/qx-ioopreport.h"
17#include "qx/io/qx-textpos.h"
18#include "qx/io/qx-textquery.h"
19
20// Extra-component Includes
21#include "qx/core/qx-index.h"
22
23namespace Qx
24{
25//-Namespace Enums-----------------------------------------------------------------------------------------------------
28
33 NewOnly = 0x4,
35 Pad = 0x10,
36 Unbuffered = 0x20
37};
38Q_DECLARE_FLAGS(WriteOptions, WriteOption)
39Q_DECLARE_OPERATORS_FOR_FLAGS(WriteOptions)
40
45Q_DECLARE_FLAGS(ReadOptions, ReadOption)
46Q_DECLARE_OPERATORS_FOR_FLAGS(ReadOptions)
47
49
50//-Namespace Variables-------------------------------------------------------------------------------------------------
51//TODO: Ensure these work in shared build. Don't think they need to be exported since they are defined here
52const QChar ENDL = '\n'; //Auto cross platform thanks to QIODevice::OpenMode Text
53const QString LIST_ITEM_PREFIX = u"- "_s;
54
55//-Namespace Functions-------------------------------------------------------------------------------------------------
56QX_IO_EXPORT bool fileIsEmpty(const QFile& file);
57QX_IO_EXPORT IoOpReport fileIsEmpty(bool& returnBuffer, const QFile& file);
58QX_IO_EXPORT QString kosherizeFileName(QString fileName);
59
60// Text
61QX_IO_EXPORT IoOpReport textFileEndsWithNewline(bool& returnBuffer, QFile& textFile);
62QX_IO_EXPORT IoOpReport textFileLayout(QList<int>& returnBuffer, QFile& textFile, bool ignoreTrailingEmpty);
63QX_IO_EXPORT IoOpReport textFileLineCount(int& returnBuffer, QFile& textFile, bool ignoreTrailingEmpty);
64QX_IO_EXPORT IoOpReport textFileAbsolutePosition(TextPos& textPos, QFile& textFile, bool ignoreTrailingEmpty);
65QX_IO_EXPORT IoOpReport findStringInFile(QList<TextPos>& returnBuffer, QFile& textFile, const TextQuery& query, ReadOptions readOptions = NoReadOptions);
66QX_IO_EXPORT IoOpReport fileContainsString(bool& returnBuffer, QFile& textFile, const QString& query, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive, bool allowSplit = false);
67QX_IO_EXPORT IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos, int count, ReadOptions readOptions = NoReadOptions);
68QX_IO_EXPORT IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos = TextPos(Start), TextPos endPos = TextPos(End), ReadOptions readOptions = NoReadOptions);
69QX_IO_EXPORT IoOpReport readTextFromFile(QStringList& returnBuffer, QFile& textFile, Index32 startLine = 0, Index32 endLine = Index32(Last), ReadOptions readOptions = NoReadOptions);
70QX_IO_EXPORT IoOpReport writeStringToFile(QFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(Start), WriteOptions writeOptions = NoWriteOptions);
71QX_IO_EXPORT IoOpReport writeStringToFile(QSaveFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(Start), WriteOptions writeOptions = NoWriteOptions);
72QX_IO_EXPORT IoOpReport deleteTextFromFile(QFile& textFile, TextPos startPos, TextPos endPos);
73
74// Directory:
75QX_IO_EXPORT bool dirContainsFiles(const QDir& directory, QDirIterator::IteratorFlags iteratorFlags);
76QX_IO_EXPORT IoOpReport dirContainsFiles(bool& returnBuffer, const QDir& directory, QDirIterator::IteratorFlags iteratorFlags);
77QX_IO_EXPORT IoOpReport dirContentInfoList(QFileInfoList& returnBuffer, const QDir& directory, QStringList nameFilters = QStringList(),
79QX_IO_EXPORT IoOpReport dirContentList(QStringList& returnBuffer, const QDir& directory, QStringList nameFilters = QStringList(),
81QX_IO_EXPORT IoOpReport copyDirectory(const QDir& directory, const QDir& destination, bool recursive = true, ReplaceMode replaceMode = Stop);
82
83// Integrity
84QX_IO_EXPORT IoOpReport calculateFileChecksum(QString& returnBuffer, QFile& file, QCryptographicHash::Algorithm hashAlgorithm);
85QX_IO_EXPORT IoOpReport fileMatchesChecksum(bool& returnBuffer, QFile& file, QString checksum, QCryptographicHash::Algorithm hashAlgorithm);
86
87// Binary Based
88QX_IO_EXPORT IoOpReport readBytesFromFile(QByteArray& returnBuffer, QFile& file, Index64 startPos = 0, Index64 endPos = Index64(Last));
89QX_IO_EXPORT IoOpReport writeBytesToFile(QFile& file, const QByteArray& bytes, WriteMode writeMode = Truncate, Index64 startPos = 0, WriteOptions writeOptions = NoWriteOptions);
90QX_IO_EXPORT IoOpReport writeBytesToFile(QSaveFile& file, const QByteArray& bytes, WriteMode writeMode = Truncate, Index64 startPos = 0, WriteOptions writeOptions = NoWriteOptions);
91}
92
93#endif // QX_IO_COMMON_H
The IoOpReport class is a container for details regarding the outcome of an IO operation.
Definition qx-ioopreport.h:53
The TextPos class is used to represent an offset within a text file in terms of lines and characters.
Definition qx-textpos.h:18
The TextQuery class contains rules for conducting a search of text.
Definition qx-textquery.h:17
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
WriteOption
Definition qx-common-io.h:29
@ CreatePath
Definition qx-common-io.h:31
@ Pad
Definition qx-common-io.h:35
@ NoWriteOptions
Definition qx-common-io.h:30
@ ExistingOnly
Definition qx-common-io.h:32
@ NewOnly
Definition qx-common-io.h:33
@ Unbuffered
Definition qx-common-io.h:36
@ EnsureBreak
Definition qx-common-io.h:34
const QString LIST_ITEM_PREFIX
Definition qx-common-io.h:53
IoOpReport copyDirectory(const QDir &directory, const QDir &destination, bool recursive, ReplaceMode replaceMode)
Definition qx-common-io.cpp:1412
WriteMode
Definition qx-common-io.h:27
@ Insert
Definition qx-common-io.h:27
@ Append
Definition qx-common-io.h:27
@ Truncate
Definition qx-common-io.h:27
@ Overwrite
Definition qx-common-io.h:27
IoOpReport writeBytesToFile(QFile &file, const QByteArray &bytes, WriteMode writeMode, Index64 startPos, WriteOptions writeOptions)
Definition qx-common-io.cpp:1689
IoOpReport dirContentInfoList(QFileInfoList &returnBuffer, const QDir &directory, QStringList nameFilters, QDir::Filters filters, QDirIterator::IteratorFlags flags)
Definition qx-common-io.cpp:1333
@ Last
Definition qx-global.h:21
@ End
Definition qx-global.h:22
@ Start
Definition qx-global.h:20
IoOpReport dirContentList(QStringList &returnBuffer, const QDir &directory, QStringList nameFilters, QDir::Filters filters, QDirIterator::IteratorFlags flags, PathType pathType)
Definition qx-common-io.cpp:1377
IoOpReport writeStringToFile(QFile &textFile, const QString &text, WriteMode writeMode, TextPos startPos, WriteOptions writeOptions)
Definition qx-common-io.cpp:1157
Index< qint32 > Index64
Definition qx-index.h:304
QString kosherizeFileName(QString fileName)
Definition qx-common-io.cpp:231
IoOpReport calculateFileChecksum(QString &returnBuffer, QFile &file, QCryptographicHash::Algorithm hashAlgorithm)
Definition qx-common-io.cpp:1460
ReadOption
Definition qx-common-io.h:41
@ IgnoreTrailingBreak
Definition qx-common-io.h:43
@ NoReadOptions
Definition qx-common-io.h:42
Index< qint32 > Index32
Definition qx-index.h:303
IoOpReport findStringInFile(QList< TextPos > &returnBuffer, QFile &textFile, const TextQuery &query, ReadOptions readOptions)
Definition qx-common-io.cpp:489
PathType
Definition qx-common-io.h:48
@ Absolute
Definition qx-common-io.h:48
@ Relative
Definition qx-common-io.h:48
IoOpReport readTextFromFile(QString &returnBuffer, QFile &textFile, TextPos startPos, int count, ReadOptions readOptions)
Definition qx-common-io.cpp:637
IoOpReport textFileLayout(QList< int > &returnBuffer, QFile &textFile, bool ignoreTrailingEmpty)
Definition qx-common-io.cpp:339
IoOpReport textFileAbsolutePosition(TextPos &textPos, QFile &textFile, bool ignoreTrailingEmpty)
Definition qx-common-io.cpp:443
IoOpReport fileContainsString(bool &returnBuffer, QFile &textFile, const QString &query, Qt::CaseSensitivity cs, bool allowSplit)
Definition qx-common-io.cpp:613
IoOpReport textFileLineCount(int &returnBuffer, QFile &textFile, bool ignoreTrailingEmpty)
Definition qx-common-io.cpp:389
ReplaceMode
Definition qx-common-io.h:26
@ Skip
Definition qx-common-io.h:26
@ Stop
Definition qx-common-io.h:26
@ Replace
Definition qx-common-io.h:26
IoOpReport deleteTextFromFile(QFile &textFile, TextPos startPos, TextPos endPos)
Definition qx-common-io.cpp:1204
IoOpReport fileMatchesChecksum(bool &returnBuffer, QFile &file, QString checksum, QCryptographicHash::Algorithm hashAlgorithm)
Definition qx-common-io.cpp:1502
IoOpReport textFileEndsWithNewline(bool &returnBuffer, QFile &textFile)
Definition qx-common-io.cpp:281
IoOpReport readBytesFromFile(QByteArray &returnBuffer, QFile &file, Index64 startPos, Index64 endPos)
Definition qx-common-io.cpp:1531
bool fileIsEmpty(const QFile &file)
Definition qx-common-io.cpp:196
bool dirContainsFiles(const QDir &directory, QDirIterator::IteratorFlags iteratorFlags)
Definition qx-common-io.cpp:1289
const QChar ENDL
Definition qx-common-io.h:52
typedef Filters
typedef IteratorFlags
CaseSensitivity