-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader.hpp
69 lines (52 loc) · 1.38 KB
/
reader.hpp
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
#ifndef READER_H
#define READER_H
#include "case.hpp"
#include "casemanager.hpp"
#include <QObject>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QByteArray>
#include <QDebug>
class Reader : public QObject
{
Q_OBJECT
public:
explicit Reader(QString const& filename)
: QObject( 0 ),
file( filename )
{
bool opened = file.open(QFile::Text | QFile::ReadOnly);
Q_ASSERT_X(opened,
"Reader ctor",
tr("Couldn't open file \"%1\"!").arg(filename).toUtf8().data()
);
Q_UNUSED(opened)
in.setDevice( &file );
}
signals:
void readCase(Case *cs);
void readAllCases();
public slots:
void readInput()
{
qDebug() << this << ": Begin reading input file" << file.fileName();
int case_amount;
in >> case_amount;
in.readLine(); // to skip to '\n' after reading case_amount
CaseManager *manager = CaseManager::instance();
manager->setTotalAmountOfCases(case_amount);
for (int case_no = 1; case_no <= case_amount; ++case_no)
{
Case *cs = manager->getCase(case_no);
cs->readInput( in );
emit readCase( cs );
}
qDebug() << this << ": Read all cases";
emit readAllCases();
}
private:
QFile file;
QTextStream in;
};
#endif // READER_H