data_t.cpp
Go to the documentation of this file.
1 #include "ros_marty/data_t.hpp"
2 
3 //----------------------------------------------------------------------------
4 bool data_t::load( const string& filename ) {
5  string s;
6  ifstream f( filename.c_str() );
7  while (getline( f, s )) {
8  deque <float> record;
9  istringstream iss( s );
10  while (getline( iss, s, ',' )) {
11  float fieldvalue = 0.0f;
12  istringstream( s ) >> fieldvalue;
13  record.push_back( fieldvalue );
14  }
15  this->push_back( record );
16  }
17  return f.good();
18 }
19 
20 //----------------------------------------------------------------------------
21 bool data_t::save( const string& filename ) {
22  ofstream f( filename.c_str() );
23  if (!f) return false;
24 
25  return save( f );
26 }
27 
28 //----------------------------------------------------------------------------
29 bool data_t::save( ostream& outs ) {
30  for (data_t::record_iterator ri = this->begin(); ri != this->end(); ri++) {
31  for (data_t::field_iterator fi = ri->begin(); fi != ri->end(); fi++)
32  outs << ((fi == ri->begin()) ? "" : ", ") << *fi;
33  outs << endl;
34  }
35  return outs.good();
36 }
37 
bool load(const string &filename)
Definition: data_t.cpp:4
deque< deque< float > >::iterator record_iterator
Definition: data_t.hpp:16
bool save(const string &filename)
Definition: data_t.cpp:21
deque< float >::iterator field_iterator
Definition: data_t.hpp:17


ros_marty
Author(s): Alejandro Bordallo
autogenerated on Fri Jul 21 2017 14:51:45