Skip to content
Snippets Groups Projects
Commit ea4d8395 authored by Olivier Stasse's avatar Olivier Stasse
Browse files

Remove contiffstream class

parent 9434feda
No related branches found
No related tags found
No related merge requests found
// -*- 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 <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
{
/// \ingroup debug
///
/// \brief TODO
///
class DG_CONTIIFSTREAM_DLLAPI Contiifstream
{
public:
explicit Contiifstream (const std::string& n = "");
~Contiifstream ();
inline void open (const std::string& n)
{
filename = n;
cursor = 0;
}
bool loop ();
inline bool ready ()
{
return 0 < reader.size ();
}
std::string next ();
protected:
std::string filename;
std::streamoff cursor;
static const unsigned int BUFFER_SIZE = 256;
char buffer[BUFFER_SIZE];
std::list< std::string > reader;
bool first;
};
} // end of namespace dynamicgraph.
#endif //! DYNAMIC_GRAPH_CONTIIFSTREAM_H
// Copyright 2010, Thomas Moulard, JRL, CNRS/AIST
// Copyright 2010-2019, CNRS, JRL, AIST, LAAS
// Thomas Moulard, Olivier Stasse
//
// 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/>.
// See License
#ifndef DYNAMIC_GRAPH_FWD_HH
# define DYNAMIC_GRAPH_FWD_HH
namespace dynamicgraph
{
class Contiifstream;
class DebugTrace;
class PluginRefMap;
......
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software:
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <dynamic-graph/contiifstream.h>
#include <dynamic-graph/debug.h>
namespace dynamicgraph
{
Contiifstream::Contiifstream (const std::string& n)
: filename (n),
cursor (0),
first (true)
{}
Contiifstream::~Contiifstream ()
{
dgDEBUGINOUT(5);
}
bool
Contiifstream::loop ()
{
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
Contiifstream::next ()
{
std::string res = *reader.begin ();
reader.pop_front ();
return res;
}
} // end of namespace dynamicgraph.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment