diff --git a/eo/src/utils/CMakeLists.txt b/eo/src/utils/CMakeLists.txt index ea36d4bb..ec70053b 100644 --- a/eo/src/utils/CMakeLists.txt +++ b/eo/src/utils/CMakeLists.txt @@ -22,7 +22,7 @@ SET (EOUTILS_SOURCES eoData.cpp eoRealBounds.cpp eoRNG.cpp eoState.cpp - eoStdoutMonitor.cpp + eoOStreamMonitor.cpp eoUpdater.cpp make_help.cpp pipecom.cpp diff --git a/eo/src/utils/checkpointing b/eo/src/utils/checkpointing index e2b7ce42..dea1432c 100644 --- a/eo/src/utils/checkpointing +++ b/eo/src/utils/checkpointing @@ -4,6 +4,7 @@ #include #include #include +#include #ifndef _MSC_VER #include #include diff --git a/eo/src/utils/eoStdoutMonitor.cpp b/eo/src/utils/eoOStreamMonitor.cpp similarity index 51% rename from eo/src/utils/eoStdoutMonitor.cpp rename to eo/src/utils/eoOStreamMonitor.cpp index 622a2743..817d9ab2 100644 --- a/eo/src/utils/eoStdoutMonitor.cpp +++ b/eo/src/utils/eoOStreamMonitor.cpp @@ -6,31 +6,34 @@ #include #include #include +#include +#include -#include +#include #include #include #include -using namespace std; +//using namespace std; -eoMonitor& eoStdoutMonitor::operator()(void) +eoMonitor& eoOStreamMonitor::operator()(void) { - if (!cout) { - string str = "eoStdoutMonitor: Could not write to cout"; - throw runtime_error (str); + if (!out) { + std::string str = "eoOStreamMonitor: Could not write to the ooutput stream"; + throw std::runtime_error(str); } if (firsttime) { if (verbose) { - eo::log << eo::progress << "First Generation" << endl; + eo::log << eo::progress << "First Generation" << std::endl; } else { // else verbose for (iterator it = vec.begin (); it != vec.end (); ++it) { - cout << (*it)->longName () << delim; + out << (*it)->longName (); + out << delim << std::left << std::setfill(fill) << std::setw(width); } - cout << endl; + out << std::endl; } // else verbose firsttime = false; @@ -40,18 +43,19 @@ eoMonitor& eoStdoutMonitor::operator()(void) if (verbose) { for (iterator it = vec.begin (); it != vec.end (); ++it) { // name: value - cout << (*it)->longName () << ": " << (*it)->getValue () << endl; + out << (*it)->longName () << ": " << (*it)->getValue () << std::endl; } // for it in vec - eo::log << eo::progress << "End of Generation" << endl; + eo::log << eo::progress << "End of Generation" << std::endl; } else { // else verbose for (iterator it = vec.begin (); it != vec.end (); ++it) { // value only - cout << (*it)->getValue () << delim; + out << (*it)->getValue (); + out << delim << std::left << std::setfill(fill) << std::setw(width); } // for it in vec - cout << endl; + out << std::endl; } // if verbose return *this; diff --git a/eo/src/utils/eoOStreamMonitor.h b/eo/src/utils/eoOStreamMonitor.h new file mode 100644 index 00000000..d9658804 --- /dev/null +++ b/eo/src/utils/eoOStreamMonitor.h @@ -0,0 +1,62 @@ + +/* + +(c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 +(c) Thales group, 2010 + + This library 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; version 2 of the license. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., 59 + Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Contact: http://eodev.sourceforge.net + +Authors: + todos@geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo +*/ + + + +#ifndef _eoOStreamMonitor_h_ +#define _eoOStreamMonitor_h_ + +#include +#include + +#include +#include + +/** + Prints statistics to stdout +*/ +class eoOStreamMonitor : public eoMonitor +{ +public : + eoOStreamMonitor( std::ostream & _out, bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : + out(_out), verbose(_verbose), delim(_delim), width(_width), fill(_fill), firsttime(true) {} + + eoMonitor& operator()(void); + + virtual std::string className(void) const { return "eoOStreamMonitor"; } + +private : + std::ostream & out; + bool verbose; + std::string delim; + unsigned int width; + char fill; + bool firsttime; +}; + +#endif // _eoOStreamMonitor_h_ + diff --git a/eo/src/utils/eoStdoutMonitor.h b/eo/src/utils/eoStdoutMonitor.h index 43335a57..4a2083ab 100644 --- a/eo/src/utils/eoStdoutMonitor.h +++ b/eo/src/utils/eoStdoutMonitor.h @@ -1,9 +1,8 @@ // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- -//----------------------------------------------------------------------------- -// eoStdoutMonitor.h -// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 /* +(c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 +(c) Thales group, 2010 This library 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 @@ -18,35 +17,34 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- + +Contact: http://eodev.sourceforge.net + +Authors: + todos@geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + Johann Dréo +*/ #ifndef _eoStdoutMonitor_h #define _eoStdoutMonitor_h #include -#include +#include #include /** Prints statistics to stdout */ -class eoStdoutMonitor : public eoMonitor +class eoStdoutMonitor : public eoOStreamMonitor { public : - eoStdoutMonitor(bool _verbose=true, std::string _delim = "\t") : - verbose(_verbose), delim(_delim), firsttime(true) {} - eoMonitor& operator()(void); + eoStdoutMonitor(bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) : + eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill) {} - virtual std::string className(void) const { return "eoStdoutMonitor"; } -private : - bool verbose; - std::string delim; - bool firsttime; + virtual std::string className(void) const { return "eoStdoutMonitor"; } }; #endif