1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/***************************************************************************
filesource.h - description
-------------------
begin : Son Feb 10 2002
copyright : (C) 2002 by Thomas Kabelmann
email : tk78@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef FILESOURCE_H
#define FILESOURCE_H
/**@class FileSource
*FileSource is an asynchronous class for reloading star data while running
*the program. It's basing on QDataSource class and implements the function
*for reading a file step by step and send these data to an QDataSink object.
*KStarsData uses this class for asynchronous io.
*@author Thomas Kabelmann
*@version 1.0
*/
#include <qasyncio.h>
#include <qstring.h>
class KStarsData;
class KSFileReader;
class FileSource : public QDataSource {
public:
/**constructor needs an KStarsData object, a file name and the new magnitude
*/
FileSource( KStarsData *ksdata, float magnitude );
/** destructor */
~FileSource();
/**send a value indicating whether the object is ready to send data.
*@return 1 if data is ready to send; return -1 if the stream is finished.
*/
int readyToSend();
/**Is this object rewindable?
*@return false, because it's not needed to rewind.
*/
bool rewindable() { return false; }
/**The function for sending data to an QDataSink object. Here will all data
*operations defined. Because this function is virtual, we need a second int
*parameter, but we don't use it, so it's unnamed.
*@p sink pointer to the QDataSink object which will receive the data stream
*/
void sendTo( QDataSink *sink, int );
/**@return current magnitude to load (always returns maxMagnitude)
*/
float magnitude() { return maxMagnitude; }
private:
bool readingData;
KSFileReader *fileReader;
// which sao file should be opened and which line
int fileNumber, lineNumber;
// counts blocksize
int counter;
// new magnitude to load
float maxMagnitude;
KStarsData *data;
/**maxLines defines how many lines in data file should be read and
*send to QDataSink. This is only needed if a data block is longer
*than the max defined lines. I figured out this value of 500
*on a fast system, so if it is to high the value might be decreased.
*A high value means faster reloading but perhaps on slow systems this
*might interrupt the main event loop.
*A low value needs longer to reload data, but it doesn't interrupt the
*main event loop (it's smoother).
*But it's important to know that 500 lines to read is very fast, but
*appending to QList in StarDataSink will take the most time and this
*will also defined with this value.
*/
#define maxLines 500
/**The loaded data will stored in a string array and a pointer to first
*object in array will send to StarDataSink.
*/
QString stringArray[ maxLines ];
};
#endif
|