VHISTlib  1.84.0.3018
Public Member Functions
vhist::FileIterator Class Reference

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>

List of all members.

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)

Detailed Description

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.


Member Function Documentation

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.

Returns:
The current line as a QByteArray.
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.

Returns:
The current line as a QString.
int FileIterator::curPos ( )

Returns the current position of the cursor in bytes relative to the beginning of the document.

Returns:
The current position of the cursor.
bool FileIterator::empty ( )

Returns whether the file is empty or not.

Returns:
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.

Returns:
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.

Parameters:
[in]startPosThe position of the first byte in the requested chunk.
[in]numBytesThe number of bytes of the requested chunk.
Returns:
The chunk of data or an empty buffer if the requested chunk is not completely inside the file.
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.

Parameters:
[in]posThe position to which the cursor should be moved. It's measured in bytes and is relative to the beginning of the file.
Returns:
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.

Returns:
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.

Returns:
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.

Parameters:
[in]filenameThe name of the file.
Returns:
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.

Returns:
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.

Returns:
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.

Returns:
true if the cursor has reached the start of the file and false otherwise.

The documentation for this class was generated from the following files:

VHISTlib 1.84.0.3018 of Jun 28 2013, generated by doxygen.