rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
dynamic_subscript.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include <array>
6#include <ostream>
7#include <cstddef>
8
9#include "subscript_tags.hpp"
10#include "slice.hpp"
11#include "index.hpp"
12#include "../platform/attributes.hpp"
13#include "../platform/cpp_explicit.hpp"
14
15namespace rexlib
16{
17
18
30{
31public:
36 enum class subscript_type
37 {
40 index,
41 slice
42 };
43
48 REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR
50
55 REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR
57
64 REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR
65 dynamic_subscript(std::ptrdiff_t index) noexcept;
66
73 REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR
74 dynamic_subscript(const slice &slice) noexcept;
75
76 dynamic_subscript(const dynamic_subscript &other) = default;
77 dynamic_subscript(dynamic_subscript &&other) = default;
78 ~dynamic_subscript() = default;
79
80 dynamic_subscript& operator=(const dynamic_subscript &other) = default;
81 dynamic_subscript& operator=(dynamic_subscript &&other) = default;
82
88 REXLIB_CONSTEXPR
90
100 std::ptrdiff_t get_index() const;
101
112
113 template <typename T>
114 friend std::basic_ostream<T>& operator<<(
115 std::basic_ostream<T>& os,
116 const dynamic_subscript &subscript
117 )
118 {
119 os << "dynamic_subscript(";
120 visit(
121 [&os] (auto x)
122 {
123 os << x;
124 },
125 subscript
126 );
127 return os << ")";
128 }
129
130private:
131 using storage_type = std::array<std::ptrdiff_t, 3>;
132
133 storage_type m_data; // When holding index, first value is used.
134 subscript_type m_type;
135};
136
138 : public std::logic_error
139{
140public:
141 using std::logic_error::logic_error;
142};
143
159template <typename F>
160REXLIB_CONSTEXPR
162
163} // namespace rexlib
164
165#include "dynamic_subscript.inl"
Container for multidimensional numeric data.
Definition array.hpp:31
Definition dynamic_subscript.hpp:139
Class describing a runtime defined subscript.
Definition dynamic_subscript.hpp:30
REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR dynamic_subscript(new_axis_tag) noexcept
Construct a dynamic_subscript holding a new_axis_tag.
std::ptrdiff_t get_index() const
Get the index.
subscript_type
Enumeration holding the types this object can hold.
Definition dynamic_subscript.hpp:37
REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR dynamic_subscript(ellipsis_tag) noexcept
Construct a dynamic_subscript holding an ellipsis_tag.
REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR dynamic_subscript(std::ptrdiff_t index) noexcept
Construct a dynamic_subscript holding an index.
REXLIB_CONSTEXPR subscript_type get_subscript_type() const noexcept
Get the subscript type held by this object.
slice get_slice() const
Get the slice.
REXLIB_NO_EXPLICIT REXLIB_CONSTEXPR dynamic_subscript(const slice &slice) noexcept
Construct a dynamic_subscript holding a slice.
Class representing an slice of an array.
Definition slice.hpp:22
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
REXLIB_CONSTEXPR ellipsis_tag ellipsis() noexcept
Construct an ellipsis_tag.
REXLIB_CONSTEXPR new_axis_tag new_axis() noexcept
Construct a new_axis_tag.
REXLIB_CONSTEXPR auto visit(F &&func, const dynamic_subscript &subscript)
Invoke the provided function with the value held by the dynamic subscript.
Tag to express the consumption of an arbitrary amount of axes until no slack is left on the right-han...
Definition subscript_tags.hpp:22
Tag to express the creation a new axis of size one.
Definition subscript_tags.hpp:58