bpp-popgen3  3.0.0
BiAlleleMonolocusGenotype.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 using namespace bpp;
8 using namespace std;
9 
10 // ** Class constructor: *******************************************************/
11 
13  size_t firstAlleleIndex,
14  size_t secondAlleleIndex) : alleleIndex_(vector<size_t>(2))
15 {
16  alleleIndex_[0] = firstAlleleIndex;
17  alleleIndex_[1] = secondAlleleIndex;
18 }
19 
21  alleleIndex_(2)
22 {
23  if (alleleIndex.size() != 2)
24  throw BadSizeException("BiAlleleMonolocusGenotype::BiAlleleMonolocusGenotype: allele_index must contain two values.", alleleIndex.size(), 2);
25  alleleIndex_[0] = alleleIndex[0];
26  alleleIndex_[1] = alleleIndex[1];
27 }
28 
30  alleleIndex_(2)
31 {
32  for (size_t i = 0; i < 2; ++i)
33  {
34  alleleIndex_[i] = bmg.getAlleleIndex()[i];
35  }
36 }
37 
38 // ** Class destructor: ********************************************************/
39 
41 {
42  alleleIndex_.clear();
43 }
44 
45 // ** Other methodes: **********************************************************/
46 
48 {
49  for (size_t i = 0; i < 2; ++i)
50  {
51  alleleIndex_.push_back(bmg.getAlleleIndex()[i]);
52  }
53  return *this;
54 }
55 
57 {
58  return (alleleIndex_[0] == bmg.getAlleleIndex()[0] && alleleIndex_[1] == bmg.getAlleleIndex()[1])
59  || (alleleIndex_[0] == bmg.getAlleleIndex()[1] && alleleIndex_[1] == bmg.getAlleleIndex()[0]);
60 }
The BiAlleleMonolocusGenotype class.
bool operator==(const BiAlleleMonolocusGenotype &bmg) const
The == operator.
std::vector< size_t > getAlleleIndex() const override
Get the alleles' index.
BiAlleleMonolocusGenotype & operator=(const BiAlleleMonolocusGenotype &bmg)
The affectation operator.
BiAlleleMonolocusGenotype(size_t firstAlleleIndex, size_t secondAlleleIndex)
Build a monolocus genotype containing two alleles.
virtual ~BiAlleleMonolocusGenotype()
Destroy the BiAlleleMonolocusGenotype.