-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathTextMatrix.h
61 lines (51 loc) · 1.74 KB
/
TextMatrix.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
#ifndef TEXTMATRIX_H
#define TEXTMATRIX_H
#include <string>
#include <vector>
class SimpleMatrix;
class TextMatrix {
public:
enum ReadOption { HAS_NONE = 0, HAS_HEADER = 1, HAS_ROWNAME = 2 };
enum WriteOption { OUTPUT_NONE = 0, OUTPUT_HEADER = 1, OUTPUT_ROWNAME = 2 };
public:
/**
* read in a text file
* @param fn the input file name
* @param flag bit masked flags, e.g. HAS_HEADER, HAS_ROWNAME
*/
int readFile(const std::string& fn, int flag = HAS_NONE);
int writeFile(const std::string& fn, int flag = OUTPUT_NONE) const;
std::vector<std::string>& operator[](int i) { return mat[i]; }
const std::vector<std::string> header() const;
void clear() {
mat.clear();
rowName.clear();
colName.clear();
}
int nrow() const { return mat.size(); };
int ncol() const {
if (mat.size() == 0) return 0;
return mat[0].size();
}
const std::vector<std::string>& getRowName() const { return this->rowName; };
const std::vector<std::string>& getColName() const { return this->colName; };
/**
* Only keep the columns whose names are in @param colName
*/
int keepCol(const std::vector<std::string>& colName);
int setRowNameByCol(const std::string& name);
/**
* Convert to SimpleMatrix @param m
* For non-numeric values, a NAN value will be used.
*/
int convert(SimpleMatrix* m) const;
void extractCol(int col, std::vector<std::string>* v) const;
std::vector<std::string> extractCol(int col) const;
void extractCol(const std::string& col, std::vector<std::string>* v) const;
std::vector<std::string> extractCol(const std::string& col) const;
private:
std::vector<std::string> rowName;
std::vector<std::string> colName;
std::vector<std::vector<std::string> > mat;
};
#endif /* TEXTMATRIX_H */