EvolvingObjects
eoEvalTimeThrowException.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 */
00023 
00024 #include <ctime>
00025 
00026 #include <eoExceptions.h>
00027 
00035 template< class EOT >
00036 class eoEvalTimeThrowException : public eoEvalFuncCounter< EOT >
00037 {
00038 public:
00039     eoEvalTimeThrowException( eoEvalFunc<EOT> & func, time_t max ) : _max(max), _start( std::time(NULL) ), eoEvalFuncCounter<EOT>( func, "Eval.") {}
00040 
00041     virtual void operator() ( EOT & eo )
00042     {
00043         if( eo.invalid() ) {
00044 
00045             time_t elapsed = static_cast<time_t>( std::difftime( std::time(NULL) , _start ) );
00046 
00047             if( elapsed >= _max ) {
00048                 throw eoMaxTimeException(elapsed);
00049             } else {
00050                 func(eo);
00051             }
00052         }
00053     }
00054 
00055 protected:
00056     time_t _max;
00057 
00058     time_t _start;
00059 };
 All Classes Namespaces Files Functions Variables Typedefs Friends