/usr/include/dune/common/enumset.hh is in libdune-common-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #ifndef DUNE_ENUMSET_HH
#define DUNE_ENUMSET_HH
#include<iostream>
namespace Dune
{
/**
* @file
* @brief Classes for building sets out of enumeration values.
* @author Markus Blatt
*/
/** @addtogroup Common
*
* @{
*/
/**
* @brief An empty set.
*/
template<typename TA>
class EmptySet
{
public:
/**
* @brief The POD type the set holds.
*/
typedef TA Type;
/**
* @brief Always returns false.
*/
static bool contains(const Type& attribute);
};
/**
* @brief An set containing everything.
*/
template<typename TA>
class AllSet
{
public:
/**
* @brief The POD type the set holds.
*/
typedef TA Type;
/**
* @brief Always returns false.
*/
static bool contains(const Type& attribute);
};
/**
* @brief A set consisting only of one item.
*/
template<typename TA, int item>
class EnumItem
{
public:
/**
* @brief The type the set holds.
*/
typedef TA Type;
/**
* @brief Tests whether an item is in the set.
* @return True if item==Type.
*/
static bool contains(const Type& attribute);
};
/**
* @brief A set representing a range including the borders.
*/
template<typename TA,int from, int end>
class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
{
public:
/**
* @brief The type the set holds.
*/
typedef TA Type;
static bool contains(const Type& item);
};
/**
* @brief The negation of a set.
* An item is contained in the set if and only if it is not
* contained in the negated set.
*/
template<typename S>
class NegateSet
{
public:
typedef typename S::Type Type;
static bool contains(const Type& item)
{
return !S::contains(item);
}
};
/**
* @brief A set combining two other sets.
*/
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(const Type& attribute)
{
return false;
}
template<typename TA>
inline bool AllSet<TA>::contains(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(const TI1& set1, 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
|