Helios++
Helios software for LiDAR simulations
DesignMatrixReader.h
1 #ifndef _HELIOS_FILEMS_DESIGN_MATRIX_READER_H_
2 #define _HELIOS_FILEMS_DESIGN_MATRIX_READER_H_
3 
4 #include <filems/read/comps/BufferedLineFileReader.h>
5 
6 #include <vector>
7 #include <unordered_map>
8 
9 namespace fluxionum { template <typename VarType> class DesignMatrix;}
10 
11 namespace helios { namespace filems{
12 
13 using std::vector;
14 using std::unordered_map;
15 
43 template <typename VarType>
45 protected:
46  // *** ATTRIBUTES *** //
47  // ******************** //
55  string sep;
60  string com;
61 
62 public:
63  // *** CONSTRUCTION / DESTRUCTION *** //
64  // ************************************ //
73  string const &path,
74  string const &sep = ",",
75  string const &com = "#",
76  long const maxCharsPerLine = 8192,
77  size_t const bufferSize = 100000
78  ) :
79  br(
80  path, // Path to the input file
81  std::ios_base::in, // Open mode
82  maxCharsPerLine, // Max size per line
83  bufferSize // How many lines
84  ),
85  sep(sep),
86  com(com)
87  {}
88  virtual ~DesignMatrixReader() = default;
89 
90  // *** READING METHODS *** //
91  // ************************* //
99  unordered_map<string, string> *keyval = nullptr
100  );
101 
102 protected:
103  // *** PARSING UTILS *** //
104  // *********************** //
115  virtual void parseComment(
116  string const &str,
117  size_t const comIdx,
118  vector<string> &header,
119  unordered_map<string, string> *keyval
120  );
129  virtual void parseRow(
130  string const &str,
131  size_t const nonEmptyIdx,
132  vector<VarType> &values
133  );
152  virtual bool isSpecComment(string const &str, size_t &colonIdx);
165  string const &str,
166  size_t const comIdx,
167  size_t const colonIdx,
168  string &key,
169  string &val
170  );
178  virtual void parseColumnNames(string const &val, vector<string> &header);
179 
180 };
181 
182 #include <filems/read/core/DesignMatrixReader.tpp>
183 
184 }}
185 
186 
187 #endif
Definition: BufferedLineFileReader.h:9
Class to read design matrices.
Definition: DesignMatrixReader.h:44
virtual void parseComment(string const &str, size_t const comIdx, vector< string > &header, unordered_map< string, string > *keyval)
Parse a comment line.
virtual void parseColumnNames(string const &val, vector< string > &header)
Parse the list of inline column names.
string com
The comment string token . Any line which first non space and non tab substring matches the comment s...
Definition: DesignMatrixReader.h:60
DesignMatrixReader(string const &path, string const &sep=",", string const &com="#", long const maxCharsPerLine=8192, size_t const bufferSize=100000)
Default constructor for DesignMatrixReader.
Definition: DesignMatrixReader.h:72
BufferedLineFileReader br
The buffered line file reader to read the design matrix.
Definition: DesignMatrixReader.h:51
virtual void parseRow(string const &str, size_t const nonEmptyIdx, vector< VarType > &values)
Parse a row.
virtual bool isSpecComment(string const &str, size_t &colonIdx)
Check whether the comment string is a specification comment or not.
string sep
The field separator.
Definition: DesignMatrixReader.h:55
virtual fluxionum::DesignMatrix< VarType > read(unordered_map< string, string > *keyval=nullptr)
Read the design matrix.
virtual void extractSpecCommentKeyValue(string const &str, size_t const comIdx, size_t const colonIdx, string &key, string &val)
Extract the key and value from given string representing a specification comment.