Helios++
Helios software for LiDAR simulations
helios::filems::DesignMatrixReader< VarType > Class Template Reference

Class to read design matrices. More...

#include <DesignMatrixReader.h>

Collaboration diagram for helios::filems::DesignMatrixReader< VarType >:

Public Member Functions

 DesignMatrixReader (string const &path, string const &sep=",", string const &com="#", long const maxCharsPerLine=8192, size_t const bufferSize=100000)
 Default constructor for DesignMatrixReader. More...
 
virtual fluxionum::DesignMatrix< VarType > read (unordered_map< string, string > *keyval=nullptr)
 Read the design matrix. More...
 

Protected Member Functions

virtual void parseComment (string const &str, size_t const comIdx, vector< string > &header, unordered_map< string, string > *keyval)
 Parse a comment line. More...
 
virtual void parseRow (string const &str, size_t const nonEmptyIdx, vector< VarType > &values)
 Parse a row. More...
 
virtual bool isSpecComment (string const &str, size_t &colonIdx)
 Check whether the comment string is a specification comment or not. More...
 
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. More...
 
virtual void parseColumnNames (string const &val, vector< string > &header)
 Parse the list of inline column names. More...
 

Protected Attributes

BufferedLineFileReader br
 The buffered line file reader to read the design matrix.
 
string sep
 The field separator.
 
string com
 The comment string token . Any line which first non space and non tab substring matches the comment string, is a commented line.
 

Detailed Description

template<typename VarType>
class helios::filems::DesignMatrixReader< VarType >

Class to read design matrices.

Author
Alberto M. Esmoris Pena
Version
1.0

A design matrix file is a CSV text file with 2 special type of string tokens. By default the separator token is the comma "," and the default comment token is the "#". Thus, it is possible to have 2 different types of lines.

The first type of line is the comment line. Any line which first non space and non tab substring is a comment token, is a comment line. There are 2 different types of comments. The typical comments, which are simply ignored during parsing and are useful for human understanding purposes only. And the specification comments that can be used to specify some extra information to the parser. Specification comments can be used to specify a header, such that:

#HEADER: "field1","field2","field3"

The second type of line is the data record, data row or data point. It is a line of \(n\) separated fields each such that:

0.5, 1.0, 2.1

Template Parameters
VarTypeThe type of value for the design matrix
See also
fluxionun::DesignMatrix

Constructor & Destructor Documentation

◆ DesignMatrixReader()

template<typename VarType >
helios::filems::DesignMatrixReader< VarType >::DesignMatrixReader ( string const &  path,
string const &  sep = ",",
string const &  com = "#",
long const  maxCharsPerLine = 8192,
size_t const  bufferSize = 100000 
)
inline

Default constructor for DesignMatrixReader.

Parameters
pathPath to the input file containing a Design Matrix
sepThe field separator
maxCharsPerLineMaximum number of characters per line
bufferSizeThe buffer size in number of lines

Member Function Documentation

◆ extractSpecCommentKeyValue()

template<typename VarType >
virtual void helios::filems::DesignMatrixReader< VarType >::extractSpecCommentKeyValue ( string const &  str,
size_t const  comIdx,
size_t const  colonIdx,
string &  key,
string &  val 
)
protectedvirtual

Extract the key and value from given string representing a specification comment.

Parameters
strString representing the specification comment
[in]comIdxThe index of the first character of the comment token in the line
[in]colonIdxThe index of the colon separator between key and value
[out]keyWhere the extracted key will be stored
[out]valWhere the extracted value will be stored

◆ isSpecComment()

template<typename VarType >
virtual bool helios::filems::DesignMatrixReader< VarType >::isSpecComment ( string const &  str,
size_t &  colonIdx 
)
protectedvirtual

Check whether the comment string is a specification comment or not.

The method assumes the string is in fact a comment, so it must be to work properly. It only checks whether it is a typical comment or a specification comment

Parameters
strThe comment line being parsed. It MUST be a comment line. The method assumes it is a comment line and only checks whether it is a specification comment or not
[out]colonIdxThe index of the colon separator will be stored here. When it is a specification comment it will be distinct than string::npos (true), otherwise it will be exactly string::npos (false)
Returns
True if the string is a specification comment, false if the string is a typical comment

◆ parseColumnNames()

template<typename VarType >
virtual void helios::filems::DesignMatrixReader< VarType >::parseColumnNames ( string const &  val,
vector< string > &  header 
)
protectedvirtual

Parse the list of inline column names.

Parameters
valInline list of column names. Each name must be separated by the separator character DesignMatrixReader::sep
[out]headerWhere the column names are stored
See also
DesignMatrixReader::sep

◆ parseComment()

template<typename VarType >
virtual void helios::filems::DesignMatrixReader< VarType >::parseComment ( string const &  str,
size_t const  comIdx,
vector< string > &  header,
unordered_map< string, string > *  keyval 
)
protectedvirtual

Parse a comment line.

Parameters
strThe line being parsed
comIdxThe index of the first character of the comment token in the line
[out]headerThe vector of column names defining the header.
[out]keyvalIf it is not null, then it will be used to store all key value pairs from specification comments (unless the header) If the parsed comment is a header specification, then it will be filled

◆ parseRow()

template<typename VarType >
virtual void helios::filems::DesignMatrixReader< VarType >::parseRow ( string const &  str,
size_t const  nonEmptyIdx,
vector< VarType > &  values 
)
protectedvirtual

Parse a row.

Parameters
strThe line being parsed
nonEmptyIdxThe index of the first non empty character in the line
[out]valuesThe vector of values defining the contents of the DesignMatrix

◆ read()

template<typename VarType >
virtual fluxionum::DesignMatrix<VarType> helios::filems::DesignMatrixReader< VarType >::read ( unordered_map< string, string > *  keyval = nullptr)
virtual

Read the design matrix.

Parameters
[out]keyvalIf it is not null, then it will be used to store all key value pairs from specification comments (unless the header)
Returns
Built design matrix

The documentation for this class was generated from the following file: