Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91898559
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
Fri, Nov 15, 13:59
Size
1 KB
Mime Type
text/x-c
Expires
Sun, Nov 17, 13:59 (2 d)
Engine
blob
Format
Raw Data
Handle
22343672
Attached To
R9490 Homework_sp4e_Peruzzo_SáezUribe
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