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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR