Skip to content
Snippets Groups Projects
Select Git revision
  • 31fefbeb01ea64ec182c2cca07cae6cdc5e04932
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

H5Attribute_misc.hpp

Blame
  • ShrinkVectorView.hpp 1.38 KiB
    #ifndef SHRINK_VECTOR_VIEW_HPP
    #define SHRINK_VECTOR_VIEW_HPP
    
    #include <utils/PugsAssert.hpp>
    #include <utils/PugsMacros.hpp>
    
    #include <cstddef>
    #include <iostream>
    #include <utils/NaNHelper.hpp>
    
    template <typename VectorType>
    class ShrinkVectorView
    {
     public:
      using index_type = typename VectorType::index_type;
      using data_type  = typename VectorType::data_type;
    
     private:
      VectorType& m_vector;
      const size_t m_dimension;
    
     public:
      friend std::ostream&
      operator<<(std::ostream& os, const ShrinkVectorView& x)
      {
        if (x.size() > 0) {
          os << 0 << ':' << NaNHelper(x[0]);
        }
        for (size_t i = 1; i < x.size(); ++i) {
          os << ' ' << i << ':' << NaNHelper(x[i]);
        }
        return os;
      }
    
      PUGS_INLINE size_t
      dimension() const noexcept
      {
        return m_dimension;
      }
    
      PUGS_INLINE
      data_type&
      operator[](index_type i) const noexcept(NO_ASSERT)
      {
        Assert(i < m_dimension, "cannot access element: invalid indices");
        return m_vector[i];
      }
    
      ShrinkVectorView(VectorType& vector, size_t dimension) noexcept(NO_ASSERT) : m_vector{vector}, m_dimension{dimension}
      {
        Assert(m_dimension <= vector.dimension(), "shrink number of rows must be smaller than original vector's");
      }
    
      ShrinkVectorView(const ShrinkVectorView&) = delete;
      ShrinkVectorView(ShrinkVectorView&&)      = delete;
    
      ~ShrinkVectorView() noexcept = default;
    };
    
    #endif   // SHRINK_VECTOR_VIEW_HPP