Helios++
Helios software for LiDAR simulations
AbstractDesignMatrix.h
1 #pragma once
2 
3 #include <fluxionum/FluxionumException.h>
4 
5 #include <vector>
6 #include <string>
7 #include <sstream>
8 
9 namespace fluxionum{
10 
11 using std::vector;
12 using std::string;
13 
25 template <typename T>
27 protected:
28  // *** ATTRIBUTES *** //
29  // ******************** //
35  vector<string> columnNames;
36 
37 public:
38  // *** CONSTRUCTION / DESTRUCTION *** //
39  // ************************************ //
46  vector<string> const &columnNames=vector<string>(0)
47  ) :
49  {}
50  virtual ~AbstractDesignMatrix() = default;
51 
52 
53 protected:
54  // *** INNER UTILS *** //
55  // ********************* //
62  inline size_t translateColumnNameToIndex(string const &columnName) const{
63  for(string const &name : columnNames){
64  if(name == columnName) return true;
65  }
66  std::stringstream ss;
67  ss << "AbstractDesignMatrix::translateColumnNameToIndex failed to "
68  << "find a column with name: \"" << columnName << "\"";
69  throw FluxionumException(ss.str());
70  }
71 
72 
73 public:
74  // *** OPERATORS *** //
75  // ******************* //
84  virtual T& operator() (size_t const i, size_t const j) = 0;
92  inline T& operator() (size_t const i, string const columnName)
93  {return operator()(i, translateColumnNameToIndex(columnName));}
94 
95 
96  // *** GETTERs and SETTERs *** //
97  // ***************************** //
104  inline bool hasColumnNames() const {return !columnNames.empty();}
111  inline string const& getColumnName(size_t const j) const
112  {return columnNames[j];}
119  inline void setColumnName(size_t const j, string const &columnName)
120  {columnNames[j] = columnName;}
126  inline vector<string> const& getColumnNames() const {return columnNames;}
132  inline void setColumnNames(vector<string> const& columnNames)
133  {this->columnNames = columnNames;}
138  virtual inline size_t getNumRows() const = 0;
143  virtual inline size_t getNumColumns() const = 0;
148  virtual inline size_t getNumElements() const = 0;
149 };
150 
151 }
The abstract class which represents the fundamentals of any design matrix.
Definition: AbstractDesignMatrix.h:26
string const & getColumnName(size_t const j) const
Obtain the name of the -th column.
Definition: AbstractDesignMatrix.h:111
virtual T & operator()(size_t const i, size_t const j)=0
Access operator for the element at -th row and -th column of the AbstractDesignMatrix.
AbstractDesignMatrix(vector< string > const &columnNames=vector< string >(0))
Default constructor for the AbstractDesignMatrix.
Definition: AbstractDesignMatrix.h:45
virtual size_t getNumElements() const =0
Obtain the number of elements of the AbstractDesignMatrix.
void setColumnName(size_t const j, string const &columnName)
Set the name of the -th column.
Definition: AbstractDesignMatrix.h:119
vector< string > columnNames
The column names for the DesignMatrix. It can be either an empty vector when no column names are spec...
Definition: AbstractDesignMatrix.h:35
virtual size_t getNumColumns() const =0
Obtain the number of columns of the AbstractDesignMatrix.
void setColumnNames(vector< string > const &columnNames)
Obtain a constant/read reference to the column names.
Definition: AbstractDesignMatrix.h:132
virtual size_t getNumRows() const =0
Obtain the number of rows of the AbstractDesignMatrix.
bool hasColumnNames() const
Check whether there are available column names for the AbstractDesignMatrix (true) or not (false)
Definition: AbstractDesignMatrix.h:104
size_t translateColumnNameToIndex(string const &columnName) const
Find the corresponding column name for given index.
Definition: AbstractDesignMatrix.h:62
vector< string > const & getColumnNames() const
Obtain a constant/read reference to the column names.
Definition: AbstractDesignMatrix.h:126
Base class for fluxionum exceptions.
Definition: FluxionumException.h:16