ProcessEvent.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 __PROCESSEVENT_HPP
00033 #define __PROCESSEVENT_HPP
00034 
00035 #include "libecs.hpp"
00036 #include "Process.hpp"
00037 
00038 #include "EventScheduler.hpp"
00039 
00040 
00041 namespace libecs
00042 {
00043 
00044   /** @file */
00045 
00046   DECLARE_CLASS( ProcessEvent );
00047 
00048   class ProcessEvent
00049     :
00050     public EventBase
00051   {
00052 
00053 
00054   public:
00055 
00056     ProcessEvent( TimeParam aTime, ProcessPtr aProcessPtr )
00057       :
00058       EventBase( aTime ),
00059       theProcess( aProcessPtr )
00060     {
00061       ; // do nothing
00062     }
00063 
00064     const ProcessPtr getProcess() const
00065     {
00066       return theProcess;
00067     }
00068 
00069 
00070     void fire()
00071     {
00072       //FIXME: should be theProcess->fire();
00073       theProcess->addValue( 1.0 );
00074 
00075       reschedule( getTime() );
00076     }
00077 
00078     void update( TimeParam aTime )
00079     {
00080       reschedule( aTime );
00081     }
00082 
00083     void reschedule( TimeParam aTime )
00084     {
00085       const Time aNewStepInterval( theProcess->getStepInterval() );
00086       setTime( aNewStepInterval + aTime );
00087     }
00088 
00089     const bool isDependentOn( ProcessEventCref anEvent ) const
00090     {
00091       return theProcess->isDependentOn( anEvent.getProcess() );
00092     }
00093 
00094 
00095     const bool operator< ( ProcessEventCref rhs ) const
00096     {
00097       // return theTime < rhs.theTime;
00098 
00099       if( getTime() > rhs.getTime() )
00100         {
00101           return false;
00102         }
00103       else if( getTime() < rhs.getTime() )
00104         {
00105           return true;
00106         }
00107       else // if theTime == rhs.theTime,
00108         {  // then higher priority comes first.  
00109           if( theProcess->getPriority() < rhs.getProcess()->getPriority() )
00110             {
00111               return true;
00112             }
00113           else
00114             {
00115               return false;
00116             }
00117         }
00118     }
00119 
00120     const bool operator!= ( ProcessEventCref rhs ) const
00121     {
00122       if( getTime() == rhs.getTime() && 
00123           getProcess() == rhs.getProcess() )
00124         {
00125           return false;
00126         }
00127       else
00128         {
00129           return true;
00130         }
00131     }
00132 
00133 
00134     // dummy, because DynamicPriorityQueue requires this. better without.
00135     ProcessEvent()
00136     {
00137       ; // do nothing
00138     }
00139 
00140 
00141   private:
00142 
00143     ProcessPtr theProcess;
00144 
00145   };
00146 
00147   /*@}*/
00148 
00149 } // namespace libecs
00150 
00151 
00152 
00153 
00154 #endif /* __PROCESSEVENT_HPP */
00155 
00156 
00157 
00158 
00159 /*
00160   Do not modify
00161   $Author: shafi $
00162   $Revision: 2529 $
00163   $Date: 2005-11-19 10:36:40 +0100 (Sat, 19 Nov 2005) $
00164   $Locker$
00165 */
00166 

Generated on Fri Aug 31 18:32:07 2007 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.5.3