• Docs >
  • Program Listing for File static_multidim_space.hpp
Shortcuts

Program Listing for File static_multidim_space.hpp

Return to documentation for file (include/ripple/space/static_multidim_space.hpp)

#ifndef RIPPLE_SPACE_STATIC_MULTIDIM_SPACE_HPP
#define RIPPLE_SPACE_STATIC_MULTIDIM_SPACE_HPP

#include "multidim_space.hpp"

namespace ripple {

template <size_t... Sizes>
struct StaticMultidimSpace
: public MultidimSpace<StaticMultidimSpace<Sizes...>> {
 private:
  static constexpr size_t dims = sizeof...(Sizes);

  size_t padding_ = 0;

 public:
  constexpr StaticMultidimSpace() = default;

  ripple_all constexpr StaticMultidimSpace(size_t padding) noexcept
  : padding_{padding} {}

  ripple_all constexpr auto padding() noexcept -> size_t& {
    return padding_;
  }

  ripple_all constexpr auto padding() const noexcept -> size_t {
    return padding_;
  }

  ripple_all constexpr auto dim_padding() const noexcept -> size_t {
    return padding_ * 2;
  }

  ripple_all constexpr auto dimensions() const noexcept -> size_t {
    return dims;
  }

  ripple_all constexpr auto size() const noexcept -> size_t {
    return ((Sizes + dim_padding()) * ... * size_t{1});
  }

  template <typename Dim>
  ripple_all constexpr auto size(Dim&& dim) const noexcept -> size_t {
    constexpr size_t sizes[dims] = {Sizes...};
    return sizes[dim] + dim_padding();
  }

  template <typename Dim>
  ripple_all constexpr auto
  internal_size(Dim&& dim) const noexcept -> size_t {
    constexpr size_t sizes[dims] = {Sizes...};
    return sizes[dim];
  }

  ripple_all constexpr auto internal_size() const noexcept -> size_t {
    return (Sizes * ... * size_t{1});
  }

  template <typename Dim>
  ripple_all constexpr auto step(Dim&& dim) const noexcept -> size_t {
    constexpr size_t sizes[dims] = {Sizes...};
    size_t           res         = 1;
    for (size_t i = 0; i < static_cast<size_t>(dim); ++i) {
      res *= sizes[i] + dim_padding();
    }
    return res;
  }
};

} // namespace ripple

#endif // RIPPLE_SPACE_STATIC_MULTIDIM_SPACE_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples