/*------------------------------------------------------------------------------ * Copyright (c) 2023 by Bai Bing (seread@163.com) * S++ COPYING file for copying and redistribution conditions. * * Alians IT Studio. *----------------------------------------------------------------------------*/ #pragma once #include #include #include #include "_Define.h" namespace ais { //================================================================================ /// A Class for slicing class AIS_EXPORT Slice { public: //====================================Attributes============================== size_t start{0}; size_t stop{1}; size_t step{1}; //============================================================================ /// Constructor /// constexpr Slice() = default; //============================================================================ /// Constructor /// /// @param stop (index not included) /// constexpr explicit Slice(size_t stop) noexcept : stop(stop) {} //============================================================================ /// Constructor /// /// @param start /// @param stop (index not included) /// constexpr Slice(size_t start, size_t stop) noexcept : start(start), stop(stop) {} //============================================================================ /// Constructor /// /// @param start /// @param stop (not included) /// @param step /// constexpr Slice(size_t start, size_t stop, size_t step) noexcept : start(start), stop(stop), step(step) {} //============================================================================ /// Equality operator /// /// @param otherSlice /// /// @return bool /// bool operator==(const Slice &otherSlice) const noexcept; //============================================================================ /// Not equality operator /// /// @param otherSlice /// /// @return bool /// bool operator!=(const Slice &otherSlice) const noexcept; //============================================================================ /// Prints the shape to the console /// /// @return std::string /// std::string str() const; //============================================================================ /// Prints the shape to the console /// void print() const; //============================================================================ /// Make the slice all positive and does some error checking /// /// @param arraySize /// void make_positive_and_validate(size_t arraySize); //============================================================================ /// Returns the number of elements that the slice contains. /// be aware that this method will also make the slice all /// positive! /// /// @param arraySize /// size_t element_number(size_t arraySize); //============================================================================ /// IO operator for the Slice class /// /// @param stream /// @param slice /// /// @return std::ostream /// friend std::ostream &operator<<(std::ostream &stream, const Slice &slice) { stream << slice.str(); return stream; } }; } // namespace ais