Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
lifecycleevent.h
Go to the documentation of this file.
1 
29 #ifndef LIFECYCLEEVENT_H
30 #define LIFECYCLEEVENT_H
31 
32 #include <string>
33 #include <list>
34 #include <map>
35 #include "param.h"
36 #include "simcomponent.h"
37 #include "metapop.h"
38 
71 class LifeCycleEvent : public virtual SimComponent
72 {
73 protected:
74 
76  std::string _event_name;
77 
78 
81 
82 
84  std::string _LCELinkedTraitType;
85 
86 
89 
90 
91 public:
97  LifeCycleEvent (const char* name, const char* trait_link)
98  : _popPtr(0), _LCELinkedTraitType(trait_link), _LCELinkedTraitIndex(-1)
99  {
100 // cout << "calling LifeCycleEvent("<<name<<","<<trait_link<<")\n";
101  set_event_name(name);
102  }
103 
104 
105  virtual ~LifeCycleEvent ( ) { }
106 
107 
113  virtual void init(Metapop* popPtr)
114  {
115  _popPtr = popPtr;
116  if(!attach_trait(_LCELinkedTraitType)) fatal("bailing out\n");
117  if(!setParameters()) fatal("bailing out\n");
118  }
119 
120 
121 
122  virtual bool attach_trait (string trait)
123  {
124  _LCELinkedTraitType = trait;
125 
126  if(_LCELinkedTraitType.size() != 0) {
127 
129 
130  if(_LCELinkedTraitIndex == -1) {
131  return error("cannot attach trait \"%s\" to life cycle event \"%s\", trait has not been initiated.\n",
132  _LCELinkedTraitType.c_str(), _event_name.c_str());
133  }
134 
135  }
136 
137  return true;
138  }
139 
140  virtual void set_paramset (std::string name, bool required, SimComponent* owner )
141  {
142  SimComponent::set_paramset(name, required, owner);
143  add_parameter(name.c_str(),INT,1,0,0,0,0);
144  }
145 
147  virtual void set_event_name (std::string& name)
148  {
149  _event_name = name;
150  set_paramset(name, 0, this);
151  }
152 
153  virtual void set_event_name (const char* name)
154  {
155  _event_name = name;
156  set_paramset(name, 0, this);
157  }
158 
160  virtual string& get_event_name ( )
161  { return _event_name; }
162 
165  virtual int get_rank ( )
166  { return (int)get_parameter_value(_event_name.c_str()); }
167 
170  virtual void set_pop_ptr (Metapop* popPtr)
171  {_popPtr = popPtr;}
172 
173  virtual Metapop* get_pop_ptr ( )
174  { return _popPtr; }
175 
176 
177 
178 
181 
183  virtual void execute () = 0;
184 
186  virtual LifeCycleEvent* clone () = 0;
187 
189  virtual age_t removeAgeClass () = 0;
190 
192  virtual age_t addAgeClass () = 0;
193 
195  virtual age_t requiredAgeClass () = 0;
196 
198 
199 
200 
201 };
202 
203 #endif //LIFECYCLEEVENT_H
204 
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:127
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
virtual age_t requiredAgeClass()=0
Specifies what age-classes are required by the LCE to execute.
virtual ~LifeCycleEvent()
Definition: lifecycleevent.h:105
virtual void execute()=0
Execute the event on the pop.
virtual void set_event_name(std::string &name)
Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set.
Definition: lifecycleevent.h:147
virtual bool attach_trait(string trait)
Definition: lifecycleevent.h:122
virtual void set_event_name(const char *name)
Definition: lifecycleevent.h:153
virtual int get_rank()
Accessor to the LCE rank in the life cycle.
Definition: lifecycleevent.h:165
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:88
virtual Metapop * get_pop_ptr()
Definition: lifecycleevent.h:173
virtual age_t removeAgeClass()=0
Removes the returned age-class flag(s) from the current Metapop age-class flags.
virtual void init(Metapop *popPtr)
Sets the pointer to the current Metapop and the trait link if applicable.
Definition: lifecycleevent.h:113
virtual void set_paramset(std::string name, bool required, SimComponent *owner)
Definition: lifecycleevent.h:140
std::string _event_name
The param name to be read in the init file.
Definition: lifecycleevent.h:76
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
virtual age_t addAgeClass()=0
Adds the returned age-class flag(s) to the current Metapop age-class flags.
virtual string & get_event_name()
Accessor to the LCE's name.
Definition: lifecycleevent.h:160
virtual void set_pop_ptr(Metapop *popPtr)
Accessors for the population pointer.
Definition: lifecycleevent.h:170
virtual LifeCycleEvent * clone()=0
Cloning interface.
std::string _LCELinkedTraitType
The name of the linked trait.
Definition: lifecycleevent.h:84
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
virtual void set_paramset(ParamSet *paramset)
Sets the ParamSet member.
Definition: simcomponent.h:85
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
virtual bool setParameters()=0
Default interface needed to initialize the component's variables from its input parameters value.
Nemo2.
void fatal(const char *str,...)
Definition: output.cc:99
int error(const char *str,...)
Definition: output.cc:78
Nemo2.
unsigned int age_t
Age class flags.
Definition: types.h:45
@ INT
Definition: types.h:77

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR