Merge branch 'master' of ssh://eodev.git.sourceforge.net/gitroot/eodev/eodev

This commit is contained in:
nojhan 2012-07-06 18:25:15 +02:00
commit 07fede786f
36 changed files with 564 additions and 468 deletions

View file

@ -29,6 +29,7 @@ SET(EOUTILS_SOURCES
pipecom.cpp
eoLogger.cpp
eoParallel.cpp
eoSignal.cpp
)
ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES})

View file

@ -1,3 +1,29 @@
/*
-----------------------------------------------------------------------------
checkpointing
(c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 2000
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
version 2 of the License, or (at your option) any later version.
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: todos@geneura.ugr.es, http://geneura.ugr.es
*/
#ifndef _CHECKPOINTING_
#define _CHECKPOINTING_
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include <utils/eoUpdater.h>
@ -10,6 +36,7 @@
#include <utils/eoGnuplot1DSnapshot.h>
#endif
#include <utils/eoCheckPoint.h>
#include <utils/eoSignal.h>
#include <utils/eoStat.h>
#include <utils/eoScalarFitnessStat.h>
#include <utils/eoAssembledFitnessStat.h>
@ -21,3 +48,9 @@
// and make_help - any better suggestion to include it?
void make_help(eoParser & _parser);
#endif // !_CHECKPOINTING_
// Local Variables:
// mode: C++
// End:

View file

@ -4,6 +4,8 @@
#include <eoFunctorStore.h>
#include <utils/eoStat.h>
/** Wrapper to turn any stand-alone function and into an eoStat.
*
* The function should take an eoPop as argument.
@ -41,4 +43,38 @@ eoFuncPtrStat<EOT, T>& makeFuncPtrStat( T (*func)(const eoPop<EOT>&), eoFunctorS
);
}
/** Wrapper to turn any stand-alone function and into an eoStat.
*
* The function should take an eoPop as argument.
*
* @ingroup Stats
*/
template <class EOT, class T>
class eoFunctorStat : public eoStat<EOT, T>
{
public :
eoFunctorStat(eoUF< const eoPop<EOT>&, T >& f, std::string _description = "functor")
: eoStat<EOT, T>(T(), _description), func(f)
{}
using eoStat<EOT, T>::value;
void operator()(const eoPop<EOT>& pop) {
value() = func(pop);
}
private:
eoUF< const eoPop<EOT>&, T >& func;
};
/**
* @ingroup Stats
*/
template <class EOT, class T>
eoFunctorStat<EOT, T>& makeFunctorStat( eoUF< const eoPop<EOT>&, T >& func, eoFunctorStore& store, std::string description = "func") {
return store.storeFunctor(
new eoFunctorStat<EOT, T>( func, description)
);
}
#endif

View file

@ -194,8 +194,7 @@ int eoLogger::outbuf::overflow(int_type c)
{
if (_fd >= 0 && c != EOF)
{
size_t num;
num = ::write(_fd, &c, 1);
::write(_fd, &c, 1);
}
}
return c;

View file

@ -44,12 +44,13 @@ Authors:
class eoOStreamMonitor : public eoMonitor
{
public :
eoOStreamMonitor( std::ostream & _out, bool _verbose=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
eoOStreamMonitor( std::ostream & _out, bool /*_verbose*/=true, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
out(_out), delim(_delim), width(_width), fill(_fill), firsttime(true)
{
(void)_verbose;
#ifndef DEPRECATED_MESSAGES
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release" << std::endl;
#pragma message "WARNING: the use of the verbose parameter in eoOStreamMonitor constructor is deprecated and will be removed in the next release"
#endif // !DEPRECATED_MESSAGES
}
eoOStreamMonitor( std::ostream & _out, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :

36
eo/src/utils/eoSignal.cpp Normal file
View file

@ -0,0 +1,36 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
/**
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
version 2 of the License, or (at your option) any later version.
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
Autors: todos@geneura.ugr.es, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mak@dhi.dk
Caner.Candan@univ-angers.fr
*/
#include <utils/eoSignal.h>
/**
* @addtogroup Continuators
* @{
*/
// --- Global variables - but don't know what else to do - MS ---
std::map< int, bool > signals_called;
/** @} */

106
eo/src/utils/eoSignal.h Normal file
View file

@ -0,0 +1,106 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
/**
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
version 2 of the License, or (at your option) any later version.
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, http://geneura.ugr.es
Marc.Schoenauer@polytechnique.fr
mak@dhi.dk
Caner.Candan@univ-angers.fr
*/
#ifndef _eoSignal_h
#define _eoSignal_h
#include <csignal>
#include <utils/eoCheckPoint.h>
#include <utils/eoLogger.h>
#include <map>
#include <vector>
/**
* @addtogroup Continuators
* @{
*/
extern std::map< int, bool > signals_called;
/** eoSignal inherits from eoCheckPoint including signals handling (see signal(7))
*
* @ingroup Utilities
*/
template <class EOT>
class eoSignal : public eoCheckPoint<EOT>
{
public :
eoSignal( int sig = SIGINT ) : eoCheckPoint<EOT>( _dummyContinue ), _sig( sig )
{
::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
}
eoSignal( eoContinue<EOT>& _cont, int sig = SIGINT ) : eoCheckPoint<EOT>( _cont ), _sig( sig )
{
::signals_called[_sig] = false;
#ifndef _WINDOWS
#ifdef SIGQUIT
::signal( _sig, handler );
#endif // !SIGQUIT
#endif // !_WINDOWS
}
bool operator()( const eoPop<EOT>& _pop )
{
bool& called = ::signals_called[_sig];
if ( called )
{
eo::log << eo::logging << "Signal granted…" << std::endl ;
called = false;
return this->eoCheckPoint<EOT>::operator()( _pop );
}
return true;
}
virtual std::string className(void) const { return "eoSignal"; }
static void handler( int sig )
{
::signals_called[sig] = true;
eo::log << eo::logging << "Signal wished…" << std::endl ;
}
private:
class DummyContinue : public eoContinue<EOT>
{
public:
bool operator() ( const eoPop<EOT>& ) { return true; }
} _dummyContinue;
int _sig;
};
/** @} */
#endif // !_eoSignal_h

View file

@ -46,7 +46,9 @@ public :
eoStdoutMonitor(bool _verbose, std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :
eoOStreamMonitor( std::cout, _verbose, _delim, _width, _fill)
{
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdutMonitor constructor is deprecated and will be removed in the next release" << std::endl;
#ifndef DEPRECATED_MESSAGES
eo::log << eo::warnings << "WARNING: the use of the verbose parameter in eoStdoutMonitor constructor is deprecated and will be removed in the next release" << std::endl;
#endif // !DEPRECATED_MESSAGES
}
eoStdoutMonitor(std::string _delim = "\t", unsigned int _width=20, char _fill=' ' ) :