Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
hgps::Population Class Reference

Defines the virtual population data type. More...

#include <population.h>

Public Types

using IteratorType = std::vector< Person >::iterator
 Population iterator. More...
 
using ConstIteratorType = std::vector< Person >::const_iterator
 Read-only population iterator. More...
 

Public Member Functions

 Population ()=delete
 
 Population (const std::size_t size)
 Initialises a new instance of the Population class. More...
 
std::size_t size () const noexcept
 Gets the current size of the population. More...
 
std::size_t initial_size () const noexcept
 Gets the initial size of the population. More...
 
std::size_t current_active_size () const noexcept
 Gets the current active size of the population. More...
 
Personoperator[] (std::size_t index)
 Gets a Person by index without bounds checking. More...
 
const Personoperator[] (std::size_t index) const
 Gets a Person by index without bounds checking. More...
 
Personat (std::size_t index)
 Gets a Person by index with bounds checking. More...
 
const Personat (std::size_t index) const
 Gets a Person by index with bounds checking. More...
 
void add (Person &&person, unsigned int time) noexcept
 Adds a Person to the virtual population. More...
 
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. More...
 
IteratorType begin () noexcept
 Gets an iterator to the beginning of the virtual population. More...
 
IteratorType end () noexcept
 Gets an iterator to the element following the last Person of the population. More...
 
ConstIteratorType begin () const noexcept
 Gets an read-only iterator to the beginning of the virtual population. More...
 
ConstIteratorType end () const noexcept
 Gets a read-only iterator to the element following the last Person of the population. More...
 
ConstIteratorType cbegin () const noexcept
 Gets an read-only iterator to the beginning of the virtual population. More...
 
ConstIteratorType cend () const noexcept
 Gets a read-only iterator to the element following the last Person of the population. More...
 

Detailed Description

Defines the virtual population data type.

The virtual population size is dynamic and can change due to births, deaths and emigration. When possible, the Population class recycles the dead and migrated individuals slots with newborn babies to minimise memory allocation and clear-up the inactive population.

Member Typedef Documentation

◆ ConstIteratorType

using hgps::Population::ConstIteratorType = std::vector<Person>::const_iterator

Read-only population iterator.

◆ IteratorType

using hgps::Population::IteratorType = std::vector<Person>::iterator

Population iterator.

Constructor & Destructor Documentation

◆ Population() [1/2]

hgps::Population::Population ( )
delete

◆ Population() [2/2]

hgps::Population::Population ( const std::size_t  size)
explicit

Initialises a new instance of the Population class.

Parameters
sizeInitial population size

Member Function Documentation

◆ add()

void hgps::Population::add ( Person &&  person,
unsigned int  time 
)
noexcept

Adds a Person to the virtual population.

Parameters
personThe new Person instance
timeCurrent simulation time

◆ add_newborn_babies()

void hgps::Population::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.

Parameters
numberThe number of newborn babies to add
genderThe gender of the newborn babies
timeCurrent simulation time
Here is the caller graph for this function:

◆ at() [1/2]

Person & hgps::Population::at ( std::size_t  index)

Gets a Person by index with bounds checking.

Parameters
indexThe population index
Returns
Reference to Person
Exceptions
std::out_of_rangefor accessing outside of the bounds

◆ at() [2/2]

const Person & hgps::Population::at ( std::size_t  index) const

Gets a Person by index with bounds checking.

Parameters
indexThe population index
Returns
Reference to Person
Exceptions
std::out_of_rangefor accessing outside of the bounds

◆ begin() [1/2]

ConstIteratorType hgps::Population::begin ( ) const
inlinenoexcept

Gets an read-only iterator to the beginning of the virtual population.

Returns
Iterator to the first Person

◆ begin() [2/2]

IteratorType hgps::Population::begin ( )
inlinenoexcept

Gets an iterator to the beginning of the virtual population.

Returns
Iterator to the first Person

◆ cbegin()

ConstIteratorType hgps::Population::cbegin ( ) const
inlinenoexcept

Gets an read-only iterator to the beginning of the virtual population.

Returns
Iterator to the first Person

◆ cend()

ConstIteratorType hgps::Population::cend ( ) const
inlinenoexcept

Gets a read-only iterator to the element following the last Person of the population.

Returns
Iterator to the element following the last Person.

◆ current_active_size()

std::size_t hgps::Population::current_active_size ( ) const
noexcept

Gets the current active size of the population.

Returns
Current active population size
Here is the caller graph for this function:

◆ end() [1/2]

ConstIteratorType hgps::Population::end ( ) const
inlinenoexcept

Gets a read-only iterator to the element following the last Person of the population.

Returns
Iterator to the element following the last Person.

◆ end() [2/2]

IteratorType hgps::Population::end ( )
inlinenoexcept

Gets an iterator to the element following the last Person of the population.

Returns
Iterator to the element following the last Person.

◆ initial_size()

std::size_t hgps::Population::initial_size ( ) const
noexcept

Gets the initial size of the population.

Returns
Initial population size
Here is the caller graph for this function:

◆ operator[]() [1/2]

Person & hgps::Population::operator[] ( std::size_t  index)

Gets a Person by index without bounds checking.

Parameters
indexThe population index
Returns
Reference to Person, out of bound access is undefined behaviour.

◆ operator[]() [2/2]

const Person & hgps::Population::operator[] ( std::size_t  index) const

Gets a Person by index without bounds checking.

Parameters
indexThe population index
Returns
Reference to Person, out of bound access is undefined behaviour.

◆ size()

std::size_t hgps::Population::size ( ) const
noexcept

Gets the current size of the population.

Returns
Current population size
Here is the caller graph for this function:

The documentation for this class was generated from the following files: