SpECTRE Documentation Coverage Report
Current view: top level - DataStructures - IndexIterator.hpp Hit Total Coverage
Commit: aabde07399ba7837e5db64eedfd0a21f31f96922 Lines: 8 14 57.1 %
Date: 2024-04-26 02:38:13
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines IndexIterator.
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <cstddef>
      10             : 
      11             : #include "DataStructures/Index.hpp"
      12             : 
      13             : /// \ingroup DataStructuresGroup
      14             : /// IndexIterator iterates over a unique set of Index.
      15             : ///
      16             : /// \example
      17             : /// \snippet Test_IndexIterator.cpp index_iterator_example
      18             : ///
      19             : /// Each integer of the Index will vary from 0 to extents[d] - 1,
      20             : /// with the lowest dimension varying the fastest.
      21             : template <std::size_t Dim>
      22           1 : class IndexIterator {
      23             :  public:
      24             :   /// Construct from an Index
      25           1 :   explicit IndexIterator(Index<Dim> extents);
      26             :   /// It does not make sense to default construct an IndexIterator
      27           1 :   IndexIterator() = delete;
      28             :   /// \cond HIDDEN_SYMBOLS
      29             :   ~IndexIterator() = default;
      30             :   /// @{
      31             :   /// No copy or move semantics
      32             :   IndexIterator(const IndexIterator<Dim>&) = delete;
      33             :   IndexIterator(IndexIterator<Dim>&&) = delete;
      34             :   IndexIterator<Dim>& operator=(const IndexIterator<Dim>&) = delete;
      35             :   IndexIterator<Dim>& operator=(IndexIterator<Dim>&&) = delete;
      36             :   /// @}
      37             :   /// \endcond
      38             : 
      39             :   /// Returns false if the end of the Index iteration is reached
      40           1 :   explicit operator bool() const { return valid_; }
      41             : 
      42             :   /// Advance to next Index.
      43           1 :   IndexIterator<Dim>& operator++();
      44             : 
      45           0 :   const Index<Dim>& operator*() const { return index_; }
      46           0 :   const Index<Dim>* operator->() const { return &index_; }
      47             : 
      48             :   /// Returns an index representing the (i, j, ...)th values that the iterator
      49             :   /// currently represents
      50           1 :   const Index<Dim>& operator()() const { return index_; }
      51             : 
      52             :   /// Get the collapsed index into a 1D array of the data corresponding to the
      53             :   /// current Index of the IndexIterator. Note that the first dimension of the
      54             :   /// Index varies fastest when computing the collapsed index.
      55           1 :   size_t collapsed_index() const { return collapsed_index_; }
      56             : 
      57             :  private:
      58           0 :   const Index<Dim> extents_{};
      59           0 :   Index<Dim> index_{};
      60           0 :   size_t collapsed_index_{0};
      61           0 :   bool valid_{false};
      62             : };

Generated by: LCOV version 1.14