https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MixedDataDelimitedFileReader.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "DelimitedFileReader.h"
13
14namespace MooseUtils
15{
16
29{
30public:
31 MixedDataDelimitedFileReader(const std::string & filename) : DelimitedFileOfStringReader(filename)
32 {
33 }
34
35 MixedDataDelimitedFileReader(const std::string & filename,
37 : DelimitedFileOfStringReader(filename, comm)
38 {
39 }
40
53 template <typename T>
54 const std::vector<T> getData(const std::string & name) const
55 {
56 return convertVector<T>(DelimitedFileOfStringReader::getData(name));
57 }
58
71 template <typename T>
72 const std::vector<T> getData(std::size_t index_column) const
73 {
74 return convertVector<T>(DelimitedFileOfStringReader::getData(index_column));
75 }
76
77protected:
90 template <typename T>
91 std::vector<T> convertVector(const std::vector<std::string> & column) const
92 {
93 auto converted_data = std::vector<T>(column.size());
94 for (size_t index_row = 0; index_row < column.size(); ++index_row)
95 {
96 convert<T>(column[index_row], converted_data[index_row], true);
97 }
98 return converted_data;
99 }
100};
101}
Utility class for reading delimited data (e.g., CSV data).
const std::vector< std::vector< T > > & getData() const
Return the rows/columns of data.
Utility class for reading delimited data (e.g., CSV data).
std::vector< T > convertVector(const std::vector< std::string > &column) const
Given a column of a data set this will convert it to a vector of the requested type.
const std::vector< T > getData(const std::string &name) const
Converts a specific named column in the data set to a vector of a specified type.
const std::vector< T > getData(std::size_t index_column) const
Converts a column in the data set to a vector of a specified type.
MixedDataDelimitedFileReader(const std::string &filename, const libMesh::Parallel::Communicator *comm)