Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80517591
csv_reader.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 1, 04:19
Size
1 KB
Mime Type
text/x-c
Expires
Tue, Sep 3, 04:19 (2 d)
Engine
blob
Format
Raw Data
Handle
19916142
Attached To
R9484 sp4e-homework-lars-bertil
csv_reader.cc
View Options
#include "csv_reader.hh"
#include "particles_factory_interface.hh"
#include <fstream>
#include <sstream>
/* -------------------------------------------------------------------------- */
CsvReader::CsvReader(const std::string& filename) : filename(filename) {}
/* -------------------------------------------------------------------------- */
void CsvReader::read(System& system) { this->compute(system); }
/* -------------------------------------------------------------------------- */
void CsvReader::compute(System& system) {
std::ifstream is(filename.c_str());
std::string line;
if (is.is_open() == false) {
std::cerr << "cannot open file " << filename << std::endl;
throw;
}
while (is.good()) {
getline(is, line);
if (line[0] == '#' || line.size() == 0)
continue;
auto p = ParticlesFactoryInterface::getInstance().createParticle();
std::stringstream sstr(line);
sstr >> *p;
system.addParticle(std::move(p));
}
is.close();
}
/* -------------------------------------------------------------------------- */
Event Timeline
Log In to Comment