VHISTlib
1.84.0.3018
|
This class makes it possible to iterate linewise over a file in both directions without keeping the whole file inside memory. More...
#include <fileiterator.h>
Public Member Functions | |
FileIterator () | |
Creates a new FileIterator object. | |
~FileIterator () | |
Destroys the FileIterator object. | |
bool | open (const QString &filename) |
Opens the given file for iterating. | |
bool | nextLine () |
Moves the cursor to the next line. | |
bool | prevLine () |
Moves the cursor to the previous line. | |
bool | firstLine () |
Moves the cursor to the first line of the file. | |
bool | lastLine () |
Move the cursor to the last line of the file. | |
bool | reachedStart () |
Returns true if the cursor has reached the start of the file. | |
bool | reachedEnd () |
Returns true if the cursor has reached the end of the file. | |
bool | onLine () |
Not implemented, yet. | |
bool | empty () |
Returns whether the file is empty or not. | |
bool | gotoPos (int pos) |
Moves the cursor to the given location. | |
MaybeArray | curLine () |
Returns the current line as a QByteArray. | |
MaybeString | curLineAsString () |
Returns the current line as a QString. | |
int | curPos () |
Returns the current position of the cursor in bytes relative to the beginning of the document. | |
QByteArray | getBytes (int startPos, int numBytes) |
Returns a chunk of data from the file. | |
bool | curLineStartsWithBytes (const char *str) |
This class makes it possible to iterate linewise over a file in both directions without keeping the whole file inside memory.
The class maintains a cursor which points to the current line. The cursor can either be moved up, down, to the beginning or end of the document or placed at an arbitrary position inside the file.
MaybeArray FileIterator::curLine | ( | ) |
Returns the current line as a QByteArray.
If there is no current line, e.g. because the file is empty or the cursor has reached the start or end of the file, MaybeArray::nothing() is returned.
MaybeString FileIterator::curLineAsString | ( | ) |
Returns the current line as a QString.
The line is therefore interpreted as beeing encoded in UTF8. If there is no current line or the line cannot be decoded from UTF8, MaybeString::nothing() is returned.
int FileIterator::curPos | ( | ) |
Returns the current position of the cursor in bytes relative to the beginning of the document.
bool FileIterator::empty | ( | ) |
Returns whether the file is empty or not.
true
if the file is empty and false
otherwise. bool FileIterator::firstLine | ( | ) |
Moves the cursor to the first line of the file.
Returns false
if the file is empty.
true
on success and false
if the document is empty. QByteArray FileIterator::getBytes | ( | int | startPos, |
int | numBytes | ||
) |
Returns a chunk of data from the file.
[in] | startPos | The position of the first byte in the requested chunk. |
[in] | numBytes | The number of bytes of the requested chunk. |
bool FileIterator::gotoPos | ( | int | pos | ) |
Moves the cursor to the given location.
Note that this position does not have to be the beginning of a line. In this case, only the part of the line following the cursor position is returned when calling curLine or curLineAsString after gotoPos.
[in] | pos | The position to which the cursor should be moved. It's measured in bytes and is relative to the beginning of the file. |
true
if moving the cursor was successful and false
otherwise. bool FileIterator::lastLine | ( | ) |
Move the cursor to the last line of the file.
Returns false
if the file is empty.
true
on success and false
if the document is empty. bool FileIterator::nextLine | ( | ) |
Moves the cursor to the next line.
If the cursor is already located at the end of the file, false
is returned.
true
if the cursor was moved to the next line and false
if the cursor has already reached the end of the file. bool FileIterator::open | ( | const QString & | filename | ) |
Opens the given file for iterating.
If the file cannot be opened, false
is returned.
[in] | filename | The name of the file. |
true
if opening the file was successful and false
otherwise. bool FileIterator::prevLine | ( | ) |
Moves the cursor to the previous line.
If the cursor is already located at the end of the file, false
is returned.
true
if the cursor was moved to the previous line and false
if the cursor has already reached the beginning of the file. bool FileIterator::reachedEnd | ( | ) |
Returns true
if the cursor has reached the end of the file.
true
if the cursor has reached the end of the file and false
otherwise. bool FileIterator::reachedStart | ( | ) |
Returns true
if the cursor has reached the start of the file.
true
if the cursor has reached the start of the file and false
otherwise.