create a more generic class for monitoring to any ostream (useful for output to clog or cerr, for example), the stdout monitor now inherits from it
This commit is contained in:
parent
47c4f58eb8
commit
4a90420dd3
5 changed files with 98 additions and 33 deletions
|
|
@ -22,7 +22,7 @@ SET (EOUTILS_SOURCES eoData.cpp
|
||||||
eoRealBounds.cpp
|
eoRealBounds.cpp
|
||||||
eoRNG.cpp
|
eoRNG.cpp
|
||||||
eoState.cpp
|
eoState.cpp
|
||||||
eoStdoutMonitor.cpp
|
eoOStreamMonitor.cpp
|
||||||
eoUpdater.cpp
|
eoUpdater.cpp
|
||||||
make_help.cpp
|
make_help.cpp
|
||||||
pipecom.cpp
|
pipecom.cpp
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <utils/eoMonitor.h>
|
#include <utils/eoMonitor.h>
|
||||||
#include <utils/eoFileMonitor.h>
|
#include <utils/eoFileMonitor.h>
|
||||||
#include <utils/eoStdoutMonitor.h>
|
#include <utils/eoStdoutMonitor.h>
|
||||||
|
#include <utils/eoOStreamMonitor.h>
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#include <utils/eoGnuplot1DMonitor.h>
|
#include <utils/eoGnuplot1DMonitor.h>
|
||||||
#include <utils/eoGnuplot1DSnapshot.h>
|
#include <utils/eoGnuplot1DSnapshot.h>
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,34 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ios>
|
||||||
|
|
||||||
#include <utils/eoStdoutMonitor.h>
|
#include <utils/eoOStreamMonitor.h>
|
||||||
#include <utils/compatibility.h>
|
#include <utils/compatibility.h>
|
||||||
#include <utils/eoParam.h>
|
#include <utils/eoParam.h>
|
||||||
#include <eoLogger.h>
|
#include <eoLogger.h>
|
||||||
|
|
||||||
using namespace std;
|
//using namespace std;
|
||||||
|
|
||||||
eoMonitor& eoStdoutMonitor::operator()(void)
|
eoMonitor& eoOStreamMonitor::operator()(void)
|
||||||
{
|
{
|
||||||
if (!cout) {
|
if (!out) {
|
||||||
string str = "eoStdoutMonitor: Could not write to cout";
|
std::string str = "eoOStreamMonitor: Could not write to the ooutput stream";
|
||||||
throw runtime_error (str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firsttime) {
|
if (firsttime) {
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
eo::log << eo::progress << "First Generation" << endl;
|
eo::log << eo::progress << "First Generation" << std::endl;
|
||||||
|
|
||||||
} else { // else verbose
|
} else { // else verbose
|
||||||
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
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
|
} // else verbose
|
||||||
|
|
||||||
firsttime = false;
|
firsttime = false;
|
||||||
|
|
@ -40,18 +43,19 @@ eoMonitor& eoStdoutMonitor::operator()(void)
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
||||||
// name: value
|
// name: value
|
||||||
cout << (*it)->longName () << ": " << (*it)->getValue () << endl;
|
out << (*it)->longName () << ": " << (*it)->getValue () << std::endl;
|
||||||
} // for it in vec
|
} // for it in vec
|
||||||
|
|
||||||
eo::log << eo::progress << "End of Generation" << endl;
|
eo::log << eo::progress << "End of Generation" << std::endl;
|
||||||
|
|
||||||
} else { // else verbose
|
} else { // else verbose
|
||||||
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
for (iterator it = vec.begin (); it != vec.end (); ++it) {
|
||||||
// value only
|
// value only
|
||||||
cout << (*it)->getValue () << delim;
|
out << (*it)->getValue ();
|
||||||
|
out << delim << std::left << std::setfill(fill) << std::setw(width);
|
||||||
} // for it in vec
|
} // for it in vec
|
||||||
|
|
||||||
cout << endl;
|
out << std::endl;
|
||||||
} // if verbose
|
} // if verbose
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
62
eo/src/utils/eoOStreamMonitor.h
Normal file
62
eo/src/utils/eoOStreamMonitor.h
Normal file
|
|
@ -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 <johann.dreo@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _eoOStreamMonitor_h_
|
||||||
|
#define _eoOStreamMonitor_h_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <utils/eoMonitor.h>
|
||||||
|
#include <eoObject.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
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_
|
||||||
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- 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
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
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
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
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
|
Contact: http://eodev.sourceforge.net
|
||||||
mkeijzer@dhi.dk
|
|
||||||
*/
|
Authors:
|
||||||
//-----------------------------------------------------------------------------
|
todos@geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
|
mkeijzer@dhi.dk
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _eoStdoutMonitor_h
|
#ifndef _eoStdoutMonitor_h
|
||||||
#define _eoStdoutMonitor_h
|
#define _eoStdoutMonitor_h
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <utils/eoMonitor.h>
|
#include <utils/eoOStreamMonitor.h>
|
||||||
#include <eoObject.h>
|
#include <eoObject.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Prints statistics to stdout
|
Prints statistics to stdout
|
||||||
*/
|
*/
|
||||||
class eoStdoutMonitor : public eoMonitor
|
class eoStdoutMonitor : public eoOStreamMonitor
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
eoStdoutMonitor(bool _verbose=true, std::string _delim = "\t") :
|
eoStdoutMonitor(bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
|
||||||
verbose(_verbose), delim(_delim), firsttime(true) {}
|
eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill) {}
|
||||||
eoMonitor& operator()(void);
|
|
||||||
|
|
||||||
virtual std::string className(void) const { return "eoStdoutMonitor"; }
|
virtual std::string className(void) const { return "eoStdoutMonitor"; }
|
||||||
private :
|
|
||||||
bool verbose;
|
|
||||||
std::string delim;
|
|
||||||
bool firsttime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue