1 #ifndef GENESIS_UTILS_CONTAINERS_MATRIX_READER_H_
2 #define GENESIS_UTILS_CONTAINERS_MATRIX_READER_H_
95 return skip_first_col_;
100 return skip_first_row_;
105 skip_first_col_ = value;
111 skip_first_row_ = value;
127 parse_value_ = functor;
139 std::vector<T> table;
143 if( ! input_stream ) {
148 if( skip_first_row_ ) {
152 while( input_stream ) {
153 auto const line = reader_.
parse_line( input_stream );
157 auto len = line.size();
158 if( len > 0 && skip_first_col_ ) {
175 }
else if( cols != len ) {
176 throw std::runtime_error(
"Matrix has different line lengths." );
181 for(
size_t i = first; i < line.size(); ++i ) {
182 table.push_back( parse_value_( line[i] ) );
185 for(
size_t i = first; i < line.size(); ++i ) {
186 table.push_back( parse_value_stringstream_( line[i] ) );
192 if( table.size() == 0 ) {
198 if( table.size() % cols != 0 ) {
201 throw std::runtime_error(
"Matrix is not rectangluar." );
205 size_t const rows = table.size() / cols;
206 return Matrix<T>( rows, cols, std::move(table) );
209 inline T parse_value_stringstream_( std::string
const& cell )
const
211 std::stringstream ss( cell );
223 bool skip_first_row_ =
false;
224 bool skip_first_col_ =
false;
228 std::function<T( std::string
const& )> parse_value_;
235 #endif // include guard