Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @file 4 : /// @author Owen Arnold 5 : #include "scipp-core_export.h" 6 : #include "scipp/common/index.h" 7 : #include "scipp/units/dim.h" 8 : 9 : #pragma once 10 : 11 : namespace scipp::core { 12 : 13 : /// Describes a slice to make over a dimension either as a single index or as a 14 : /// range 15 : class SCIPP_CORE_EXPORT Slice { 16 : public: 17 3081016 : Slice() : m_dim(Dim::None), m_begin(-1), m_end(-1), m_stride(1) {} 18 : Slice(const Dim dim_, const scipp::index begin_, const scipp::index end_, 19 : const scipp::index stride_ = 1); 20 : Slice(const Dim dim_, const scipp::index begin_); 21 : Slice(const Slice &) = default; 22 : Slice &operator=(const Slice &) = default; 23 : bool operator==(const Slice &other) const noexcept; 24 : bool operator!=(const Slice &other) const noexcept; 25 2338355 : scipp::index begin() const noexcept { return m_begin; } 26 5148532 : scipp::index end() const noexcept { return m_end; } 27 7697918 : Dim dim() const noexcept { return m_dim; } 28 2214359 : scipp::index stride() const noexcept { return m_stride; } 29 713408 : bool isRange() const noexcept { return m_end != -1; } 30 : 31 : private: 32 : Dim m_dim; 33 : scipp::index m_begin; 34 : scipp::index m_end; 35 : scipp::index m_stride; 36 : }; 37 : 38 : } // namespace scipp::core 39 : 40 : namespace scipp { 41 : using core::Slice; 42 : } // namespace scipp