diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index e766432ea2347d26801160fadbb5f02d37ac1ad0..ef66bdc56d9e93129a02bb5ebd3278f8355ed3f9 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -258,6 +258,12 @@ template< typename Value, typename Device, typename Index, typename Allocator > typename Array< Value, Device, Index, Allocator >::ViewType Array< Value, Device, Index, Allocator >::getView( IndexType begin, IndexType end ) { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, getSize(), "Parameter 'begin' must be lower or equal to size of the array." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, getSize(), "Parameter 'end' must be lower or equal to size of the array." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = getSize(); return ViewType( getData() + begin, end - begin ); @@ -267,6 +273,12 @@ template< typename Value, typename Device, typename Index, typename Allocator > typename Array< Value, Device, Index, Allocator >::ConstViewType Array< Value, Device, Index, Allocator >::getConstView( IndexType begin, IndexType end ) const { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, getSize(), "Parameter 'begin' must be lower or equal to size of the array." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, getSize(), "Parameter 'end' must be lower or equal to size of the array." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = getSize(); return ConstViewType( getData() + begin, end - begin ); diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index c94e9e05f8b166ea3f1ea46824c0d6bc10182544..c7db08cceba497a407cf0a83338c45c53e06908d 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -59,6 +59,12 @@ __cuda_callable__ typename ArrayView< Value, Device, Index >::ViewType ArrayView< Value, Device, Index >::getView( IndexType begin, IndexType end ) { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, getSize(), "Parameter 'begin' must be lower or equal to size of the array view." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, getSize(), "Parameter 'end' must be lower or equal to size of the array view." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ViewType( getData() + begin, end - begin ); @@ -70,6 +76,12 @@ __cuda_callable__ typename ArrayView< Value, Device, Index >::ConstViewType ArrayView< Value, Device, Index >::getConstView( IndexType begin, IndexType end ) const { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, getSize(), "Parameter 'begin' must be lower or equal to size of the array view." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, getSize(), "Parameter 'end' must be lower or equal to size of the array view." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ConstViewType( getData() + begin, end - begin ); diff --git a/src/TNL/Containers/Vector.hpp b/src/TNL/Containers/Vector.hpp index 12d2d4337c5bbdbf73147763d792b4de7827fd3a..2572b3ff7b8b62b823e1981cc91532d107548c25 100644 --- a/src/TNL/Containers/Vector.hpp +++ b/src/TNL/Containers/Vector.hpp @@ -28,6 +28,12 @@ template< typename Real, typename Device, typename Index, typename Allocator > typename Vector< Real, Device, Index, Allocator >::ViewType Vector< Real, Device, Index, Allocator >::getView( IndexType begin, IndexType end ) { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, this->getSize(), "Parameter 'begin' must be lower or equal to size of the vector." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, this->getSize(), "Parameter 'end' must be lower or equal to size of the vector." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ViewType( this->getData() + begin, end - begin ); @@ -37,6 +43,12 @@ template< typename Real, typename Device, typename Index, typename Allocator > typename Vector< Real, Device, Index, Allocator >::ConstViewType Vector< Real, Device, Index, Allocator >::getConstView( IndexType begin, IndexType end ) const { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, this->getSize(), "Parameter 'begin' must be lower or equal to size of the vector." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, this->getSize(), "Parameter 'end' must be lower or equal to size of the vector." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ConstViewType( this->getData() + begin, end - begin ); diff --git a/src/TNL/Containers/VectorView.hpp b/src/TNL/Containers/VectorView.hpp index bc993be309330aa74a2b8cd9196d02f246bd7c7c..65aa56af9c67ca4a75febc389c95a0abb6bf58c5 100644 --- a/src/TNL/Containers/VectorView.hpp +++ b/src/TNL/Containers/VectorView.hpp @@ -17,6 +17,12 @@ __cuda_callable__ typename VectorView< Real, Device, Index >::ViewType VectorView< Real, Device, Index >::getView( IndexType begin, IndexType end ) { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, this->getSize(), "Parameter 'begin' must be lower or equal to size of the vector view." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, this->getSize(), "Parameter 'end' must be lower or equal to size of the vector view." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ViewType( this->getData() + begin, end - begin ); @@ -28,6 +34,12 @@ __cuda_callable__ typename VectorView< Real, Device, Index >::ConstViewType VectorView< Real, Device, Index >::getConstView( const IndexType begin, IndexType end ) const { + TNL_ASSERT_GE( begin, ( Index ) 0, "Parameter 'begin' must be non-negative." ); + TNL_ASSERT_LE( begin, this->getSize(), "Parameter 'begin' must be lower or equal to size of the vector view." ); + TNL_ASSERT_GE( end, ( Index ) 0, "Parameter 'end' must be non-negative." ); + TNL_ASSERT_LE( end, this->getSize(), "Parameter 'end' must be lower or equal to size of the vector view." ); + TNL_ASSERT_LE( begin, end, "Parameter 'begin' must be lower or equal to the parameter 'end'." ); + if( end == 0 ) end = this->getSize(); return ConstViewType( this->getData() + begin, end - begin );