Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
population.h
Go to the documentation of this file.
1 #pragma once
2 #include "person.h"
3 
4 #include <vector>
5 
6 namespace hgps {
7 
14 class Population {
15  public:
17  using IteratorType = std::vector<Person>::iterator;
19  using ConstIteratorType = std::vector<Person>::const_iterator;
20 
21  Population() = delete;
24  explicit Population(const std::size_t size);
25 
28  std::size_t size() const noexcept;
29 
32  std::size_t initial_size() const noexcept;
33 
36  std::size_t current_active_size() const noexcept;
37 
41  Person &operator[](std::size_t index);
42 
46  const Person &operator[](std::size_t index) const;
47 
52  Person &at(std::size_t index);
53 
58  const Person &at(std::size_t index) const;
59 
63  void add(Person &&person, unsigned int time) noexcept;
64 
69  void add_newborn_babies(std::size_t number, core::Gender gender, unsigned int time) noexcept;
70 
73  IteratorType begin() noexcept { return people_.begin(); }
74 
77  IteratorType end() noexcept { return people_.end(); }
78 
81  ConstIteratorType begin() const noexcept { return people_.cbegin(); }
82 
85  ConstIteratorType end() const noexcept { return people_.cend(); }
86 
89  ConstIteratorType cbegin() const noexcept { return people_.cbegin(); }
90 
93  ConstIteratorType cend() const noexcept { return people_.cend(); }
94 
95  private:
96  std::size_t initial_size_;
97  std::vector<Person> people_;
98 
99  std::vector<int> find_index_of_recyclables(unsigned int time,
100  std::size_t top = 0) const noexcept;
101 };
102 } // namespace hgps
Defines the virtual population data type.
Definition: population.h:14
ConstIteratorType end() const noexcept
Gets a read-only iterator to the element following the last Person of the population.
Definition: population.h:85
IteratorType end() noexcept
Gets an iterator to the element following the last Person of the population.
Definition: population.h:77
std::vector< Person >::iterator IteratorType
Population iterator.
Definition: population.h:17
ConstIteratorType cend() const noexcept
Gets a read-only iterator to the element following the last Person of the population.
Definition: population.h:93
std::size_t size() const noexcept
Gets the current size of the population.
Definition: population.cpp:7
std::vector< Person >::const_iterator ConstIteratorType
Read-only population iterator.
Definition: population.h:19
std::size_t initial_size() const noexcept
Gets the initial size of the population.
Definition: population.cpp:9
Population()=delete
std::size_t current_active_size() const noexcept
Gets the current active size of the population.
Definition: population.cpp:11
ConstIteratorType cbegin() const noexcept
Gets an read-only iterator to the beginning of the virtual population.
Definition: population.h:89
Person & at(std::size_t index)
Gets a Person by index with bounds checking.
Definition: population.cpp:22
IteratorType begin() noexcept
Gets an iterator to the beginning of the virtual population.
Definition: population.h:73
void add_newborn_babies(std::size_t number, core::Gender gender, unsigned int time) noexcept
Adds newborn babies of gender to the virtual population, age = 0.
Definition: population.cpp:36
void add(Person &&person, unsigned int time) noexcept
Adds a Person to the virtual population.
Definition: population.cpp:26
ConstIteratorType begin() const noexcept
Gets an read-only iterator to the beginning of the virtual population.
Definition: population.h:81
Gender
Enumerates gender types.
Definition: forward_type.h:18
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
Global namespace.
Definition: jsonparser.h:88
Defines a virtual population person data type.
Definition: person.h:40