Skip to content

Commit

Permalink
At global Extent enum
Browse files Browse the repository at this point in the history
Replaces/unifies Index<T>::Extent and TextPos::Extent.
  • Loading branch information
oblivioncth committed Aug 11, 2023
1 parent d746312 commit e48207c
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 91 deletions.
16 changes: 8 additions & 8 deletions lib/core/doc/res/snippets/qx-index.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! [0]
Index<int>::LAST + 10 // = Index<int>::LAST
Index<int>::LAST - 10 // = Index<int>::LAST
Index<int>(5) + Index<int>::LAST // = Index<int>::LAST
Index<int>(1087) - Index<int>::LAST // = 0
Index<int>::LAST * 130 // = Index<int>::LAST
Index<int>::LAST / 58 // = Index<int>::LAST
Index<int>::LAST / Index<int>::LAST // = 1
Index<int>(98) / Index<int>::LAST // = 0
Index<int>(Qx::Last) + 10 // = Index<int>(Qx::Last)
Index<int>(Qx::Last) - 10 // = Index<int>(Qx::Last)
Index<int>(5) + Index<int>(Qx::Last) // = Index<int>(Qx::Last)
Index<int>(1087) - Index<int>(Qx::Last) // = 0
Index<int>(Qx::Last) * 130 // = Index<int>(Qx::Last)
Index<int>(Qx::Last) / 58 // = Index<int>(Qx::Last)
Index<int>(Qx::Last) / Index<int>(Qx::Last) // = 1
Index<int>(98) / Index<int>(Qx::Last) // = 0
//! [0]
8 changes: 8 additions & 0 deletions lib/core/include/qx/core/qx-global.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ enum Severity
Critical = 3
};

enum Extent
{
First,
Start = First,
Last,
End = Last
};

//-Namespace Functions-----------------------------------------------------------------------------------------------------------
QString severityString(Severity sv, bool uc = true);

Expand Down
8 changes: 1 addition & 7 deletions lib/core/include/qx/core/qx-index.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QtGlobal>

// Intra-component Includes
#include "qx/core/qx-global.h"
#include "qx/core/qx-algorithm.h"

namespace Qx
Expand All @@ -23,13 +24,6 @@ class Index
private:
enum class Type {Null, End, Value};

public:
enum Extent
{
First,
Last
};

//-Instance Members----------------------------------------------------------------------------------------------------
private:
Type mType;
Expand Down
28 changes: 20 additions & 8 deletions lib/core/src/qx-global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,33 @@ namespace Qx
* @enum Severity
*
* This enum represents the the severity of an error/outcome.
*/

/*!
*
* @var Severity Warning
* A warning.
*/

/*!
*
* @var Severity Err
* An error.
*
* @var Severity Critical
* A critical/fatal error.
*/

/*!
* @var Severity Critical
* A critical/fatal error.
* @enum Extent
*
* Used to refer the extents of a range.
*
* @var Extent First
* The beginning of a range, or its first unit.
*
* @var Extent Start
* Equivalent to First.
*
* @var Extent Last
* The end of a range, or its last unit.
*
* @var Extent End
* Equivalent to Last.
*/

//-Namespace Functions-----------------------------------------------------------------------------------------------------------
Expand Down
17 changes: 1 addition & 16 deletions lib/core/src/qx-index.dox
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@ namespace Qx
* @li 2) 'last' indices are greater than everything except other 'last' indices (highest possible value)
*/

//-Class Types----------------------------------------------------------------------------------------------------
//Public:
// TODO: Report this as a Doxygen bug, likely should need to be Index<T>::Extent
/*!
* @enum Index::Extent
*
* Used to refer to indicies of special significance.
*
* @var Index<T>::Extent Index<T>::First
* The first index, equivalent to @c Index<T>(0).
*
* @var Index<T>::Extent Index<T>::Last
* The last index.
*/

//-Constructor----------------------------------------------------------------------------------------------
//Public:
/*!
Expand Down Expand Up @@ -102,7 +87,7 @@ namespace Qx
*
* Returns @c true if the index represents the last index of an arbitrary dataset; otherwise returns @c false.
*
* This is equivalent to <tt>*this == Index<T>(Last)</tt>.
* This is equivalent to <tt>*this == Index<T>(Qx::Last)</tt>.
*/

