diff --git a/Control/CxxUtils/CxxUtils/Array.h b/Control/CxxUtils/CxxUtils/Array.h index 7d6eda7b4c6eb04f465c33dc9830e478c7a86095..6d3df24ef33971995a2f5d7228110cee81d28da2 100644 --- a/Control/CxxUtils/CxxUtils/Array.h +++ b/Control/CxxUtils/CxxUtils/Array.h @@ -46,9 +46,11 @@ namespace CxxUtils { -// Forward declaration. +// Forward declarations. template <unsigned int N> class ArrayIterator; +template <unsigned int N> +class WritableArray; //********************************************************************** @@ -245,6 +247,7 @@ protected: // These classes need to call the above protected constructor. friend class Array<N+1>; + friend WritableArray<N+1>; friend class ArrayIterator<N+1>; /// Pointer to the representation. @@ -358,6 +361,7 @@ protected: // This class needs to call the above protected constructor. friend class Array<1>; + friend class WritableArray<1>; /// Pointer to this array's single element. /// Null if this instance was created using the default constructor. @@ -663,7 +667,17 @@ public: * * Note that this operation is not available if @c N is 0. */ - WritableArray<N-1> operator[] (unsigned int i) const; + WritableArray<N-1> operator[] (unsigned int i); + + /** + * @brief Array indexing. + * @param i The desired index. Must be less than the array size + * along this dimension. + * @return The @a i'th @c N-1 dimensional subarray in the array. + * + * Note that this operation is not available if @c N is 0. + */ + Array<N-1> operator[] (unsigned int i) const; /** * @brief Return a direct pointer to array elements. diff --git a/Control/CxxUtils/CxxUtils/Array.icc b/Control/CxxUtils/CxxUtils/Array.icc index 2bfe08933f09e460aca022e2937f13c07da43379..07dec65cf34543b0dc0baf5e9c7a26cd1f7affdb 100644 --- a/Control/CxxUtils/CxxUtils/Array.icc +++ b/Control/CxxUtils/CxxUtils/Array.icc @@ -1,7 +1,7 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -709,7 +709,7 @@ WritableArray<N>::WritableArray (Arrayrep& rep) */ template <unsigned int N> inline -WritableArray<N-1> WritableArray<N>::operator[] (unsigned int i) const +WritableArray<N-1> WritableArray<N>::operator[] (unsigned int i) { assert (i < this->m_rep_nc->m_shape[this->m_rep_nc->m_shape.size() - N]); return WritableArray<N-1> (*this->m_rep_nc, @@ -717,6 +717,24 @@ WritableArray<N-1> WritableArray<N>::operator[] (unsigned int i) const } +/** + * @brief Array indexing. + * @param i The desired index. Must be less than the array size + * along this dimension. + * @return The @a i'th @c N-1 dimensional subarray in the array. + * + * Note that this operation is not available if @c N is 0. + */ +template <unsigned int N> +inline +Array<N-1> WritableArray<N>::operator[] (unsigned int i) const +{ + assert (i < this->m_rep_nc->m_shape[this->m_rep_nc->m_shape.size() - N]); + return Array<N-1> (*this->m_rep_nc, + this->m_offs + i * this->m_rep_nc->m_sizes[N-1]); +} + + /** * @brief Return a direct pointer to array elements. * @return A pointer to the first array elements.