X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fgeneration.h;h=88942ec0d9fd2a0cac8e19b3762bee8cef227da8;hb=5e4a04634f1d31d4c774b44184cf08d3faf4d02a;hp=a37602897694cc6d5afabf80d59331ff74fadca5;hpb=1bef1f38888f19f83083d2f5bc1e1a90bb14291f;p=genetic.git diff --git a/src/generation.h b/src/generation.h index a376028..88942ec 100644 --- a/src/generation.h +++ b/src/generation.h @@ -20,6 +20,7 @@ namespace genetic { */ vector<_Chromosome> chromosomes; + template friend class Generation; public: /** * Default constructor @@ -37,14 +38,7 @@ namespace genetic { /** Copy constructor */ Generation(const Generation& generation) - : chromosomes(generation.get()) { - } - - /** - * Allows read-only access to Generation Chromosomes - */ - vector<_Chromosome> get() const { - return this->chromosomes; + : chromosomes(generation.chromosomes) { } /** @@ -54,9 +48,27 @@ namespace genetic { * @return Generation instance containing copied Chromosomes */ Generation& operator=(const Generation& generation){ - this->chromosomes = generation.get(); + this->chromosomes = generation.chromosomes; return *this; } + + /** + * Returns number of Chromosomes in current Generation + * + * @return number of Chromosomes in current Generation + */ + unsigned int size() const { + return this->chromosomes.size(); + } + + /** + * Returns i-th Chromosome in the current Generation + * + * @return i-th Chromosome in the current Generation + */ + _Chromosome& operator[](unsigned int i) { + return this->chromosomes[i]; + } }; }