contiifstream.h 1.79 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Lesser Public License for more details.  You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.

#ifndef DYNAMIC_GRAPH_CONTIIFSTREAM_H
# define DYNAMIC_GRAPH_CONTIIFSTREAM_H
# include <fstream>
# include <iostream>
# include <list>
# include <sstream>

# ifndef WIN32
#  include <unistd.h>
#  include <pthread.h>
# endif //! WIN32

# include <dynamic-graph/fwd.hh>
# include <dynamic-graph/interpreter.h>
# include <dynamic-graph/config-contiifstream.hh>

namespace dynamicgraph
{
  class DG_CONTIIFSTREAM_DLLAPI Contiifstream
  {
  public:
    explicit Contiifstream (const std::string& n="");
    ~Contiifstream  ();
41

Thomas Moulard's avatar
Thomas Moulard committed
42
43
44
45
46
    inline void open (const std::string& n)
    {
      filename=n;
      cursor=0;
    }
47

Thomas Moulard's avatar
Thomas Moulard committed
48
    bool loop ();
49

Thomas Moulard's avatar
Thomas Moulard committed
50
51
52
53
    inline bool ready ()
    {
      return 0 < reader.size  ();
    }
54

Thomas Moulard's avatar
Thomas Moulard committed
55
    std::string next  ();
56

florent's avatar
florent committed
57
58
  protected:
    std::string filename;
Thomas Moulard's avatar
Thomas Moulard committed
59
    std::streamoff cursor;
florent's avatar
florent committed
60
61
62
63
64
    static const unsigned int BUFFER_SIZE = 256;
    char buffer[BUFFER_SIZE];
    std::list< std::string > reader;
    bool first;
  };
Thomas Moulard's avatar
Thomas Moulard committed
65
} // end of namespace dynamicgraph.
66

Thomas Moulard's avatar
Thomas Moulard committed
67
#endif //! DYNAMIC_GRAPH_CONTIIFSTREAM_H