• Main Page
  • Classes
  • Files
  • File List

/home/rotten/Code/adevs/trunk/include/adevs_models.h

00001 /***************
00002 Copyright (C) 2000-2010 by James Nutaro
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; either
00007 version 2 of the License, or (at your option) any later version.
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 Bugs, comments, and questions can be sent to nutaro@gmail.com
00019 ***************/
00020 #ifndef __adevs_models_h_
00021 #define __adevs_models_h_
00022 #include "adevs_bag.h"
00023 #include "adevs_set.h"
00024 #include <cstdlib>
00025 
00026 namespace adevs
00027 {
00028 
00029 /*
00030  * Declare network and atomic model so types can be used as the type of
00031  * parent in the basic Devs model and for type ID functions.  
00032  */
00033 template <class X> class Network;
00034 template <class X> class Atomic;
00035 template <class X> class Schedule;
00036 template <class X> class Simulator;
00037 
00038 /*
00039  * Constant indicating no processor assignment for the model. This is used by the
00040  * parallel simulator
00041  */
00042 #define ADEVS_NOT_ASSIGNED_TO_PROCESSOR -1
00043 
00048 template <class X> class Devs
00049 {
00050         public:
00052                 Devs():
00053                 parent(NULL),
00054                 proc(ADEVS_NOT_ASSIGNED_TO_PROCESSOR)
00055                 {
00056                 }
00058                 virtual ~Devs()
00059                 {
00060                 }
00066                 virtual Network<X>* typeIsNetwork() { return NULL; }
00068                 virtual Atomic<X>* typeIsAtomic() { return NULL; }
00073                 const Network<X>* getParent() const { return parent; }
00074                 Network<X>* getParent() { return parent; }
00081                 void setParent(Network<X>* parent) { this->parent = parent; }
00094                 virtual bool model_transition() { return false; }
00102                 virtual double lookahead() { return 0.0; }
00109                 void setProc(int proc) { this->proc = proc; }
00114                 int getProc() { return proc; }
00115 
00116         private:
00117                 Network<X>* parent;
00118                 int proc;
00119 };
00120 
00126 template <class X> class Event
00127 {
00128         public:
00130                 Event():
00131                 model(NULL),
00132                 value()
00133                 {
00134                 }
00142                 Event(Devs<X>* model, const X& value):
00143                 model(model),
00144                 value(value)
00145                 {
00146                 }
00148                 Event(const Event<X>& src):
00149                 model(src.model),
00150                 value(src.value)
00151                 {
00152                 }
00154                 const Event<X>& operator=(const Event<X>& src)
00155                 {
00156                         model = src.model;
00157                         value = src.value;
00158                         return *this;
00159                 }
00161                 Devs<X>* model;
00163                 X value;
00165                 ~Event()
00166                 {
00167                 }
00168 };
00169 
00173 template <class X> class Atomic: public Devs<X>
00174 {
00175         public:
00177                 Atomic():
00178                 Devs<X>()
00179                 {
00180                         tL = 0.0;
00181                         x = y = NULL;
00182                         q_index = 0; // The Schedule requires this to be zero
00183                         active = false;
00184                 }
00186                 virtual void delta_int() = 0;
00192                 virtual void delta_ext(double e, const Bag<X>& xb) = 0;
00197                 virtual void delta_conf(const Bag<X>& xb) = 0;
00202                 virtual void output_func(Bag<X>& yb) = 0;
00207                 virtual double ta() = 0;
00214                 virtual void gc_output(Bag<X>& g) = 0;
00216                 virtual ~Atomic(){}
00218                 Atomic<X>* typeIsAtomic() { return this; }
00219         protected:
00226                 double getLastEventTime() const { return tL; }
00227 
00228         private:
00229 
00230                 friend class Simulator<X>;
00231                 friend class Schedule<X>;
00232 
00233                 // Time of last event
00234                 double tL;
00235                 // Index in the priority queue
00236                 unsigned int q_index;
00237                 // Input and output event bags
00238                 Bag<X> *x, *y;
00239                 // Has this model been activated?
00240                 bool active;
00241 };
00242 
00246 template <class X> class Network: public Devs<X>
00247 {
00248         public:
00250                 Network():
00251                 Devs<X>()
00252                 {
00253                 }
00260                 virtual void getComponents(Set<Devs<X>*>& c) = 0;
00272                 virtual void route(const X& value, Devs<X>* model, Bag<Event<X> >& r) = 0;
00277                 virtual ~Network()
00278                 {
00279                 }
00281                 Network<X>* typeIsNetwork() { return this; }
00282 };
00283 
00284 } // end of namespace
00285 
00286 #endif

Generated on Sun Jan 23 2011 for adevs by  doxygen 1.7.1