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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
binfilehelper.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  binfilehelper.h - K Desktop Planetarium
4  -------------------
5  begin : Sat May 31 2008
6  copyright : (C) 2008 by Akarsh Simha
7  email : akarshsimha@gmail.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #ifndef BINFILEHELPER_H_
21 #define BINFILEHELPER_H_
22 
23 #include <QString>
24 #include <QVector>
25 
26 #include <cstdio>
27 
28 class QString;
29 
33 typedef struct dataElement {
34  char name[10];
35  qint8 size;
36  quint8 type;
37  qint32 scale;
38 } dataElement;
39 
40 
52 class BinFileHelper {
53 
54  public:
55 
60  BinFileHelper();
61 
66  ~BinFileHelper();
67 
71  static bool testFileExists( const QString &fileName );
72 
80  FILE *openFile(const QString &fileName);
81 
87  bool readHeader();
88 
93  void closeFile();
94 
99  int getErrorNumber();
100 
105  QString getError();
106 
113  struct dataElement getField(const QString &fieldName);
114 
120  bool isField(const QString &FieldName);
121 
126  inline bool propertiesUpdated() { return indexUpdated; }
127 
132  inline FILE *getFileHandle() { return fileHandle; }
133 
139  inline long getOffset(int id) { return (indexUpdated ? indexOffset.at( id ) : 0); }
140 
146  inline unsigned int getRecordCount(int id) { return (indexUpdated ? indexCount.at( id ) : 0); }
147 
152  inline unsigned long getRecordCount() { return (indexUpdated ? recordCount : 0); }
153 
159  inline bool getByteSwap() { return byteswap; }
160 
167  inline int guessRecordSize() { return (RSUpdated ? recordSize : 0); }
168 
176  inline void setRecordSize(int rs) { recordSize = rs; RSUpdated = true; }
177 
182  inline int getFieldCount() { return (FDUpdated ? nfields : 0); }
183 
188  inline QString getHeaderText() { return (preambleUpdated ? headerText : ""); }
189 
194  inline long getDataOffset() { return (indexUpdated ? dataOffset : 0); }
195 
200  inline long getIndexTableOffset() { return (FDUpdated ? itableOffset : 0); }
201 
217  static int unsigned_KDE_fseek( FILE *stream, quint32 offset, int whence );
218 
222  enum Errors {
223  ERR_NULL, // No error occurred
224  ERR_FILEOPEN, // File could not be opened
225  ERR_FD_TRUNC, // Field descriptor table is truncated
226  ERR_INDEX_TRUNC, // File ends prematurely, before expected end of index table
227  ERR_INDEX_BADID, // Index table has an invalid ID entry
228  ERR_INDEX_IDMISMATCH, // Index table has a mismatched ID entry [ID found in the wrong place]
229  ERR_INDEX_BADOFFSET, // Offset / Record count specified in the Index table is bad
230  ERR_BADSEEK // Premature end of file / bad seek while reading index table
231  };
232 
237  enum dataType {
238  DT_CHAR, /* Character */
239  DT_INT8, /* 8-bit Integer */
240  DT_UINT8, /* 8-bit Unsigned Integer */
241  DT_INT16, /* 16-bit Integer */
242  DT_UINT16, /* 16-bit Unsigned Integer */
243  DT_INT32, /* 32-bit Integer */
244  DT_UINT32, /* 32-bit Unsigned Integer */
245  DT_CHARV, /* Fixed-length array of characters */
246  DT_STR, /* Variable length array of characters, either terminated by NULL or by the limit on field size */
247  DT_SPCL = 128 /* Flag indicating that the field requires special treatment (eg: Different bits may mean different things) */
248  };
249 
250  private:
251 
256  enum Errors __readHeader();
257 
261  void clearFields();
262 
266  void init();
267 
268  FILE *fileHandle; // Handle to the file.
269  QVector<unsigned long> indexOffset; // Stores offsets corresponding to each index table entry
270  QVector<unsigned int> indexCount; // Stores number of records under each index table entry
271  bool indexUpdated; // True if the data from the index, and associated properties have been updated
272  bool FDUpdated; // True if the data from the Field Descriptor, and associated properties have been updated
273  bool RSUpdated; // True if the recordSize parameter is set correctly, either manually or bye reading the FD
274  bool preambleUpdated; // True if the data from the preamble and associated properties have been updated
275  enum Errors errnum; // Stores the number corresponding to the previous error
276  bool byteswap; // True if byteswapping should be done
277  int recordSize; // Stores the size of a record in bytes for quick retrieval
278  QVector<dataElement *> fields; // Maintains a list of fields in the file, along with relevant details
279  QString headerText; // Stores the file header text
280  qint16 nfields; // Stores the number of fields as indicated by the field descriptor
281  quint32 indexSize; // Stores the size of the index table in number of entries
282  long itableOffset; // Stores the offset position of the first index table entry
283  long dataOffset; // Stores the offset position of the start of data
284  QString errorMessage; // Stores the most recent 'unread' error message
285  unsigned long recordCount; // Stores the total number of records in the file
286  quint8 versionNumber; // Stores the version number of the file
287 };
288 
289 #endif
BinFileHelper::propertiesUpdated
bool propertiesUpdated()
Check whether file properties are real or bogus.
Definition: binfilehelper.h:126
BinFileHelper::getHeaderText
QString getHeaderText()
Returns the header text.
Definition: binfilehelper.h:188
BinFileHelper::getIndexTableOffset
long getIndexTableOffset()
Returns the offset at which the index table begins.
Definition: binfilehelper.h:200
BinFileHelper::DT_UINT32
Definition: binfilehelper.h:244
BinFileHelper::DT_UINT16
Definition: binfilehelper.h:242
BinFileHelper::DT_CHAR
Definition: binfilehelper.h:238
BinFileHelper::closeFile
void closeFile()
Close the binary data file.
Definition: binfilehelper.cpp:223
BinFileHelper::DT_INT8
Definition: binfilehelper.h:239
BinFileHelper::ERR_FILEOPEN
Definition: binfilehelper.h:224
BinFileHelper::getFieldCount
int getFieldCount()
Returns the number of fields as suggested by the field descriptor in the header.
Definition: binfilehelper.h:182
BinFileHelper::getRecordCount
unsigned long getRecordCount()
Returns the total number of records in the file.
Definition: binfilehelper.h:152
BinFileHelper::isField
bool isField(const QString &FieldName)
Check whether a field exists.
Definition: binfilehelper.cpp:251
BinFileHelper::ERR_NULL
Definition: binfilehelper.h:223
BinFileHelper::ERR_INDEX_BADID
Definition: binfilehelper.h:227
BinFileHelper::getRecordCount
unsigned int getRecordCount(int id)
Returns the number of records under the given index ID.
Definition: binfilehelper.h:146
BinFileHelper::getError
QString getError()
Get error string.
Definition: binfilehelper.cpp:234
BinFileHelper::getFileHandle
FILE * getFileHandle()
Get the file handle corresponding to the currently open file.
Definition: binfilehelper.h:132
BinFileHelper::setRecordSize
void setRecordSize(int rs)
Override record size.
Definition: binfilehelper.h:176
BinFileHelper::DT_CHARV
Definition: binfilehelper.h:245
BinFileHelper::testFileExists
static bool testFileExists(const QString &fileName)
Checks if a file exists.
Definition: binfilehelper.cpp:56
BinFileHelper::ERR_INDEX_BADOFFSET
Definition: binfilehelper.h:229
BinFileHelper
This class provides utility functions to handle binary data files in the format prescribed by KStars...
Definition: binfilehelper.h:52
BinFileHelper::openFile
FILE * openFile(const QString &fileName)
WARNING: This function may not be compatible in other locales, because it calls QString::toAscii.
Definition: binfilehelper.cpp:69
dataElement
A structure describing a data field in the file.
Definition: binfilehelper.h:33
BinFileHelper::guessRecordSize
int guessRecordSize()
Return a guessed record size.
Definition: binfilehelper.h:167
BinFileHelper::getErrorNumber
int getErrorNumber()
Get error number.
Definition: binfilehelper.cpp:228
BinFileHelper::DT_UINT8
Definition: binfilehelper.h:240
BinFileHelper::getDataOffset
long getDataOffset()
Returns the offset at which the data begins.
Definition: binfilehelper.h:194
dataElement
struct dataElement dataElement
A structure describing a data field in the file.
dataElement::scale
qint32 scale
Definition: binfilehelper.h:37
BinFileHelper::DT_SPCL
Definition: binfilehelper.h:247
BinFileHelper::DT_INT32
Definition: binfilehelper.h:243
BinFileHelper::~BinFileHelper
~BinFileHelper()
Destructor.
Definition: binfilehelper.cpp:32
dataElement::type
quint8 type
Definition: binfilehelper.h:36
BinFileHelper::ERR_FD_TRUNC
Definition: binfilehelper.h:225
BinFileHelper::getByteSwap
bool getByteSwap()
Should we do byte swapping?
Definition: binfilehelper.h:159
BinFileHelper::ERR_INDEX_TRUNC
Definition: binfilehelper.h:226
dataElement::name
char name[10]
Definition: binfilehelper.h:34
BinFileHelper::readHeader
bool readHeader()
Read the header and index table from the file and fill up the QVector s with the entries.
Definition: binfilehelper.cpp:200
BinFileHelper::ERR_INDEX_IDMISMATCH
Definition: binfilehelper.h:228
BinFileHelper::unsigned_KDE_fseek
static int unsigned_KDE_fseek(FILE *stream, quint32 offset, int whence)
Wrapper around fseek for large offsets.
Definition: binfilehelper.cpp:259
BinFileHelper::dataType
dataType
An enum providing user-friendly names for data types.
Definition: binfilehelper.h:237
BinFileHelper::DT_INT16
Definition: binfilehelper.h:241
BinFileHelper::Errors
Errors
An enum providing user-friendly names for errors encountered.
Definition: binfilehelper.h:222
BinFileHelper::BinFileHelper
BinFileHelper()
Constructor.
Definition: binfilehelper.cpp:27
BinFileHelper::getOffset
long getOffset(int id)
Returns the offset in the file corresponding to the given index ID.
Definition: binfilehelper.h:139
BinFileHelper::DT_STR
Definition: binfilehelper.h:246
BinFileHelper::ERR_BADSEEK
Definition: binfilehelper.h:230
dataElement::size
qint8 size
Definition: binfilehelper.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 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