Browse code

cleaned up parser

Tom Sherman authored on 25/05/2018 20:06:17
Showing5 changed files

... ...
@@ -199,7 +199,7 @@ static void printTime(const std::string &message, unsigned totalSeconds)
199 199
     int minutes = totalSeconds / 60;
200 200
     totalSeconds -= minutes * 60;
201 201
     int seconds = totalSeconds;
202
-    printf("%s: %02d:%02d:%02d\n", message.c_str(), hours, minutes, seconds);
202
+    Rprintf("%s: %02d:%02d:%02d\n", message.c_str(), hours, minutes, seconds);
203 203
 }
204 204
 
205 205
 // need to call storeSamplerInfo before calling this function
... ...
@@ -70,7 +70,7 @@ RowMatrix::RowMatrix(const std::string &path)
70 70
     while (csv.hasNext())
71 71
     {
72 72
         MatrixElement e(csv.getNext());
73
-        this->operator(e.row, e.col) = e.value;
73
+        this->operator()(e.row, e.col) = e.value;
74 74
     }
75 75
 }
76 76
 
... ...
@@ -1,38 +1,39 @@
1 1
 #include "CsvParser.h"
2 2
 #include "../math/Algorithms.h"
3 3
 
4
+#include <fstream>
4 5
 #include <iostream>
5 6
 
6 7
 // get the number of rows and cols in a csv file
7
-MatrixDimension CsvParser::getDimensions(const std::string &path)
8
+MatrixDimensions CsvParser::getDimensions(const std::string &path)
8 9
 {
9 10
     // initialize struct that holds dimensions
10
-    MatrixDimension dim(0,0);
11
+    MatrixDimensions dim(0,0);
11 12
 
12 13
     // open file stream
13
-    std::ifstream str(path);
14
+    std::ifstream file_str(path.c_str());
14 15
 
15 16
     // read first entry (blank)
16 17
     std::string line;
17
-    std::getline(mFile, line, ',');
18
+    std::getline(file_str, line, ',');
18 19
 
19 20
     // get col size
20 21
     std::size_t pos;
21 22
     do
22 23
     {
23
-        std::getline(mFile, line, ',');
24
+        std::getline(file_str, line, ',');
24 25
         dim.nCol++;
25 26
     }
26 27
     while ((pos = line.find('\n')) == std::string::npos);
27 28
 
28 29
     // get row size
29 30
     dim.nRow++; // acount for current row
30
-    while (mFile.peek() != EOF)
31
+    while (file_str.peek() != EOF)
31 32
     {
32 33
         // throw away data
33 34
         do
34 35
         {
35
-            std::getline(mFile, line, ',');
36
+            std::getline(file_str, line, ',');
36 37
         }
37 38
         while ((pos = line.find('\n')) == std::string::npos);
38 39
 
... ...
@@ -49,7 +50,7 @@ MatrixDimension CsvParser::getDimensions(const std::string &path)
49 50
 // open file, read column names
50 51
 CsvParser::CsvParser(const std::string &path) : mCurrentRow(0), mCurrentCol(0)
51 52
 {
52
-    mFile.open(path);
53
+    mFile.open(path.c_str());
53 54
 }
54 55
 
55 56
 bool CsvParser::hasNext()
... ...
@@ -23,7 +23,7 @@ public:
23 23
     bool hasNext();
24 24
     MatrixElement getNext();
25 25
 
26
-    static MatrixDimension getDimensions(const std::string &path);
26
+    static MatrixDimensions getDimensions(const std::string &path);
27 27
 };
28 28
 
29 29
 #endif
30 30
\ No newline at end of file
... ...
@@ -22,12 +22,12 @@ struct MatrixElement
22 22
     }
23 23
 };
24 24
 
25
-struct MatrixDimension
25
+struct MatrixDimensions
26 26
 {
27 27
     unsigned nRow;
28 28
     unsigned nCol;
29 29
 
30
-    MatrixDimension(unsigned nr, unsigned nc) : nRow(nr), nCol(nc) {}
30
+    MatrixDimensions(unsigned nr, unsigned nc) : nRow(nr), nCol(nc) {}
31 31
 };
32 32
 
33 33
 #endif
34 34
\ No newline at end of file