MAJ pour upgrade pc backup
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#ifndef CATEGORY_HPP
|
||||
#define CATEGORY_HPP
|
||||
|
||||
#include "Criterion.hpp"
|
||||
#include "VoteScheme.hpp"
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace People {
|
||||
|
||||
template<typename T>
|
||||
concept CatEnum = std::is_enum_v<T> && (
|
||||
std::is_same_v<T, Region> ||
|
||||
std::is_same_v<T, TypeZone> ||
|
||||
std::is_same_v<T, TrancheAge> ||
|
||||
std::is_same_v<T, CategorieSocioPro> ||
|
||||
std::is_same_v<T, NiveauDiplome> ||
|
||||
std::is_same_v<T, Sexe>
|
||||
);
|
||||
|
||||
template<CatEnum... Crits>
|
||||
class Category
|
||||
{
|
||||
private:
|
||||
static_assert(sizeof...(Crits) > 0, "At least one criterion");
|
||||
std::tuple<Crits...> criteria;
|
||||
std::size_t pop;
|
||||
VoteScheme voteScheme;
|
||||
template<std::size_t I = 0, CatEnum C>
|
||||
bool hasCriterionImpl(C val) const
|
||||
{
|
||||
if constexpr (I < sizeof...(Crits))
|
||||
{
|
||||
using ElemType = std::tuple_element_t<I, std::tuple<Crits...>>;
|
||||
if constexpr (std::is_same_v<ElemType, C>)
|
||||
{
|
||||
if (std::get<I>(criteria) == val)
|
||||
return true;
|
||||
}
|
||||
return hasCriterionImpl<I + 1>(val);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public:
|
||||
// Constructeur : reçoit les valeurs brutes des enums
|
||||
Category(Crits... values, size_t p): criteria(values...), pop(p){}
|
||||
|
||||
std::size_t getPop() const {return pop;}
|
||||
|
||||
template<CatEnum C>
|
||||
bool hasCriterion(C val) const
|
||||
{
|
||||
return hasCriterionImpl(val);
|
||||
}
|
||||
|
||||
VoteScheme& getVoteScheme() {return voteScheme;}
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user