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
85
86
87
// *****************************************************************************
/*!
  \file      src/Mesh/Around.hpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Helper class for iterating through linked lists of derived data
  \details   Helper class for iterating through every item in a linked list data
    structure derived from unstructured mesh connectivity.
  \see src/Mesh/DerivedData.h
*/
// *****************************************************************************
#ifndef Around_h
#define Around_h

#include <vector><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <map><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <utility><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstddef><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "Types.hpp"
#include "Fields.hpp"
#include "UnsMesh.hpp"

namespace tk {

//! \brief Helper class simplifying client code for iterating on entries
//!   surrounding entries via linked lists derived from unstructured mesh
//!   connectivity
class Around {

  private:
    //! Linked list type: T1: item list, T2: index list
    using List =
      std::pair< std::vector< std::size_t >, std::vector< std::size_t > >;

    //! Non-const iterator to the item list in List::T1
    using iterator = List::first_type::iterator;

    //! Const iterator to the item list in List::T1
    using const_iterator = List::first_type::const_iterator;

    //! Difference type for iterator/pointer arithmetics
    using diff_type = List::first_type::difference_type;

  public:
    //! Constructor
    //! \param[in] list Linked list (vectors) storing derived data
    //! \param[in] idx Index of entry whose surrounding items we will iterate on
    explicit Around( const List& list, std::size_t idx ) :
      m_list( list ), m_idx( idx ) {}

    //! Const iterator to the beginning of the entries of surrounding entries
    //! \return Iterator to the beginning of the entries of surrounding entries
    //! \note This class does not allow modifing the underlying linked list, so
    //!   the begin/end iterators are aliased to cbegin/cend.
    const_iterator begin() const noexcept { return this->cbegin(); }

    //! Const iterator to the entry after the last of the surrounding entries
    //! \return Iterator to the entry after the last of the surrounding entries
    //! \note This class does not allow modifing the underlying linked list, so
    //!   the begin/end iterators are aliased to cbegin/cend.
    const_iterator end() const noexcept { return this->cend(); }

    //! Iterator to the beginning of the entries of surrounding entries
    //! \return Iterator to the beginning of the entries of surrounding entries
    const_iterator cbegin() const noexcept {
      return m_list.first.cbegin() +
             static_cast< diff_type >( m_list.second[m_idx] + 1 );
    }

    //! Iterator to the entry after the last of the surrounding entries
    //! \return Iterator to the entry after the last of the surrounding entries
    const_iterator cend() const noexcept {
      return m_list.first.cbegin() +
             static_cast< diff_type >( m_list.second[m_idx+1] + 1 );
    }

  private:
    const List& m_list; //!< Linked list to iterate in
    std::size_t m_idx;  //!< Index whose surrounding entries to iterate on
};

} // tk::

#endif // Around_h