//-Operators-------------------------------------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions lib/io/include/qx/io/qx-common-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ QX_IO_EXPORT IoOpReport textFileAbsolutePosition(TextPos& textPos, QFile& textFi
QX_IO_EXPORT IoOpReport findStringInFile(QList<TextPos>& returnBuffer, QFile& textFile, const TextQuery& query, ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport fileContainsString(bool& returnBuffer, QFile& textFile, const QString& query, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive, bool allowSplit = false);
QX_IO_EXPORT IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos, int count, ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos = TextPos(TextPos::Start), TextPos endPos = TextPos(TextPos::End), ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport readTextFromFile(QStringList& returnBuffer, QFile& textFile, Index32 startLine = 0, Index32 endLine = Index32(Index32::Last), ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport writeStringToFile(QFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(TextPos::Start), WriteOptions writeOptions = NoWriteOptions);
QX_IO_EXPORT IoOpReport writeStringToFile(QSaveFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(TextPos::Start), WriteOptions writeOptions = NoWriteOptions);
QX_IO_EXPORT IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos startPos = TextPos(Start), TextPos endPos = TextPos(End), ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport readTextFromFile(QStringList& returnBuffer, QFile& textFile, Index32 startLine = 0, Index32 endLine = Index32(Last), ReadOptions readOptions = NoReadOptions);
QX_IO_EXPORT IoOpReport writeStringToFile(QFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(Start), WriteOptions writeOptions = NoWriteOptions);
QX_IO_EXPORT IoOpReport writeStringToFile(QSaveFile& textFile, const QString& text, WriteMode writeMode = Truncate, TextPos startPos = TextPos(Start), WriteOptions writeOptions = NoWriteOptions);
QX_IO_EXPORT IoOpReport deleteTextFromFile(QFile& textFile, TextPos startPos, TextPos endPos);

// Directory:
Expand All @@ -81,7 +81,7 @@ QX_IO_EXPORT IoOpReport calculateFileChecksum(QString& returnBuffer, QFile& file
QX_IO_EXPORT IoOpReport fileMatchesChecksum(bool& returnBuffer, QFile& file, QString checksum, QCryptographicHash::Algorithm hashAlgorithm);

// Binary Based
QX_IO_EXPORT IoOpReport readBytesFromFile(QByteArray& returnBuffer, QFile& file, Index64 startPos = 0, Index64 endPos = Index64(Index64::Last));
QX_IO_EXPORT IoOpReport readBytesFromFile(QByteArray& returnBuffer, QFile& file, Index64 startPos = 0, Index64 endPos = Index64(Last));
QX_IO_EXPORT IoOpReport writeBytesToFile(QFile& file, const QByteArray& bytes, WriteMode writeMode = Truncate, Index64 startPos = 0, WriteOptions writeOptions = NoWriteOptions);
QX_IO_EXPORT IoOpReport writeBytesToFile(QSaveFile& file, const QByteArray& bytes, WriteMode writeMode = Truncate, Index64 startPos = 0, WriteOptions writeOptions = NoWriteOptions);
}
Expand Down
8 changes: 0 additions & 8 deletions lib/io/include/qx/io/qx-textpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ namespace Qx

class QX_IO_EXPORT TextPos
{
//-Class Types------------------------------------------------------------------------------------------------------
public:
enum Extent
{
Start,
End
};

//-Instance Variables------------------------------------------------------------------------------------------------
private:
Index32 mLine;
Expand Down
22 changes: 11 additions & 11 deletions lib/io/src/qx-common-io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ IoOpReport findStringInFile(QList<TextPos>& returnBuffer, QFile& textFile, const

// Query tracking
TextPos trueStartPos = query.startPosition();
TextPos currentPos = TextPos(TextPos::Start);
TextPos currentPos = TextPos(Start);
TextPos possibleMatch = TextPos();
int hitsSkipped = 0;
QString::const_iterator queryIt = query.string().constBegin();
Expand All @@ -469,7 +469,7 @@ IoOpReport findStringInFile(QList<TextPos>& returnBuffer, QFile& textFile, const
QTextStream fileTextStream(&textFile);

// Translate start position to absolute position
if(trueStartPos != TextPos(TextPos::Start))
if(trueStartPos != TextPos(Start))
{
IoOpReport translate = textFileAbsolutePosition(trueStartPos, textFile, readOptions.testFlag(IgnoreTrailingBreak));
if(translate.isFailure())
Expand All @@ -489,7 +489,7 @@ IoOpReport findStringInFile(QList<TextPos>& returnBuffer, QFile& textFile, const
QScopeGuard fileGuard([&textFile](){ textFile.close(); });

// Skip to start pos
if(trueStartPos != TextPos(TextPos::Start))
if(trueStartPos != TextPos(Start))
{
int line;
// Skip to start line
Expand Down Expand Up @@ -739,7 +739,7 @@ IoOpReport readTextFromFile(QString& returnBuffer, QFile& textFile, TextPos star
TextStream fileTextStream(&textFile);

// Cover each possible range type
if(startPos == TextPos(TextPos::Start) && endPos == TextPos(TextPos::End)) // Whole file is desired
if(startPos == TextPos(Start) && endPos == TextPos(End)) // Whole file is desired
{
returnBuffer = fileTextStream.readAll();

Expand Down Expand Up @@ -999,7 +999,7 @@ namespace

// Fill beforeNew
TextPos beforeEnd = TextPos(startPos.line(), startPos.character() - 1);
IoOpReport readBefore = readTextFromFile(beforeNew, auxFile, TextPos(TextPos::Start), beforeEnd);
IoOpReport readBefore = readTextFromFile(beforeNew, auxFile, TextPos(Start), beforeEnd);
if(readBefore.isFailure())
return readBefore;

Expand Down Expand Up @@ -1178,27 +1178,27 @@ IoOpReport deleteTextFromFile(QFile& textFile, TextPos startPos, TextPos endPos)
IoOpReport transientReport;

// Determine beforeDeletion
if(startPos == TextPos(TextPos::Start)) // (0,0)
if(startPos == TextPos(Start)) // (0,0)
beforeDeletion = u""_s;
else if(startPos.character().isLast())
{
transientReport = readTextFromFile(beforeDeletion, textFile, TextPos(TextPos::Start), startPos);
transientReport = readTextFromFile(beforeDeletion, textFile, TextPos(Start), startPos);
beforeDeletion.chop(1);
}
else
transientReport = readTextFromFile(beforeDeletion, textFile, TextPos(TextPos::Start), TextPos(startPos.line(), startPos.character() - 1));
transientReport = readTextFromFile(beforeDeletion, textFile, TextPos(Start), TextPos(startPos.line(), startPos.character() - 1));

// Check for transient errors
if(!transientReport.isNull() && transientReport.result() != IO_SUCCESS)
return IoOpReport(IO_OP_WRITE, transientReport.result(), textFile);

// Determine afterDeletion
if(endPos == TextPos(TextPos::End))
if(endPos == TextPos(End))
afterDeletion = u""_s;
else if(endPos.character().isLast())
transientReport = readTextFromFile(afterDeletion, textFile, TextPos(endPos.line() + 1, 0), TextPos(TextPos::End));
transientReport = readTextFromFile(afterDeletion, textFile, TextPos(endPos.line() + 1, 0), TextPos(End));
else
transientReport = readTextFromFile(afterDeletion, textFile, TextPos(endPos.line(), endPos.character() + 1), TextPos(TextPos::End));
transientReport = readTextFromFile(afterDeletion, textFile, TextPos(endPos.line(), endPos.character() + 1), TextPos(End));

// Check for transient errors
if(transientReport.result() != IO_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/qx-common-io_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ IoOpReport writePrep(const QFileInfo& fileInfo, WriteOptions writeOptions)
void matchAppendConditionParams(WriteMode& writeMode, TextPos& startPos)
{
// Match append condition parameters
if(startPos == TextPos(TextPos::End))
if(startPos == TextPos(End))
writeMode = Append;
else if(writeMode == Append)
startPos = TextPos(TextPos::End);
startPos = TextPos(End);
}

/*! @endcond */
Expand Down
2 changes: 1 addition & 1 deletion lib/io/src/qx-common-io_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void matchAppendConditionParams(WriteMode& writeMode, Index<T>& startPos)
if(startPos.isLast())
writeMode = Append;
else if(writeMode == Append)
startPos = Index<T>(Index<T>::Last);
startPos = Index<T>(Last);
}
/*! @endcond */
}
Expand Down
28 changes: 5 additions & 23 deletions lib/io/src/qx-textpos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ namespace Qx
* @brief The TextPos class is used to represent an offset within a text file in terms of lines and characters.
*/

//-Class Types-----------------------------------------------------------------------------------------------
//Public:

/*!
* @enum TextPos::Extent
*
* Used to refer to text positions of special significance.
*
* @var Index<T>::Extent Index<T>::First
* A text position representing the start of a file.
*
* Equivalent to @c TextPos(0,0).
*
* @var Index<T>::Extent Index<T>::Last
* A text position representing the end file.
*
* Equivalent to @c TextPos(Index32(Index32::Last), Index32(Index32::Last)).
*/

//-Constructor---------------------------------------------------------------------------------------------------
//Public:

Expand All @@ -45,10 +26,11 @@ TextPos::TextPos() :
mCharacter(Index32())
{}

//TODO: Consider creating Qx::Extent (with Start/End) in qx-global and just use
// that for Index and TextPos.
/*!
* Creates a text position at the given extent @a e.
*
* Start creates a text position equivalent to @c TextPos(0,0), while End creates
* a text position equivalent to @c TextPos(Index32(Qx::Last), Index32(Qx::Last)).
*/
TextPos::TextPos(Extent e)
{
Expand All @@ -60,8 +42,8 @@ TextPos::TextPos(Extent e)
break;

case End:
mLine = Index32(Index32::Last);
mCharacter = Index32(Index32::Last);
mLine = Index32(Last);
mCharacter = Index32(Last);
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions lib/io/src/qx-textquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Qx
TextQuery::TextQuery(const QString& string, Qt::CaseSensitivity cs) :
mString(string),
mCaseSensitivity(cs),
mStartPos(TextPos(TextPos::Start)),
mStartPos(TextPos(Start)),
mHitsToSkip(0),
mHitLimit(-1),
mAllowSplit(false)
Expand All @@ -48,7 +48,7 @@ Qt::CaseSensitivity TextQuery::caseSensitivity() const { return mCaseSensitivity
/*!
* Returns the position from which the search should begin.
*
* The default is @c TextPos(TextPos::Start).
* The default is @c TextPos(Start).
*/
TextPos TextQuery::startPosition() const { return mStartPos; }

Expand Down

0 comments on commit e48207c

Please sign in to comment.