Loading...
Searching...
No Matches
enumset.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_ENUMSET_HH
#define DUNE_ENUMSET_HH
#include <iostream>
namespace Dune
{
template<typename TA>
class EmptySet
{
public:
typedef TA Type;
static bool contains(const Type& attribute);
};
template<typename TA>
class AllSet
{
public:
typedef TA Type;
static bool contains(const Type& attribute);
};
template<typename TA, int item>
class EnumItem
{
public:
typedef TA Type;
static bool contains(const Type& attribute);
};
template<typename TA,int from, int end>
class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
{
public:
typedef TA Type;
static bool contains(const Type& item);
};
template<typename S>
class NegateSet
{
public:
typedef typename S::Type Type;
static bool contains(const Type& item)
{
return !S::contains(item);
}
};
template<class TI1, class TI2, typename TA=typename TI1::Type>
class Combine
{
public:
static bool contains(const TA& item);
};
template<typename TA>
inline bool EmptySet<TA>::contains([[maybe_unused]] const Type& attribute)
{
return false;
}
template<typename TA>
inline bool AllSet<TA>::contains([[maybe_unused]] const Type& attribute)
{
return true;
}
template<typename TA,int i>
inline bool EnumItem<TA,i>::contains(const Type& item)
{
return item==i;
}
template<typename TA,int i>
inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
{
return os<<i;
}
template<typename TA, int from, int to>
inline bool EnumRange<TA,from,to>::contains(const Type& item)
{
return from<=item && item<=to;
}
template<typename TA, int from, int to>
inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
{
return os<<"["<<from<<" - "<<to<<"]";
}
template<class TI1, class TI2, typename TA>
inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
{
return TI1::contains(item) ||
TI2::contains(item);
}
template<class TI1, class TI2>
inline Combine<TI1,TI2,typename TI1::Type> combine([[maybe_unused]] const TI1& set1,
[[maybe_unused]] const TI2& set2)
{
return Combine<TI1,TI2,typename TI1::Type>();
}
template<class TI1, class TI2, class T>
inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
{
return os << TI1()<<" "<<TI2();
}
}
#endif
Dune::AllSet::contains
static bool contains(const Type &attribute)
Always returns true.
Definition enumset.hh:123
Dune::EnumRange::contains
static bool contains(const Type &item)
Definition enumset.hh:141
Dune::Combine::contains
static bool contains(const TA &item)
Definition enumset.hh:153
Dune::EmptySet::contains
static bool contains(const Type &attribute)
Always returns false.
Definition enumset.hh:117
Dune::EnumItem::contains
static bool contains(const Type &attribute)
Tests whether an item is in the set.
Definition enumset.hh:129
Dune::combine
Combine< TI1, TI2, typename TI1::Type > combine(const TI1 &set1, const TI2 &set2)
Definition enumset.hh:160
Dune::operator<<
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition bigunsignedint.hh:301
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::EmptySet
An empty set.
Definition enumset.hh:27
Dune::EmptySet::Type
TA Type
The POD type the set holds.
Definition enumset.hh:32
Dune::AllSet
A set containing everything.
Definition enumset.hh:44
Dune::AllSet::Type
TA Type
The POD type the set holds.
Definition enumset.hh:49
Dune::EnumItem
A set consisting only of one item.
Definition enumset.hh:61
Dune::EnumItem::Type
TA Type
The type the set holds.
Definition enumset.hh:66
Dune::EnumRange
A set representing a range including the borders.
Definition enumset.hh:80
Dune::EnumRange::Type
TA Type
The type the set holds.
Definition enumset.hh:85
Dune::NegateSet
The negation of a set. An item is contained in the set if and only if it is not contained in the nega...
Definition enumset.hh:96
Dune::NegateSet::Type
S::Type Type
Definition enumset.hh:98
Dune::NegateSet::contains
static bool contains(const Type &item)
Definition enumset.hh:100
Dune::Combine
A set combining two other sets.
Definition enumset.hh:111