summaryrefslogtreecommitdiff
path: root/src/population.h
blob: c2d1becfdd57ccc0854a0e7445298f135ee2f0ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef GENETIC_POPULATION_H
#define GENETIC_POPULATION_H

#include <bu/string.h>
#include <bu/hash.h>
#include <bu/mutex.h>

#include "genetic/config.h"

namespace Genetic
{
	class Phenotype;

	class Population
	{
	public:
		Population();
		virtual ~Population();

		typedef Bu::Hash<PhenotypeId, Phenotype *> PhenotypeHash;
		typedef PhenotypeHash::iterator iterator;
		typedef PhenotypeHash::const_iterator const_iterator;

		iterator begin() { return hPhenotype.begin(); }
		const_iterator begin() const { return hPhenotype.begin(); }
		int getSize() const { return hPhenotype.getSize(); }

		PhenotypeId addPhenotype( Phenotype *pNew );
		Phenotype *getPhenotype( PhenotypeId id )
			{ return hPhenotype.get( id ); }
		bool hasProperty( PhenotypeId id, const Bu::String &sKey ) const;
		Bu::Variant getProperty( PhenotypeId id, const Bu::String &sKey ) const;
		void setProperty( PhenotypeId id, const Bu::String &sKey,
				Bu::Variant vValue );
		void delPhenotype( PhenotypeId id );
		Phenotype *takePhenotype( PhenotypeId id );
		void clear();

		PhenotypeId timestep();
		PhenotypeId time() const;

	private:
		PhenotypeId uNextId;
		PhenotypeId uTime;
		PhenotypeHash hPhenotype;
		mutable Bu::Mutex mGeneral;
	};
};

#endif