bpp-phyl3  3.0.0
Mapping.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_MAPPING_MAPPING_H
6 #define BPP_PHYL_MAPPING_MAPPING_H
7 
8 #include <Bpp/Clonable.h>
10 
11 #include "../Tree/PhyloTree.h"
12 #include "PhyloBranchMapping.h"
13 
14 // From the STL:
15 #include <vector>
16 #include <memory>
17 
18 namespace bpp
19 {
25  public virtual Clonable
26 {
27 public:
29  virtual ~MappingInterface() {}
30 
31  MappingInterface* clone() const override = 0;
32 
33 public:
37  virtual size_t getNumberOfSites() const = 0;
38 
42  virtual const PhyloBranch& getBranch(unsigned int branchId) const = 0;
43 
44  virtual PhyloBranch& getBranch(unsigned int branchId) = 0;
45 
46  // virtual unsigned int getBranchIndex(const std::shared_ptr<PhyloBranch> branch) const = 0;
47 
51  virtual size_t getNumberOfBranches() const = 0;
52 
57  virtual int getSitePosition(size_t index) const = 0;
58 
66  virtual void setSitePosition(size_t index, int position) = 0;
67 };
68 
69 
78  public virtual MappingInterface
79 {
80 protected:
81  std::vector<int> sitesPositions_;
82  size_t nbSites_;
83 
84 public:
86  {}
87 
89  {}
90 
91  AbstractMapping(const AbstractMapping& absm) = default;
92 
93  AbstractMapping& operator=(const AbstractMapping& absm) = default;
94 
95  virtual ~AbstractMapping() {}
96 
97 public:
98  int getSitePosition(size_t index) const
99  {
100  return sitesPositions_.size() == 0 ? (int)(index + 1) : sitesPositions_[index];
101  }
102 
103  void setSitePosition(size_t index, int position)
104  {
105  if (sitesPositions_.size() == 0)
106  sitesPositions_.resize(nbSites_);
107 
108  sitesPositions_[index] = position;
109  }
110 
111  size_t getNumberOfSites() const { return nbSites_; }
112 
113  virtual void setNumberOfSites(size_t numberOfSites)
114  {
115  nbSites_ = numberOfSites;
116  sitesPositions_.clear();
117  }
118 };
119 } // end of namespace bpp.
120 #endif // BPP_PHYL_MAPPING_MAPPING_H
Partial implementation of the mapping interface.
Definition: Mapping.h:79
int getSitePosition(size_t index) const
Definition: Mapping.h:98
std::vector< int > sitesPositions_
Definition: Mapping.h:81
AbstractMapping(const AbstractMapping &absm)=default
virtual ~AbstractMapping()
Definition: Mapping.h:95
AbstractMapping(size_t nb)
Definition: Mapping.h:88
void setSitePosition(size_t index, int position)
Set the position of a given site.
Definition: Mapping.h:103
virtual void setNumberOfSites(size_t numberOfSites)
Definition: Mapping.h:113
size_t getNumberOfSites() const
Definition: Mapping.h:111
AbstractMapping & operator=(const AbstractMapping &absm)=default
General interface for storing mapping data.
Definition: Mapping.h:26
virtual size_t getNumberOfBranches() const =0
MappingInterface * clone() const override=0
virtual const PhyloBranch & getBranch(unsigned int branchId) const =0
virtual int getSitePosition(size_t index) const =0
virtual ~MappingInterface()
Definition: Mapping.h:29
virtual PhyloBranch & getBranch(unsigned int branchId)=0
virtual void setSitePosition(size_t index, int position)=0
Set the position of a given site.
virtual size_t getNumberOfSites() const =0
Defines the basic types of data flow nodes.