StepperEvent.hpp

Go to the documentation of this file.
00001 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00002 //
00003 //        This file is part of E-Cell Simulation Environment package
00004 //
00005 //                Copyright (C) 1996-2005 Keio University
00006 //                Copyright (C) 2005 The Molecular Sciences Institute
00007 //
00008 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00009 //
00010 //
00011 // E-Cell is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public
00013 // License as published by the Free Software Foundation; either
00014 // version 2 of the License, or (at your option) any later version.
00015 // 
00016 // E-Cell is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 // See the GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public
00022 // License along with E-Cell -- see the file COPYING.
00023 // If not, write to the Free Software Foundation, Inc.,
00024 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00025 // 
00026 //END_HEADER
00027 //
00028 // written by Koichi Takahashi <shafi@e-cell.org>,
00029 // E-Cell Project.
00030 //
00031 
00032 #ifndef __STEPPEREVENT_HPP
00033 #define __STEPPEREVENT_HPP
00034 
00035 #include "libecs.hpp"
00036 #include "Stepper.hpp"
00037 
00038 
00039 namespace libecs
00040 {
00041 
00042   /** @file */
00043 
00044   DECLARE_CLASS( StepperEvent );
00045 
00046   class StepperEvent
00047     :
00048     public EventBase
00049   {
00050 
00051 
00052   public:
00053 
00054     StepperEvent( TimeParam aTime, StepperPtr aStepperPtr )
00055       :
00056       EventBase( aTime ),
00057       theStepper( aStepperPtr )
00058     {
00059       ; // do nothing
00060     }
00061 
00062 
00063     void fire()
00064     {
00065       theStepper->integrate( getTime() );
00066       theStepper->step();
00067       theStepper->log();
00068 
00069       reschedule();
00070     }
00071 
00072     void update( TimeParam aTime )
00073     {
00074       theStepper->interrupt( aTime );
00075 
00076       reschedule();
00077     }
00078 
00079     void reschedule()
00080     {
00081       const Time aLocalTime( theStepper->getCurrentTime() );
00082       const Time aNewStepInterval( theStepper->getStepInterval() );
00083       setTime( aNewStepInterval + aLocalTime );
00084     }
00085 
00086     const bool isDependentOn( StepperEventCref anEvent ) const
00087     {
00088       return theStepper->isDependentOn( anEvent.getStepper() );
00089     }
00090 
00091 
00092     const StepperPtr getStepper() const
00093     {
00094       return theStepper;
00095     }
00096 
00097 
00098     // this method is basically used in initializing and rescheduling 
00099     // in the Scheduler to determine if
00100     // goUp()/goDown (position change) is needed 
00101     const bool operator< ( StepperEventCref rhs ) const
00102     {
00103       if( getTime() > rhs.getTime() )
00104         {
00105           return false;
00106         }
00107       else if( getTime() < rhs.getTime() )
00108         {
00109           return true;
00110         }
00111       else // if theTime == rhs.theTime,
00112         {  // then higher priority comes first 
00113           //      return false;
00114           if( theStepper->getPriority() < rhs.getStepper()->getPriority() )
00115             {
00116               return true;
00117             }
00118           else
00119             {
00120               return false;
00121             }
00122         }
00123     }
00124 
00125     const bool operator!= ( StepperEventCref rhs ) const
00126     {
00127       if( getStepper() == rhs.getStepper() &&
00128           getTime() == rhs.getTime() )
00129         {
00130           return false;
00131         }
00132       else
00133         {
00134           return true;
00135         }
00136     }
00137 
00138 
00139     // dummy, because DynamicPriorityQueue requires this. better without.
00140     StepperEvent()
00141     {
00142       ; // do nothing
00143     }
00144 
00145 
00146   private:
00147 
00148     StepperPtr theStepper;
00149 
00150   };
00151 
00152 
00153 
00154 } // namespace libecs
00155 
00156 
00157 
00158 
00159 #endif /* __STEPPEREVENT_HPP */
00160 
00161 
00162 
00163 
00164 /*
00165   Do not modify
00166   $Author: shafi $
00167   $Revision: 2540 $
00168   $Date: 2005-12-19 05:40:56 +0100 (Mon, 19 Dec 2005) $
00169   $Locker$
00170 */
00171 

Generated on Mon Dec 18 07:29:46 2006 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.5.1