EvolvingObjects
eoEvalCounterThrowException.h
00001 /*
00002 (c) Thales group, 2010
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation;
00007     version 2 of the License.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 Contact: http://eodev.sourceforge.net
00019 
00020 Authors:
00021 Johann Dréo <johann.dreo@thalesgroup.com>
00022 Caner Candan <caner.candan@thalesgroup.com>
00023 
00024 */
00025 
00026 #ifndef __eoEvalCounterThrowException_h__
00027 #define __eoEvalCounterThrowException_h__
00028 
00029 #include <eoEvalFuncCounter.h>
00030 #include <utils/eoParam.h>
00031 #include <eoExceptions.h>
00032 
00047 template < typename EOT >
00048 class eoEvalCounterThrowException : public eoEvalFuncCounter< EOT >
00049 {
00050 public :
00051     eoEvalCounterThrowException( eoEvalFunc<EOT>& func, unsigned long max_evals, std::string name = "Eval. ")
00052         : eoEvalFuncCounter< EOT >( func, name ), _threshold( max_evals )
00053     {}
00054 
00055     using eoEvalFuncCounter< EOT >::value;
00056 
00058     virtual void operator()(EOT& eo)
00059     {
00060         // bypass already evaluated individuals
00061         if (eo.invalid()) {
00062 
00063             // increment the value of the self parameter
00064             // (eoEvalFuncCounter inherits from @see eoValueParam)
00065             value()++;
00066 
00067             // if we have reached the maximum
00068             if ( value() >= _threshold ) {
00069 
00070                 // go back through the stack until catched
00071                 throw eoMaxEvalException(_threshold);
00072             }
00073 
00074             // evaluate
00075             func(eo);
00076 
00077         } // if invalid
00078     }
00079 
00080     virtual std::string className() const {return "eoEvalCounterThrowException";}
00081 
00082 private :
00083     unsigned long _threshold;
00084 };
00085 
00086 #endif // __eoEvalCounterThrowException_h__
 All Classes Namespaces Files Functions Variables Typedefs Friends