LDMX Software
GeneralCSVLoader.h
1
5#ifndef CONDITIONS_GENERALCSVLOADER_H_
6#define CONDITIONS_GENERALCSVLOADER_H_
7
8#include <istream>
9#include <string>
10#include <vector>
11
12namespace conditions {
13
20 public:
22 virtual ~GeneralCSVLoader() {}
23
25 std::vector<std::string> columnNames() const { return colNames_; }
26
28 bool nextRow();
29
31 const std::string& get(const std::string& colname,
32 bool ignore_case = true) const;
33
35 int getInteger(const std::string& colname, bool ignore_case = true) const;
36
37 protected:
39
42 virtual std::string getNextLine() = 0;
43
44 private:
48 std::vector<std::string> colNames_;
52 std::vector<std::string> rowData_;
53};
54
58 public:
60 StringCSVLoader(const std::string& source,
61 const std::string lineseparators = "\n");
62
63 protected:
66 virtual std::string getNextLine();
67
68 private:
72 const std::string& source_;
76 const std::string linesep_;
80 std::string::size_type rowBegin_, rowEnd_;
81};
82
86 public:
93 StreamCSVLoader(const std::string& filename);
100 StreamCSVLoader(std::istream& stream);
101
103 virtual ~StreamCSVLoader();
104
105 protected:
108 virtual std::string getNextLine();
109
110 private:
114 std::istream* source_;
122 std::string line_;
123};
124
125} // namespace conditions
126#endif // CONDITIONS_GENERALCSVLOADER_H_
Class which parses a CSV file and provides the rows one at a time to a user The parser ignores any li...
bool nextRow()
Advance to next row if possible.
const std::string & get(const std::string &colname, bool ignore_case=true) const
Get the value for the given column in the current row.
int getInteger(const std::string &colname, bool ignore_case=true) const
Get the value for the given column in the current row as an integer.
virtual std::string getNextLine()=0
Get the next line, returning an empty string when there is no further data.
virtual ~GeneralCSVLoader()
Destructor.
std::vector< std::string > columnNames() const
Get the column names.
std::vector< std::string > rowData_
The row data.
std::vector< std::string > colNames_
The column names.
Specialization of the GeneralCSVLoader for loading from a file/stream.
virtual ~StreamCSVLoader()
Clean-up the stream if we own it.
virtual std::string getNextLine()
Get the next line, returning an empty string when there is no further data.
std::string line_
Line buffer.
std::istream * source_
The stream.
Specialization of the GeneralCSVLoader for loading from a string.
const std::string & source_
The original string.
std::string::size_type rowBegin_
The current start and end pointers.
const std::string linesep_
The separators.
virtual std::string getNextLine()
Get the next line, returning an empty string when there is no further data.