#include <iostream>
#include <fstream>
#include <vector>

#include "Student.h"
#include "Employee.h"

void print_population(const vector<Person*>& population)
{
	for (size_t i = 0; i < population.size(); ++i)
		population[i]->print(cout);

}

// Factory method. It could be a class
Person* createPerson(const string& role)
{
	if ( role == "estudiante" )
		return new Student();
	if ( role == "administrativo" )
		return new Employee();
	// ...
	return NULL;
}

int main()
{
	ifstream source("poblacion.txt");
	vector<Person*> population;

	string role;
	while ( source >> role )
	{
		Person* person = createPerson(role);
		if ( person )
		{
			person->load(source);
			population.push_back(person);
#if 0
			Student* temp = dynamic_cast<Student*>(person);
			if ( temp )
				temp->specificMethodOfStudent();
#endif
		}
	}

	source.close();
	print_population(population);

	for (size_t i = 0; i < population.size(); ++i)
		delete population[i];

	return 0;
}
