contiifstream.cpp 1.33 KB
Newer Older
1
2
3
4
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
5
6
 * File:      Contiifstream.cpp
 * Project:   DYNAMIC-GRAPH
7
8
9
10
11
12
13
14
15
16
17
18
19
 * Author:    Nicolas Mansard
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

20
21
#include <dynamic-graph/contiifstream.h>
#include <dynamic-graph/debug.h>
22

23
24
using namespace dynamicgraph;

25
26
Contiifstream::
Contiifstream( const std::string& n )
27
28
29
  :filename(n),cursor(0),first(true) {}


30
31
Contiifstream::
~Contiifstream( void )
32
33
34
35
36
{
  dgDEBUGINOUT(5);
}


37
bool Contiifstream::
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
loop( void )
{
  dgDEBUGIN(25);
  bool res=false;
  
  std::fstream file( filename.c_str() );

  file.seekg(cursor);
  file.sync();
      
  while(1)
    {
      file.get(buffer,BUFFER_SIZE);
      if( file.gcount() ) 
	{ 
	  res=true;
	  std::string line(buffer);
	  if(! first) reader.push_back(line);
	  cursor=file.tellg(); cursor++;
	  file.get(*buffer); // get the last char ( = '\n')
	  dgDEBUG(15) << "line: "<< line<<std::endl;
	}
      else { break; }
    }

  first=false;
  dgDEBUGOUT(25);
  return res;
}

std::string 
69
Contiifstream::next( void ) 
70
71
72
73
74
75
76
77
78
79
{
  std::string res = *reader.begin();
  reader.pop_front();
  return res;
}