Browse code

added file parser folder

Tom Sherman authored on 24/05/2018 20:06:18
Showing 5 changed files

... ...
@@ -1,7 +1,5 @@
1 1
 #include "Matrix.h"
2 2
 
3
-/******************************** HELPER *******************************/
4
-
5 3
 template<class GenericMatrix>
6 4
 static Rcpp::NumericMatrix convertToRMatrix(const GenericMatrix &mat)
7 5
 {
... ...
@@ -52,6 +50,11 @@ RowMatrix::RowMatrix(const Rcpp::NumericMatrix &rmat)
52 50
     }
53 51
 }
54 52
 
53
+RowMatrix::RowMatrix(const std::string &path)
54
+{
55
+
56
+}
57
+
55 58
 void RowMatrix::operator=(const RowMatrix &mat)
56 59
 {
57 60
     copyMatrix(*this, mat);
... ...
@@ -119,6 +122,11 @@ ColMatrix::ColMatrix(const Rcpp::NumericMatrix &rmat)
119 122
     }
120 123
 }
121 124
 
125
+ColMatrix::ColMatrix(const std::string &path)
126
+{
127
+
128
+}
129
+
122 130
 ColMatrix ColMatrix::operator/(float val) const
123 131
 {
124 132
     ColMatrix mat(mNumRows, mNumCols);
125 133
new file mode 100644
... ...
@@ -0,0 +1,42 @@
1
+#include "CsvParser.h"
2
+
3
+// open file, read column names
4
+CsvParser::CsvParser(const std::string &path)
5
+{
6
+    mFile.open(path);
7
+
8
+    std::string line;
9
+    std::getline(mFile, line); // read first entry (blank)
10
+    
11
+    while (!std::isdigit(mFile.peek()))
12
+    {
13
+        std::getline(mFile, line)
14
+        mColNames.push_back(line);
15
+    }
16
+    mRowNames.push_back(mColNames.back());
17
+    mColNames.pop_back(); // read one too far
18
+}
19
+
20
+bool CsvParser::hasNext() const
21
+{
22
+    return mFile.peek() != EOF;
23
+}
24
+
25
+MatrixElement CsvParser::getNext() const
26
+{
27
+    int c = mFile.peek();
28
+    
29
+    std::string line;
30
+    std::getline(mFile, line);
31
+    if (std::isdigit(c)) // matrix element
32
+    {
33
+        Rcout << line << '\n';
34
+        return MatrixElement(0,0,0.f);
35
+    }
36
+    else // row name
37
+    {
38
+        mRowNames.push_back(line);
39
+        return getNext();
40
+    }
41
+}
42
+ 
0 43
\ No newline at end of file
1 44
new file mode 100644
... ...
@@ -0,0 +1,24 @@
1
+#ifndef __COGAPS_CSV_PARSER_H__
2
+#define __COGAPS_CSV_PARSER_H__
3
+
4
+class CsvParser
5
+{
6
+private:
7
+
8
+    std::ifstream mFile;
9
+
10
+    std::vector<std::string> mRowNames;
11
+    std::vector<std::string> mColNames;
12
+
13
+    unsigned mCurrentRow;
14
+    unsigned mCurrentCol;
15
+
16
+public:
17
+
18
+    CsvParser(const std::string &path);
19
+
20
+    bool hasNext() const;
21
+    MatrixElement getNext() const; 
22
+};
23
+
24
+#endif
0 25
\ No newline at end of file
1 26
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+#ifndef __COGAPS_MTX_PARSER_H__
2
+#define __COGAPS_MTX_PARSER_H__
3
+
4
+
5
+#endif
0 6
\ No newline at end of file
1 7
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+#ifndef __COGAPS_TSV_PARSER_H__
2
+#define __COGAPS_TSV_PARSER_H__
3
+
4
+
5
+#endif
0 6
\ No newline at end of file