mmiteratorinterface.hh 2.01 KB
Newer Older
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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MULTIMESH_ITERATOR_INTERFACE_HH
#define DUNE_MULTIMESH_ITERATOR_INTERFACE_HH

#include <dune/common/iteratorfacades.hh>
#include <dune/grid/common/exceptions.hh>

#include "mmentity.hh"

namespace Dune
{
  namespace tag
  {
    struct begin_iterator {};
    struct end_iterator {};
  }

  class DummyIterator
  {
  public:
    template <class... Args>
    DummyIterator(Args&&... args)
    {
      DUNE_THROW(NotImplemented, "Not implemented for entity of codim != 0!");
    }

    int operator*() const { return 0; }
    DummyIterator& operator++() { return *this; }
    DummyIterator operator++(int) { return *this; }
    bool operator!=(const DummyIterator&) const { return false; }
  };


  /** \brief Iterator over all entities of a given codimension and level of a grid.
   *  \ingroup MultiMesh
   *
   *  Implemented for codim 0 entities only
   */
  template <class HostGrid, class Derived>
  class MultiMeshIteratorInterface
      : public ForwardIteratorFacade<Derived, MultiEntity<HostGrid>, const MultiEntity<HostGrid>&>
  {
    using HostEntity = typename HostGrid::template Codim<0>::Entity;

  public:

    void initialIncrement ()
    {
      derived().initialIncrement_impl();
    }

    /// prefix increment
    void increment ()
    {
      derived().increment_impl();
    }

    /// dereferencing
    const MultiEntity<HostGrid>& dereference () const
    {
      return derived().dereference_impl();
    }

    /// equality
    template <class Iterator>
    bool equals (const Iterator& that) const
    {
      return derived().equals_impl(that);
    }

    bool levelReached (std::size_t i, const HostEntity& entity) const
    {
      return derived().levelReached_impl(i, entity);
    }

  private:
    const Derived& derived() const { return static_cast<const Derived&>(*this); }
    Derived& derived() { return static_cast<Derived&>(*this); }
  };

}  // end namespace Dune

#endif // DUNE_MULTIMESH_ITERATOR_INTERFACE_HH