A library for working with phylogenetic and population genetic data.
v0.32.0
filter_status.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FILTER_FILTER_STATUS_H_
2 #define GENESIS_POPULATION_FILTER_FILTER_STATUS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
34 #include <cstdint>
35 #include <stdexcept>
36 #include <string>
37 
38 namespace genesis {
39 namespace population {
40 
41 // =================================================================================================
42 // Filter Status
43 // =================================================================================================
44 
66 {
67 public:
68 
69  using IntType = uint32_t;
70 
71  // -------------------------------------------
72  // Getter
73  // -------------------------------------------
74 
75  bool passing() const
76  {
77  return status_ == 0;
78  }
79 
80  bool is( IntType value ) const
81  {
82  return status_ == value;
83  }
84 
85  template<typename FilterTag>
86  bool is( FilterTag value ) const
87  {
88  return is( static_cast<IntType>( value ));
89  }
90 
91  IntType get() const
92  {
93  return status_;
94  }
95 
96  // -------------------------------------------
97  // Setter
98  // -------------------------------------------
99 
100  void set( IntType value )
101  {
102  if( status_ != 0 ) {
103  throw std::domain_error(
104  "Cannot set FilterStatus to " + std::to_string(value) + ", as the status has "
105  "already been set to " + std::to_string(status_) + " before. Use reset() instead."
106  );
107  }
108  status_ = value;
109  }
110 
111  template<typename FilterTag>
112  void set( FilterTag value )
113  {
114  set( static_cast<IntType>( value ));
115  }
116 
117  void reset()
118  {
119  status_ = 0;
120  }
121 
122  void reset( IntType value )
123  {
124  status_ = value;
125  }
126 
127  template<typename FilterTag>
128  void reset( FilterTag value )
129  {
130  reset( static_cast<IntType>( value ));
131  }
132 
133  // -------------------------------------------
134  // Private Members
135  // -------------------------------------------
136 
137 private:
138 
139  IntType status_ = 0;
140 };
141 
142 } // namespace population
143 } // namespace genesis
144 
145 #endif // include guard
genesis::population::FilterStatus::is
bool is(FilterTag value) const
Definition: filter_status.hpp:86
genesis::population::FilterStatus::get
IntType get() const
Definition: filter_status.hpp:91
genesis::population::FilterStatus
Tag class to assign a filter status to a Variant or SampleCounts.
Definition: filter_status.hpp:65
genesis::population::FilterStatus::set
void set(FilterTag value)
Definition: filter_status.hpp:112
genesis::population::FilterStatus::is
bool is(IntType value) const
Definition: filter_status.hpp:80
genesis::population::FilterStatus::set
void set(IntType value)
Definition: filter_status.hpp:100
genesis::population::to_string
std::string to_string(GenomeLocus const &locus)
Definition: function/genome_locus.hpp:52
genesis::population::FilterStatus::IntType
uint32_t IntType
Definition: filter_status.hpp:69
genesis::population::FilterStatus::reset
void reset(FilterTag value)
Definition: filter_status.hpp:128
genesis::population::FilterStatus::reset
void reset(IntType value)
Definition: filter_status.hpp:122
genesis::population::FilterStatus::reset
void reset()
Definition: filter_status.hpp:117
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::FilterStatus::passing
bool passing() const
Definition: filter_status.hpp:75