15 Man *MAN(Person *pPerson);
16 Woman *WOMAN(Person *pPerson);
21 enum InfectionType { None, Partner, Mother, Seed };
23 Person(
double dateOfBirth, Gender g);
29 void setFather(Man *pFather) { assert(m_pFather == 0); assert(pFather != 0); m_pFather = pFather; }
30 void setMother(Woman *pMother) { assert(m_pMother == 0); assert(pMother != 0); m_pMother = pMother; }
32 Man *getFather()
const {
return m_pFather; }
33 Woman *getMother()
const {
return m_pMother; }
36 int getNumberOfRelationships()
const {
return m_relationshipsSet.size(); }
37 void startRelationshipIteration();
38 Person *getNextRelationshipPartner(
double &formationTime);
40 bool hasRelationshipWith(Person *pPerson)
const;
43 void addRelationship(Person *pPerson,
double t);
44 void removeRelationship(Person *pPerson,
double t);
47 double getLastRelationshipChangeTime()
const {
return m_lastRelationChangeTime; }
49 void setSexuallyActive() { m_sexuallyActive =
true; }
50 bool isSexuallyActive() {
return m_sexuallyActive; }
52 void setInfected(
double t, Person *pOrigin, InfectionType iType);
53 bool isInfected()
const {
return m_infected; }
54 double getInfectionTime()
const { assert(m_infected);
return m_infectionTime; }
55 bool inAcuteStage()
const { assert(m_infected);
return m_acuteStage; }
56 void setInChronicStage() { assert(m_infected); assert(m_acuteStage); m_acuteStage =
false; }
63 void addChild(Person *pPerson);
64 bool hasChild(Person *pPerson)
const;
65 int getNumberOfChildren()
const {
return m_children.size(); }
67 void setBreastFeeding() { assert(!m_breastFeeding); m_breastFeeding =
true; }
68 bool isBreastFeeding()
const {
return m_breastFeeding; }
69 void stopBreastFeeding() { assert(m_breastFeeding); m_breastFeeding =
false; }
76 Relationship(Person *pPerson,
double formationTime) { assert(pPerson != 0); assert(formationTime > 0); m_pPerson = pPerson; m_formationTime = formationTime; }
77 Relationship(Person *pPerson) { assert(pPerson != 0); m_pPerson = pPerson; m_formationTime = -1; }
79 Person *getPartner()
const {
return m_pPerson; }
80 double getFormationTime()
const {
return m_formationTime; }
82 bool operator<(
const Relationship &rel)
const
84 if (m_pPerson->getPersonID() < rel.m_pPerson->getPersonID())
90 double m_formationTime;
93 std::set<Relationship> m_relationshipsSet;
94 std::set<Relationship>::const_iterator m_relationshipsIterator;
95 double m_lastRelationChangeTime;
96 bool m_sexuallyActive;
98 double m_infectionTime;
100 Person *m_pInfectionOrigin;
101 InfectionType m_infectionType;
107 std::vector<Person *> m_children;
109 bool m_breastFeeding;
112 bool m_relIterationBusy;
116 class Man :
public Person
119 Man(
double dateOfBirth);
123 class Woman :
public Person
126 Woman(
double dateOfBirth);
129 void setPregnant(
bool f) { m_pregnant = f; }
130 bool isPregnant()
const {
return m_pregnant; }
135 inline void Person::addRelationship(Person *pPerson,
double t)
137 assert(!m_relIterationBusy);
138 assert(pPerson != 0);
139 assert(pPerson !=
this);
140 assert(!hasDied() && !pPerson->hasDied());
142 assert(m_relationshipsSet.find(Person::Relationship(pPerson)) == m_relationshipsSet.end());
144 Person::Relationship r(pPerson, t);
146 m_relationshipsSet.insert(r);
147 m_relationshipsIterator = m_relationshipsSet.begin();
149 assert(t >= m_lastRelationChangeTime);
150 m_lastRelationChangeTime = t;
153 inline void Person::removeRelationship(Person *pPerson,
double t)
155 assert(!m_relIterationBusy);
156 assert(pPerson != 0);
158 std::set<Person::Relationship>::iterator it = m_relationshipsSet.find(pPerson);
160 if (it == m_relationshipsSet.end())
162 std::cerr <<
"Consistency error: a person was not found exactly once in the relationship list" << std::endl;
166 m_relationshipsSet.erase(it);
167 m_relationshipsIterator = m_relationshipsSet.begin();
169 assert(t >= m_lastRelationChangeTime);
170 m_lastRelationChangeTime = t;
173 inline bool Person::hasRelationshipWith(Person *pPerson)
const
175 return m_relationshipsSet.find(Person::Relationship(pPerson)) != m_relationshipsSet.end();
178 inline void Person::addChild(Person *pPerson)
180 assert(pPerson != 0);
181 assert(!hasChild(pPerson));
183 m_children.push_back(pPerson);
188 inline bool Person::hasChild(Person *pPerson)
const
190 assert(pPerson != 0);
192 for (
int i = 0 ; i < m_children.size() ; i++)
194 assert(m_children[i] != 0);
196 if (m_children[i] == pPerson)
203 inline void Person::setInfected(
double t, Person *pOrigin, InfectionType iType)
209 m_pInfectionOrigin = pOrigin;
210 m_infectionType = iType;
214 assert(iType != None);
215 assert(!(pOrigin == 0 && iType != Seed));
218 inline void Person::startRelationshipIteration()
220 assert(!m_relIterationBusy);
222 m_relationshipsIterator = m_relationshipsSet.begin();
224 if (m_relationshipsIterator != m_relationshipsSet.end())
225 m_relIterationBusy =
true;
229 inline Person *Person::getNextRelationshipPartner(
double &formationTime)
231 if (m_relationshipsIterator == m_relationshipsSet.end())
234 m_relIterationBusy =
false;
239 assert(m_relIterationBusy);
241 const Person::Relationship &r = *m_relationshipsIterator;
243 ++m_relationshipsIterator;
245 formationTime = r.getFormationTime();
246 return r.getPartner();
249 inline Man *MAN(Person *pPerson)
251 assert(pPerson != 0);
254 return static_cast<Man*
>(pPerson);
257 inline Woman *WOMAN(Person *pPerson)
259 assert(pPerson != 0);
262 return static_cast<Woman*
>(pPerson);
The person is a man.
Definition: personbase.h:30
Gender getGender() const
Returns the gender of the person as set at construction time.
Definition: personbase.h:48
The person is a woman.
Definition: personbase.h:32
This is the base class for a person in a population-based simulation that used the Population class...
Definition: personbase.h:23