Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90969990
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
Wed, Nov 6, 12:40
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Nov 8, 12:40 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22165717
Attached To
R7571 SP4E-TB-TL-FR
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