dune-istl  2.3.1
dependency.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // $Id$
4 #ifndef DUNE_AMG_DEPENDENCY_HH
5 #define DUNE_AMG_DEPENDENCY_HH
6 
7 
8 #include <bitset>
9 #include <ostream>
10 
11 #include "graph.hh"
12 #include "properties.hh"
13 #include <dune/common/propertymap.hh>
14 #include <dune/common/unused.hh>
15 
16 
17 namespace Dune
18 {
19  namespace Amg
20  {
39  {
40  friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
41  public:
43  enum {INFLUENCE, DEPEND, SIZE};
44 
45  private:
46 
47  std::bitset<SIZE> flags_;
48  public:
51 
53  std::bitset<SIZE>::reference operator[](std::size_t v);
54 
56  bool operator[](std::size_t v) const;
57 
63  bool depends() const;
64 
69  void setDepends();
70 
74  void resetDepends();
75 
80  bool influences() const;
81 
85  void setInfluences();
86 
90  void resetInfluences();
91 
96  bool isOneWay() const;
97 
102  bool isTwoWay() const;
103 
108  bool isStrong() const;
109 
113  void reset();
114 
118  void printFlags() const;
119  };
120 
127  friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
128  public:
130  private:
131 
133  std::bitset<SIZE> flags_;
134 
135  public:
138 
140  std::bitset<SIZE>::reference operator[](std::size_t v);
141 
143  bool operator[](std::size_t v) const;
144 
151  void setIsolated();
152 
156  bool isolated() const;
157 
161  void resetIsolated();
162 
166  void setVisited();
167 
171  bool visited() const;
172 
176  void resetVisited();
177 
181  void setFront();
182 
186  bool front() const;
187 
191  void resetFront();
192 
196  void setExcludedBorder();
197 
202  bool excludedBorder() const;
203 
207  void resetExcludedBorder();
208 
212  void reset();
213 
214  };
215 
216  template<typename G, std::size_t i>
218  : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
219  PropertyGraphVertexPropertyMap<G,i> >
220  {
221  public:
222 
223  typedef ReadWritePropertyMapTag Category;
224 
225  enum {
227  index = i
228  };
229 
233  typedef G Graph;
234 
238  typedef std::bitset<VertexProperties::SIZE> BitSet;
239 
243  typedef typename BitSet::reference Reference;
244 
248  typedef bool ValueType;
249 
253  typedef typename G::VertexDescriptor Vertex;
254 
260  : graph_(&g)
261  {}
262 
267  : graph_(0)
268  {}
269 
270 
275  Reference operator[](const Vertex& vertex) const
276  {
277  return graph_->getVertexProperties(vertex)[index];
278  }
279  private:
280  Graph* graph_;
281  };
282 
283  } // end namespace Amg
284 
285  template<typename G, typename EP, typename VM, typename EM>
286  struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
287  {
289  };
290 
291  template<typename G, typename EP, typename VM, typename EM>
292  typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
294  {
295  DUNE_UNUSED_PARAMETER(tag);
297  }
298 
299  namespace Amg
300  {
301  inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
302  {
303  return os << props.flags_;
304  }
305 
307  : flags_()
308  {}
309 
310  inline std::bitset<EdgeProperties::SIZE>::reference
312  {
313  return flags_[v];
314  }
315 
316  inline bool EdgeProperties::operator[](std::size_t i) const
317  {
318  return flags_[i];
319  }
320 
321  inline void EdgeProperties::reset()
322  {
323  flags_.reset();
324  }
325 
327  {
328  // Set the INFLUENCE bit
329  //flags_ |= (1<<INFLUENCE);
330  flags_.set(INFLUENCE);
331  }
332 
333  inline bool EdgeProperties::influences() const
334  {
335  // Test the INFLUENCE bit
336  return flags_.test(INFLUENCE);
337  }
338 
340  {
341  // Set the first bit.
342  //flags_ |= (1<<DEPEND);
343  flags_.set(DEPEND);
344  }
345 
347  {
348  // reset the first bit.
349  //flags_ &= ~(1<<DEPEND);
350  flags_.reset(DEPEND);
351  }
352 
353  inline bool EdgeProperties::depends() const
354  {
355  // Return the first bit.
356  return flags_.test(DEPEND);
357  }
358 
360  {
361  // reset the second bit.
362  flags_ &= ~(1<<INFLUENCE);
363  }
364 
365  inline bool EdgeProperties::isOneWay() const
366  {
367  // Test whether only the first bit is set
368  //return isStrong() && !isTwoWay();
369  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
370  }
371 
372  inline bool EdgeProperties::isTwoWay() const
373  {
374  // Test whether the first and second bit is set
375  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
376  }
377 
378  inline bool EdgeProperties::isStrong() const
379  {
380  // Test whether the first or second bit is set
381  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
382  }
383 
384 
385  inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
386  {
387  return os << props.flags_;
388  }
389 
391  : flags_()
392  {}
393 
394 
395  inline std::bitset<VertexProperties::SIZE>::reference
397  {
398  return flags_[v];
399  }
400 
401  inline bool VertexProperties::operator[](std::size_t v) const
402  {
403  return flags_[v];
404  }
405 
407  {
408  flags_.set(ISOLATED);
409  }
410 
411  inline bool VertexProperties::isolated() const
412  {
413  return flags_.test(ISOLATED);
414  }
415 
417  {
418  flags_.reset(ISOLATED);
419  }
420 
422  {
423  flags_.set(VISITED);
424  }
425 
426  inline bool VertexProperties::visited() const
427  {
428  return flags_.test(VISITED);
429  }
430 
432  {
433  flags_.reset(VISITED);
434  }
435 
437  {
438  flags_.set(FRONT);
439  }
440 
441  inline bool VertexProperties::front() const
442  {
443  return flags_.test(FRONT);
444  }
445 
447  {
448  flags_.reset(FRONT);
449  }
450 
452  {
453  flags_.set(BORDER);
454  }
455 
457  {
458  return flags_.test(BORDER);
459  }
460 
462  {
463  flags_.reset(BORDER);
464  }
465 
467  {
468  flags_.reset();
469  }
470 
472  }
473 }
474 #endif