• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

Public Types | Public Member Functions | Static Public Member Functions | List of all members
BinFileHelper Class Reference

#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

Author
Akarsh Simha
Version
1.0

Definition at line 52 of file binfilehelper.h.

Member Enumeration Documentation

enum BinFileHelper::dataType

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.

enum BinFileHelper::Errors

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.

bool BinFileHelper::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 159 of file binfilehelper.h.

long BinFileHelper::getDataOffset ( )
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
fieldNameName 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.

int BinFileHelper::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 182 of file binfilehelper.h.

FILE* BinFileHelper::getFileHandle ( )
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.

QString BinFileHelper::getHeaderText ( )
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.

long BinFileHelper::getIndexTableOffset ( )
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.

long BinFileHelper::getOffset ( int  id)
inline

Returns the offset in the file corresponding to the given index ID.

Parameters
idID 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.

unsigned int BinFileHelper::getRecordCount ( int  id)
inline

Returns the number of records under the given index ID.

Parameters
idID 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.

unsigned long BinFileHelper::getRecordCount ( )
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.

int BinFileHelper::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 167 of file binfilehelper.h.

bool BinFileHelper::isField ( const QString &  FieldName)

Check whether a field exists.

Parameters
fieldNameName 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
fileNameReference 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.

bool BinFileHelper::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 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.

void BinFileHelper::setRecordSize ( int  rs)
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
Thecorrect recordSize

Definition at line 176 of file binfilehelper.h.

bool BinFileHelper::testFileExists ( const QString &  fileName)
static

Checks if a file exists.

WARNING: Might be incompatible in other locales

Definition at line 56 of file binfilehelper.cpp.

int BinFileHelper::unsigned_KDE_fseek ( FILE *  stream,
quint32  offset,
int  whence 
)
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:
  • binfilehelper.h
  • binfilehelper.cpp
This file is part of the KDE documentation.
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.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal