dune-istl  2.2.0
dependency.hh
Go to the documentation of this file.
1 // $Id: dependency.hh 1296 2010-10-01 14:40:21Z robertk $
2 #ifndef DUNE_AMG_DEPENDENCY_HH
3 #define DUNE_AMG_DEPENDENCY_HH
4 
5 
6 #include<bitset>
7 #include<ostream>
8 
9 #include "graph.hh"
10 #include "properties.hh"
11 #include <dune/common/propertymap.hh>
12 
13 
14 namespace Dune
15 {
16  namespace Amg
17  {
36  {
37  friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
38  public:
41 
42  private:
43 
44  std::bitset<SIZE> flags_;
45  public:
48 
50  std::bitset<SIZE>::reference operator[](std::size_t v);
51 
53  bool operator[](std::size_t v)const;
54 
60  bool depends() const;
61 
66  void setDepends();
67 
71  void resetDepends();
72 
77  bool influences() const;
78 
82  void setInfluences();
83 
87  void resetInfluences();
88 
93  bool isOneWay() const;
94 
99  bool isTwoWay() const;
100 
105  bool isStrong() const;
106 
110  void reset();
111 
115  void printFlags() const;
116  };
117 
124  friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
125  public:
127  private:
128 
130  std::bitset<SIZE> flags_;
131 
132  public:
135 
137  std::bitset<SIZE>::reference operator[](std::size_t v);
138 
140  bool operator[](std::size_t v) const;
141 
148  void setIsolated();
149 
153  bool isolated() const;
154 
158  void resetIsolated();
159 
163  void setVisited();
164 
168  bool visited() const;
169 
173  void resetVisited();
174 
178  void setFront();
179 
183  bool front() const;
184 
188  void resetFront();
189 
193  void setExcludedBorder();
194 
199  bool excludedBorder() const;
200 
204  void resetExcludedBorder();
205 
209  void reset();
210 
211  };
212 
213  template<typename G, std::size_t i>
215  : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
216  PropertyGraphVertexPropertyMap<G,i> >
217  {
218  public:
219 
220  typedef ReadWritePropertyMapTag Category;
221 
222  enum{
224  index = i
225  };
226 
230  typedef G Graph;
231 
235  typedef std::bitset<VertexProperties::SIZE> BitSet;
236 
240  typedef typename BitSet::reference Reference;
241 
245  typedef bool ValueType;
246 
250  typedef typename G::VertexDescriptor Vertex;
251 
257  : graph_(&g)
258  {}
259 
264  :graph_(0)
265  {}
266 
267 
272  Reference operator[](const Vertex& vertex) const
273  {
274  return graph_->getVertexProperties(vertex)[index];
275  }
276  private:
277  Graph* graph_;
278  };
279 
280  } // end namespace Amg
281 
282  template<typename G, typename EP, typename VM, typename EM>
283  struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
284  {
286  };
287 
288  template<typename G, typename EP, typename VM, typename EM>
289  typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
291  {
293  }
294 
295  namespace Amg
296  {
297  inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
298  {
299  return os << props.flags_;
300  }
301 
303  : flags_()
304  {}
305 
306  inline std::bitset<EdgeProperties::SIZE>::reference
308  {
309  return flags_[v];
310  }
311 
312  inline bool EdgeProperties::operator[](std::size_t i) const
313  {
314  return flags_[i];
315  }
316 
317  inline void EdgeProperties::reset()
318  {
319  flags_.reset();
320  }
321 
323  {
324  // Set the INFLUENCE bit
325  //flags_ |= (1<<INFLUENCE);
326  flags_.set(INFLUENCE);
327  }
328 
329  inline bool EdgeProperties::influences() const
330  {
331  // Test the INFLUENCE bit
332  return flags_.test(INFLUENCE);
333  }
334 
336  {
337  // Set the first bit.
338  //flags_ |= (1<<DEPEND);
339  flags_.set(DEPEND);
340  }
341 
343  {
344  // reset the first bit.
345  //flags_ &= ~(1<<DEPEND);
346  flags_.reset(DEPEND);
347  }
348 
349  inline bool EdgeProperties::depends() const
350  {
351  // Return the first bit.
352  return flags_.test(DEPEND);
353  }
354 
356  {
357  // reset the second bit.
358  flags_ &= ~(1<<INFLUENCE);
359  }
360 
361  inline bool EdgeProperties::isOneWay() const
362  {
363  // Test whether only the first bit is set
364  //return isStrong() && !isTwoWay();
365  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
366  }
367 
368  inline bool EdgeProperties::isTwoWay() const
369  {
370  // Test whether the first and second bit is set
371  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
372  }
373 
374  inline bool EdgeProperties::isStrong() const
375  {
376  // Test whether the first or second bit is set
377  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
378  }
379 
380 
381  inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
382  {
383  return os << props.flags_;
384  }
385 
387  : flags_()
388  {}
389 
390 
391  inline std::bitset<VertexProperties::SIZE>::reference
393  {
394  return flags_[v];
395  }
396 
397  inline bool VertexProperties::operator[](std::size_t v) const
398  {
399  return flags_[v];
400  }
401 
403  {
404  flags_.set(ISOLATED);
405  }
406 
407  inline bool VertexProperties::isolated() const
408  {
409  return flags_.test(ISOLATED);
410  }
411 
413  {
414  flags_.reset(ISOLATED);
415  }
416 
418  {
419  flags_.set(VISITED);
420  }
421 
422  inline bool VertexProperties::visited() const
423  {
424  return flags_.test(VISITED);
425  }
426 
428  {
429  flags_.reset(VISITED);
430  }
431 
433  {
434  flags_.set(FRONT);
435  }
436 
437  inline bool VertexProperties::front() const
438  {
439  return flags_.test(FRONT);
440  }
441 
443  {
444  flags_.reset(FRONT);
445  }
446 
448  {
449  flags_.set(BORDER);
450  }
451 
453  {
454  return flags_.test(BORDER);
455  }
456 
458  {
459  flags_.reset(BORDER);
460  }
461 
463  {
464  flags_.reset();
465  }
466 
468  }
469 }
470 #endif