BinFileHelper
#include <binfilehelper.h>
Public Types | |
enum | Errors { ERR_NULL , ERR_FILEOPEN , ERR_FD_TRUNC , ERR_INDEX_TRUNC , ERR_INDEX_BADID , ERR_INDEX_IDMISMATCH , ERR_INDEX_BADOFFSET , ERR_BADSEEK } |
Public Member Functions | |
BinFileHelper () | |
~BinFileHelper () | |
void | closeFile () |
bool | getByteSwap () const |
long | getDataOffset () const |
QString | getError () |
int | getErrorNumber () |
struct dataElement | getField (const QString &fieldName) const |
int | getFieldCount () const |
FILE * | getFileHandle () const |
QString | getHeaderText () const |
long | getIndexTableOffset () const |
long | getOffset (int id) const |
unsigned long | getRecordCount () const |
unsigned int | getRecordCount (int id) const |
int | guessRecordSize () const |
bool | isField (const QString &FieldName) const |
FILE * | openFile (const QString &fileName) |
bool | propertiesUpdated () const |
bool | readHeader () |
void | setRecordSize (int rs) |
Static Public Member Functions | |
static bool | testFileExists (const QString &fileName) |
static int | unsigned_KDE_fseek (FILE *stream, quint32 offset, int whence) |
Detailed Description
This class provides utility functions to handle binary data files in the format prescribed by KStars.
The file format is designed specifically to support data that has the form of an array of structures. See data/README.fileformat for details. The methods use primitive C file I/O routines defined in stdio.h to obtain efficiency
Implements an interface to handle binary data files used by KStars
- Version
- 1.0
Definition at line 38 of file binfilehelper.h.
Member Enumeration Documentation
◆ Errors
An enum providing user-friendly names for errors encountered.
Definition at line 201 of file binfilehelper.h.
Constructor & Destructor Documentation
◆ BinFileHelper()
BinFileHelper::BinFileHelper | ( | ) |
Constructor.
Definition at line 16 of file binfilehelper.cpp.
◆ ~BinFileHelper()
BinFileHelper::~BinFileHelper | ( | ) |
Destructor.
Definition at line 21 of file binfilehelper.cpp.
Member Function Documentation
◆ closeFile()
void BinFileHelper::closeFile | ( | ) |
Close the binary data file.
Definition at line 276 of file binfilehelper.cpp.
◆ getByteSwap()
|
inline |
Should we do byte swapping?
- Note
- To be called only after the header has been parsed
- Returns
- true if we must do byte swapping, false if not
Definition at line 136 of file binfilehelper.h.
◆ getDataOffset()
|
inline |
Returns the offset at which the data begins.
- Returns
- The value of dataOffset if indexUpdated, else zero
Definition at line 175 of file binfilehelper.h.
◆ getError()
QString BinFileHelper::getError | ( | ) |
Get error string.
- Returns
- A QString containing the error message to be displayed
Definition at line 289 of file binfilehelper.cpp.
◆ getErrorNumber()
int BinFileHelper::getErrorNumber | ( | ) |
Get error number.
- Returns
- A number corresponding to the error
Definition at line 282 of file binfilehelper.cpp.
◆ getField()
struct dataElement BinFileHelper::getField | ( | const QString & | fieldName | ) | const |
Get field by name.
- Parameters
-
fieldName Name of the field
- Returns
- A dataElement structure containing field data if the field exists, containing junk values if the field doesn't exist
Definition at line 296 of file binfilehelper.cpp.
◆ getFieldCount()
|
inline |
Returns the number of fields as suggested by the field descriptor in the header.
- Returns
- Number of fields, or zero if the FD hasn't been read yet
Definition at line 163 of file binfilehelper.h.
◆ getFileHandle()
|
inline |
Get the file handle corresponding to the currently open file.
- Returns
- The filehandle if a file is open, nullptr if no file is open
Definition at line 109 of file binfilehelper.h.
◆ getHeaderText()
|
inline |
Returns the header text.
Definition at line 169 of file binfilehelper.h.
◆ getIndexTableOffset()
|
inline |
Returns the offset at which the index table begins.
- Returns
- The value of itableOffset if FDUpdated, else zero
Definition at line 181 of file binfilehelper.h.
◆ getOffset()
|
inline |
Returns the offset in the file corresponding to the given index ID.
- Parameters
-
id ID of the index entry whose offset is required
- Returns
- The offset corresponding to that index ID, 0 if the index hasn't been read
Definition at line 116 of file binfilehelper.h.
◆ getRecordCount() [1/2]
|
inline |
Returns the total number of records in the file.
- Returns
- The number of records in the file, or 0 if the index has not been read
Definition at line 129 of file binfilehelper.h.
◆ getRecordCount() [2/2]
|
inline |
Returns the number of records under the given index ID.
- Parameters
-
id ID of the index entry
- Returns
- The number of records under index that index ID, or 0 if the index has not been read
Definition at line 123 of file binfilehelper.h.
◆ guessRecordSize()
|
inline |
Return a guessed record size.
- Note
- The record size returned is guessed from the field descriptor table and may not be correct in many cases
- Returns
- A guessed size of the record, or zero if the FD hasn't been read yet
Definition at line 144 of file binfilehelper.h.
◆ isField()
bool BinFileHelper::isField | ( | const QString & | FieldName | ) | const |
Check whether a field exists.
- Parameters
-
FieldName Name of the field
- Returns
- True if the field exists, false if it does not or the FD hasn't been read yet
Definition at line 311 of file binfilehelper.cpp.
◆ openFile()
FILE * BinFileHelper::openFile | ( | const QString & | fileName | ) |
WARNING: This function may not be compatible in other locales, because it calls QString::toAscii.
Open a Binary data file and set the handle
- Parameters
-
fileName Reference to QString containing the name of the file
- Returns
- Handle to the file if successful, nullptr if an error occurred, sets the error.
Definition at line 72 of file binfilehelper.cpp.
◆ propertiesUpdated()
|
inline |
Check whether file properties are real or bogus.
- Returns
- The value of private variable indexUpdated, which is true if data has been updated
Definition at line 103 of file binfilehelper.h.
◆ readHeader()
bool BinFileHelper::readHeader | ( | ) |
Read the header and index table from the file and fill up the QVector s with the entries.
- Returns
- True if successful, false if an error occurred, sets the error.
Definition at line 250 of file binfilehelper.cpp.
◆ setRecordSize()
|
inline |
Override record size.
- Note
- To be used to override the guess in case the guess is wrong. This method should be called before calling readHeader(). Use this only if you are sure of the recordSize or are sure that the guess will not work.
- Parameters
-
rs The correct recordSize
Definition at line 153 of file binfilehelper.h.
◆ testFileExists()
|
static |
Checks if a file exists.
WARNING: Might be incompatible in other locales
Definition at line 57 of file binfilehelper.cpp.
◆ unsigned_KDE_fseek()
|
static |
Wrapper around fseek for large offsets.
fseek takes a signed long for the offset, since it can be either positive or negative. If the argument is a 32-bit unsigned integer, fseek will fail in most situations, since that will be interpreted as a number of the opposite sign. This wrapper circumvents that problem by repeatedly calling fseek twice if the offset is too large. Useful when 64-bit handling is really not necessary.
- Returns
- Zero on success. Else, error code of the first failing fseek call.
- Note
- Clearly, this method can move forward only. When we need one that goes back, we'll implement that.
Definition at line 321 of file binfilehelper.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:15:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.