Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
PointWithId.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
3/*********************************************************************** * This program is free software; you can
4 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
5 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
6 * *
7 ***************************************************************************/
8
9#ifndef __POINT_WITH_ID_H_INCLUDED__
10#define __POINT_WITH_ID_H_INCLUDED__
11
12namespace quetzal
13{
14namespace utils
15{
22template <typename Point> size_t getIndexOfPointInVector(Point const &p, std::vector<Point> const &vect)
23{
24 auto it = std::find(vect.begin(), vect.end(), p);
25 assert(it != vect.end());
26 return std::distance(vect.begin(), it);
27}
36template <typename Point> class PointWithId
37{
38 public:
44 PointWithId(std::vector<Point> const &vect, size_t index) : m_vector{vect}, m_index{index}
45 {
46 }
53 PointWithId(std::vector<Point> const &vect, Point const &p)
54 : m_vector{vect}, m_index{getIndexOfPointInVector(p, vect)}
55 {
56 }
61 Point getPoint() const
62 {
63 return m_vector[m_index];
64 }
69 size_t getId() const
70 {
71 return m_index;
72 }
77 bool operator==(PointWithId const &other) const
78 {
79 return getPoint() == other.getPoint();
80 }
85 bool operator!=(PointWithId const &other) const
86 {
87 return !(*this == other);
88 }
89
90 private:
91 std::vector<Point> const &m_vector;
92 size_t m_index;
93}; // end PointWithId
94} // namespace utils
95} // namespace quetzal
96#endif
Class to associate an indexing semantics to a collection of points.
Definition PointWithId.hpp:37
bool operator==(PointWithId const &other) const
Comparator.
Definition PointWithId.hpp:77
size_t getId() const
Getter.
Definition PointWithId.hpp:69
PointWithId(std::vector< Point > const &vect, size_t index)
Constructor.
Definition PointWithId.hpp:44
bool operator!=(PointWithId const &other) const
Comparator.
Definition PointWithId.hpp:85
Point getPoint() const
Getter.
Definition PointWithId.hpp:61
PointWithId(std::vector< Point > const &vect, Point const &p)
Constructor.
Definition PointWithId.hpp:53
size_t getIndexOfPointInVector(Point const &p, std::vector< Point > const &vect)
Find the index of a point in a vector.
Definition PointWithId.hpp:22
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21