kstars
#include <binfilehelper.h>
Public Types | |
enum | dataType { DT_CHAR, DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_UINT32, DT_CHARV, DT_STR, DT_SPCL = 128 } |
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 () |
long | getDataOffset () |
QString | getError () |
int | getErrorNumber () |
struct dataElement | getField (const QString &fieldName) |
int | getFieldCount () |
FILE * | getFileHandle () |
QString | getHeaderText () |
long | getIndexTableOffset () |
long | getOffset (int id) |
unsigned int | getRecordCount (int id) |
unsigned long | getRecordCount () |
int | guessRecordSize () |
bool | isField (const QString &FieldName) |
FILE * | openFile (const QString &fileName) |
bool | propertiesUpdated () |
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 52 of file binfilehelper.h.
Member Enumeration Documentation
An enum providing user-friendly names for data types.
Enumerator | |
---|---|
DT_CHAR | |
DT_INT8 | |
DT_UINT8 | |
DT_INT16 | |
DT_UINT16 | |
DT_INT32 | |
DT_UINT32 | |
DT_CHARV | |
DT_STR | |
DT_SPCL |
Definition at line 237 of file binfilehelper.h.
An enum providing user-friendly names for errors encountered.
Enumerator | |
---|---|
ERR_NULL | |
ERR_FILEOPEN | |
ERR_FD_TRUNC | |
ERR_INDEX_TRUNC | |
ERR_INDEX_BADID | |
ERR_INDEX_IDMISMATCH | |
ERR_INDEX_BADOFFSET | |
ERR_BADSEEK |
Definition at line 222 of file binfilehelper.h.
Constructor & Destructor Documentation
BinFileHelper::BinFileHelper | ( | ) |
Constructor.
Definition at line 27 of file binfilehelper.cpp.
BinFileHelper::~BinFileHelper | ( | ) |
Destructor.
Definition at line 32 of file binfilehelper.cpp.
Member Function Documentation
void BinFileHelper::closeFile | ( | ) |
Close the binary data file.
Definition at line 223 of file binfilehelper.cpp.
|
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 159 of file binfilehelper.h.
|
inline |
Returns the offset at which the data begins.
- Returns
- The value of dataOffset if indexUpdated, else zero
Definition at line 194 of file binfilehelper.h.
QString BinFileHelper::getError | ( | ) |
Get error string.
- Returns
- A QString containing the error message to be displayed
Definition at line 234 of file binfilehelper.cpp.
int BinFileHelper::getErrorNumber | ( | ) |
Get error number.
- Returns
- A number corresponding to the error
Definition at line 228 of file binfilehelper.cpp.
struct dataElement BinFileHelper::getField | ( | const QString & | fieldName | ) |
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 240 of file binfilehelper.cpp.
|
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 182 of file binfilehelper.h.
|
inline |
Get the file handle corresponding to the currently open file.
- Returns
- The filehandle if a file is open, NULL if no file is open
Definition at line 132 of file binfilehelper.h.
|
inline |
Returns the header text.
- Returns
- QString containing the header text if header has been read, blank QString otherwise
Definition at line 188 of file binfilehelper.h.
|
inline |
Returns the offset at which the index table begins.
- Returns
- The value of itableOffset if FDUpdated, else zero
Definition at line 200 of file binfilehelper.h.
|
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 139 of file binfilehelper.h.
|
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 146 of file binfilehelper.h.
|
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 152 of file binfilehelper.h.
|
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 167 of file binfilehelper.h.
bool BinFileHelper::isField | ( | const QString & | FieldName | ) |
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 251 of file binfilehelper.cpp.
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, NULL if an error occurred, sets the error.
Definition at line 69 of file binfilehelper.cpp.
|
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 126 of file binfilehelper.h.
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 200 of file binfilehelper.cpp.
|
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
-
The correct recordSize
Definition at line 176 of file binfilehelper.h.
|
static |
Checks if a file exists.
WARNING: Might be incompatible in other locales
Definition at line 56 of file binfilehelper.cpp.
|
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 259 of file binfilehelper.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.