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

Program Listing for File storage_accessor.hpp

Return to documentation for file (include/ripple/storage/storage_accessor.hpp)

#ifndef RIPPLE_STORAGE_STORAGE_ACCESSOR_HPP
#define RIPPLE_STORAGE_STORAGE_ACCESSOR_HPP

#include "storage_traits.hpp"
#include <ripple/algorithm/unrolled_for.hpp>

namespace ripple {

template <typename Impl>
struct StorageAccessor {
 private:
  ripple_all constexpr auto impl() const noexcept -> const Impl* {
    return static_cast<const Impl*>(this);
  }

  ripple_all constexpr auto impl() noexcept -> Impl* {
    return static_cast<Impl*>(this);
  }

 public:
  template <typename Other>
  ripple_all auto copy(const Other& other) noexcept -> void {
    impl()->copy(other);
  }

  template <size_t I>
  ripple_all constexpr auto components_of() const noexcept -> size_t {
    return impl()->template components_of<I>();
  }

  template <size_t I>
  ripple_all decltype(auto) get() noexcept {
    return impl()->template get<I>();
  }

  template <size_t I>
  ripple_all decltype(auto) get() const noexcept {
    return impl()->template get<I>();
  }

  template <size_t I, size_t J>
  ripple_all decltype(auto) get() noexcept {
    return impl()->template get<I, J>();
  }

  template <size_t I, size_t J>
  ripple_all decltype(auto) get() const noexcept {
    return impl()->template get<I, J>();
  }

  template <size_t I>
  ripple_all decltype(auto) get(size_t j) noexcept {
    return impl()->get<I>(j);
  }

  template <size_t I>
  ripple_all decltype(auto) get(size_t j) const noexcept {
    return impl()->get<I>(j);
  }
};

/*==--- [utilities] --------------------------------------------------------==*/

template <
  size_t I,
  size_t Values,
  typename TypeI,
  typename ImplFrom,
  typename ImplTo,
  vec_element_enable_t<TypeI> = 0>
ripple_all auto
copy_from_to(const ImplFrom& from, ImplTo& to) noexcept -> void {
  unrolled_for<Values>([&](auto j) {
    constexpr auto J        = size_t{j};
    to.template get<I, J>() = from.template get<I, J>();
  });
}

template <
  size_t I,
  size_t Values,
  typename TypeI,
  typename ImplFrom,
  typename ImplTo,
  non_vec_element_enable_t<TypeI> = 0>
ripple_all auto copy_from_to(const ImplFrom& from, ImplTo& to) -> void {
  to.template get<I>() = from.template get<I>();
}

} // namespace ripple

#endif // RIPPLE_STORAGE_STORAGE_ACCESSOR_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