35#include "CSV_Reader.h"
46CSV_Reader::CSV_Reader(): _row_number(0) {
47 _stream_in =
new fstream();
50CSV_Reader::~CSV_Reader() {
52 if (_stream_in->is_open()) {
61CSV_Reader::open(
const string &filepath) {
64 _stream_in->open(filepath.c_str(), fstream::in);
65 if (!(_stream_in->fail()) && _stream_in->is_open()) {
73CSV_Reader::close()
const {
77 if (!(_stream_in->bad()) && !(_stream_in->is_open())) {
85CSV_Reader::eof()
const {
86 return _stream_in->eof();
92 _stream_in->seekg(ios::beg);
97CSV_Reader::get(vector<string> &row) {
104 getline(*_stream_in, line);
108 }
while(!_stream_in->eof() && (line.size() == 0 || line[0] ==
'#'));
116 strm << BESIndent::LMarg <<
"CSV_Reader::dump - ("
117 << (
void *)
this <<
")" << endl;
120 strm << BESIndent::LMarg <<
"File " << _filepath <<
" is open" << endl;
121 strm << BESIndent::LMarg <<
"Current row " << _row_number << endl;
124 strm << BESIndent::LMarg <<
"No stream opened at this time" << endl;
126 BESIndent::UnIndent();
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
static void split(const std::string &str, char delimiter, std::vector< std::string > &tokens)
Splits a string into separate strings based on the delimiter.