-
Notifications
You must be signed in to change notification settings - Fork 5
/
asterixReportGenerator.h
91 lines (72 loc) · 3.3 KB
/
asterixReportGenerator.h
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
/*
* This application is free software and is released under the terms of
* the BSD license. See LICENSE file for details.
*
* Copyright (c) 2016 Volker Poplawski ([email protected])
*/
#ifndef ASTERIXREPORTGENERATOR_H
#define ASTERIXREPORTGENERATOR_H
#include <QtCore>
#include <QTextStream>
#include "asterix.h"
class AbstractGenerator;
class AsterixReportGenerator : public QObject
{
Q_OBJECT
public:
explicit AsterixReportGenerator( QObject *parent = 0 );
enum Type {
XML,
};
void createReport(QTextStream& output, Type type);
void handleBlock(AbstractGenerator* gen, const AsterixBlock& block);
protected:
void createBlockReport( const AsterixBlock& block, QTextStream& out );
void createRecordReport( const AsterixRecord& record, QTextStream& out );
void createDataItemReport(const AsterixDataItem &dataItem, QTextStream &out);
void applyUnitAndScale(const UapField &uapField, int value, QTextStream &out);
};
class AbstractGenerator
{
public:
struct Field {
QString value;
QString unit;
qint64 rawval;
bool hasraw;
};
AbstractGenerator(QTextStream& out) : m_stream(out), m_indention(4) {}
virtual ~AbstractGenerator() {}
virtual void startBlock(const AsterixBlock& block) = 0;
virtual void finishBlock(const AsterixBlock& block) = 0;
virtual void startRecordsSection(const AsterixBlock& /*block*/) {}
virtual void finishRecordsSection(const AsterixBlock& /*block*/) {}
virtual void startRecord(const AsterixRecord& record) = 0;
virtual void finishRecord(const AsterixRecord& record) = 0;
virtual void startDataItemsSection(const AsterixRecord& /*record*/, int /*indent*/ = 0) {}
virtual void startDataItem(const AsterixDataItem& dataItem, const UapDataItem& uap, int indent = 0) = 0;
virtual void finishDataItem(const AsterixDataItem& dataItem, const UapDataItem& uap, int indent = 0) = 0;
virtual void finishDataItemsSection(const AsterixRecord& /*record*/, int /*indent*/ = 0) {}
virtual void startFinishField(const AsterixDataItem& dataItem, const UapField& uap, int indent = 0) = 0;
static Field decodeField(const AsterixDataItem& dataItem, const UapField& uapField);
static Field unitAndScale(const UapField &uapField, qint64 rawvalue);
protected:
QTextStream& ind(int level) const { m_stream << QString(level * m_indention, ' '); return m_stream; } // indent line
QTextStream& m_stream;
int m_indention;
};
class XmlGenerator : public AbstractGenerator
{
public:
XmlGenerator(QTextStream& out) : AbstractGenerator(out) { m_stream << "<report>" << endl; }
~XmlGenerator() { m_stream << "</report>" << endl; }
void startBlock(const AsterixBlock& block) override;
void finishBlock(const AsterixBlock& block) override;
void startRecord(const AsterixRecord& record) override;
void finishRecord(const AsterixRecord& record) override;
void startDataItem(const AsterixDataItem& dataItem, const UapDataItem& uap, int indent = 0) override;
void finishDataItem(const AsterixDataItem& dataItem, const UapDataItem& uap, int indent = 0) override;
void startFinishField(const AsterixDataItem& dataItem, const UapField& uap, int indent = 0) override;
static QString wrapInCData(const QString& s);
};
#endif // ASTERIXREPORTGENERATOR_H