Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80367950
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
Sat, Aug 31, 09:15
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Sep 2, 09:15 (2 d)
Engine
blob
Format
Raw Data
Handle
19916142
Attached To
R7554 sp4e_exercices
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