TePDIAlgorithm.cpp

Go to the documentation of this file.
00001 #include "TePDIAlgorithm.hpp"
00002 
00003 #include "../kernel/TeAgnostic.h"
00004 
00005 TePDIAlgorithm::TePDIAlgorithm()
00006 {
00007   progress_enabled_ = true;
00008 }
00009 
00010 
00011 TePDIAlgorithm::~TePDIAlgorithm()
00012 {
00013 }
00014 
00015 
00016 bool TePDIAlgorithm::Reset( const TePDIParameters& params )
00017 {
00018   if( CheckParameters( params ) ) {
00019     ResetState( params );
00020 
00021     /* This line must come after the ResetState line, because some algorithms
00022        checks the difference between the current internal parameters and the
00023        new supplied parameters */
00024     params_.Clear();
00025     params_ = params;
00026 
00027     return true;
00028   } else {
00029     TEAGN_LOG_AND_RETURN( "Invalid supplied parameters" );
00030   }
00031 }
00032 
00033 
00034 bool TePDIAlgorithm::Apply()
00035 {
00036   bool return_value = false;
00037   
00038   if( CheckInternalParameters() ) {
00039     #ifdef NDEBUG
00040       try
00041       {
00042         return_value = RunImplementation();
00043       }
00044       catch( const TeException& exc )
00045       {
00046         TEAGN_LOGERR( "Exception raised from algorithm - " +
00047           exc.message() );
00048       }
00049       catch(...)
00050       {
00051         TEAGN_LOGERR( "Unhandled exception raised from algorithm" );
00052       }
00053     #else
00054       return_value = RunImplementation();
00055     #endif
00056     
00057     StopProgInt();
00058   } else {
00059     TEAGN_LOG_AND_RETURN( "Invalid supplied parameters" );
00060   }
00061   
00062   return return_value;
00063 }
00064 
00065 
00066 bool TePDIAlgorithm::Apply( const TePDIParameters& params )
00067 {
00068   TEAGN_TRUE_OR_RETURN( CheckParameters( params ),
00069     "Invalid parameters" )
00070     
00071   ResetState( params );
00072 
00073   /* This line must come after the ResetState line, because some algorithms
00074      checks the difference between the current internal parameters and the
00075      new supplied parameters */
00076   params_.Clear();
00077   params_ = params;
00078   
00079   #ifdef NDEBUG
00080     try
00081     {
00082       return RunImplementation();
00083     }
00084     catch( const TeException& exc )
00085     {
00086       TEAGN_LOG_AND_RETURN( "Exception raised from algorithm - " +
00087         exc.message() );
00088     }
00089     catch(...)
00090     {
00091       TEAGN_LOG_AND_RETURN( "Unhandled exception raised from algorithm" );
00092     }
00093   #else
00094     return RunImplementation();
00095   #endif    
00096 }
00097 
00098 
00099 const TePDIParameters& TePDIAlgorithm::GetParameters() const
00100 {
00101   return params_;
00102 }
00103 
00104 
00105 bool TePDIAlgorithm::CheckInternalParameters() const
00106 {
00107   return CheckParameters( params_ );
00108 }
00109 
00110 
00111 const TePDIAlgorithm& TePDIAlgorithm::operator=( 
00112   const TePDIAlgorithm& external )
00113 {
00114   TEAGN_LOG_AND_THROW( "Algorithms cannot be copied" );  
00115   
00116   return external;
00117 }
00118 
00119 TePDIAlgorithm* TePDIAlgorithm::DefaultObject( const TePDIParameters& params )
00120 {
00121   TEAGN_LOG_AND_THROW( "Trying to create an invalid algorithm instance" );
00122   
00123   TePDIParameters dummy_params = params;
00124 
00125   return 0;
00126 }
00127 
00128 
00129 void TePDIAlgorithm::ToggleProgInt( bool enabled )
00130 {
00131   progress_enabled_ = enabled;
00132   
00133   if( ! enabled ) {
00134     pi_manager_.Toggle( false );
00135   }
00136 }
00137 
00138 
00139 void TePDIAlgorithm::StartProgInt( const std::string& message, 
00140   unsigned int steps )
00141 {
00142   if( progress_enabled_ ) {
00143     pi_manager_.Reset( message, steps );
00144     pi_manager_.Toggle( true );
00145   }
00146 }
00147 
00148 
00149 bool TePDIAlgorithm::UpdateProgInt( unsigned int step )
00150 {
00151   return pi_manager_.Update( step );
00152 }
00153 
00154 
00155 bool TePDIAlgorithm::IncProgInt()
00156 {
00157   return pi_manager_.Increment();
00158 }
00159 
00160 
00161 void TePDIAlgorithm::StopProgInt()
00162 {
00163   pi_manager_.Toggle( false );
00164 }
00165 

Generated on Sun Jul 29 04:01:23 2012 for TerraLib - Development Source by  doxygen 1.5.3