-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTsvFile.h
More file actions
55 lines (44 loc) · 1.54 KB
/
TsvFile.h
File metadata and controls
55 lines (44 loc) · 1.54 KB
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
#ifndef TSVFILE_H
#define TSVFILE_H
#include "cppCORE_global.h"
#include <QStringList>
#include <QTextStream>
#include <QHash>
///TSV file representation (row-wise)
class CPPCORESHARED_EXPORT TsvFile
{
public:
TsvFile();
void addComment(const QString& comment);
const QStringList& comments() const { return comments_; }
void setComments(const QStringList& comments);
void addHeader(const QString& header);
const QStringList& headers() const;
int columnCount() const { return headers_.count(); }
void addRow(const QStringList& row);
const QStringList& operator[](int i) const;
int count() const { return rows_.count(); }
//Returns the column index. Throws an exception if the column does not exist, or returns -1.
int columnIndex(const QString& column, bool throw_if_not_found=true) const;
//Loads a TSV file with '#' as start of header line and '##' as start of comment lines. Field strings can be hashed to save memory by implicit sharing.
void load(QString filename, bool use_string_hash=false);
//Stores the TSV file to a file.
void store(QString filename) const;
//Converts the TSV file to string.
QString toString() const;
//Creates a columns representation (slow).
QStringList extractColumn(int c);
//Removes a column.
void removeColumn(int c);
//returns wheather a file is loaded
bool isValid() const;
private:
QString filename_;
QStringList comments_;
QStringList headers_;
QList<QStringList> rows_;
QHash<QString, QString> hash_;
//Stream writer helper
void toStream(QTextStream& steam) const;
};
#endif // TSVFILE_H