1#ifndef DUNE_MULTIDOMAINGRID_SINGLEVALUESET_HH
2#define DUNE_MULTIDOMAINGRID_SINGLEVALUESET_HH
7#include <dune/common/typetraits.hh>
8#include <dune/common/exceptions.hh>
22bool setContains(
const SingleValueSet<SI>& a,
23 const SingleValueSet<SI>& b);
27void setAdd(SingleValueSet<SI>& a,
28 const SingleValueSet<SI>& b);
34 friend bool setContains<>(
const SingleValueSet<SI>& a,
35 const SingleValueSet<SI>& b);
37 friend void setAdd<>(SingleValueSet<SI>& a,
38 const SingleValueSet<SI>& b);
42 typedef SI SubDomainIndex;
44 static const std::size_t maxSize = 1;
45 static const SubDomainIndex emptyTag = ~SubDomainIndex(0);
46 typedef const SubDomainIndex* Iterator;
47 typedef SingleValueSet<SubDomainIndex> This;
49 enum SetState {emptySet,simpleSet,multipleSet};
53 typedef SubDomainIndex DataType;
55 static bool fixedSize(
int dim,
int codim)
60 static std::size_t size(
const SingleValueSet& sds)
65 template<
typename MessageBufferImp>
66 static void gather(MessageBufferImp& buf,
const SingleValueSet& sds)
71 template<
typename MessageBufferImp>
72 static void scatter(MessageBufferImp& buf, SingleValueSet& sds, std::size_t n)
76 assert(sds._set == emptyTag || sds._set == i);
82 Iterator begin()
const {
86 Iterator end()
const {
87 return &_set + (_set != emptyTag ? 1 : 0);
90 bool contains(SubDomainIndex domain)
const {
91 return _set == domain;
94 template<
typename Set>
95 bool containsAll(
const Set& set)
const {
96 return setContains(*
this,set);
100 return _set != emptyTag;
104 return _set == emptyTag;
107 SetState state()
const {
108 return _set == emptyTag ? emptySet : simpleSet;
111 std::size_t size()
const {
112 return _set == emptyTag ? 0 : 1;
119 void add(SubDomainIndex domain) {
120 assert(_set == emptyTag || _set == domain);
124 void remove(SubDomainIndex domain) {
125 assert(_set == domain);
129 void set(SubDomainIndex domain) {
133 template<
typename Set>
134 void addAll(
const Set& set) {
138 int domainOffset(SubDomainIndex domain)
const {
139 assert(_set == domain);
154inline bool setContains(
const SingleValueSet<SI>& a,
155 const SingleValueSet<SI>& b) {
156 return a._set == b._set;
160inline void setAdd(SingleValueSet<SI>& a,
161 const SingleValueSet<SI>& b) {
162 assert(a._set == SingleValueSet<SI>::emptyTag || a._set == b._set);