43 #include "atlas/array/ArrayUtil.h" 44 #include "atlas/library/config.h" 56 template <
typename Value>
65 FortranIndex( Value* idx ) : idx_( idx ) {}
66 void set(
const Value& value ) { *( idx_ ) = value + BASE; }
67 Value
get()
const {
return *(idx_)-BASE; }
68 void operator =(
const Value& value ) {
set( value ); }
69 FortranIndex<Value>& operator=(
const FortranIndex<Value>& other ) {
73 FortranIndex<Value>& operator--() {
77 FortranIndex<Value>& operator++() {
83 operator Value()
const {
return get(); }
91 #if ATLAS_HAVE_FORTRAN 92 #define INDEX_REF Index 93 #define FROM_FORTRAN -1 113 template <
typename Value,
int Rank>
116 using value_type =
typename remove_const<Value>::type;
118 #if ATLAS_HAVE_FORTRAN 119 typedef detail::FortranIndex<Value> Index;
121 typedef Value& Index;
125 #ifndef DOXYGEN_SHOULD_SKIP_THIS 126 IndexView( Value* data,
const idx_t shape[Rank] );
128 IndexView( Value* data,
const idx_t shape[Rank],
const idx_t strides[Rank] );
133 template <
typename... Idx>
135 check_bounds( idx... );
136 return INDEX_REF( &data_[index( idx... )] );
140 template <
typename... Ints>
142 return data_[index( idx... )] FROM_FORTRAN;
148 template <
int Dim,
typename Int,
typename... Ints>
149 constexpr
idx_t index_part( Int idx, Ints... next_idx )
const {
150 return idx * strides_[Dim] + index_part<Dim + 1>( next_idx... );
153 template <
int Dim,
typename Int>
154 constexpr
idx_t index_part( Int last_idx )
const {
155 return last_idx * strides_[Dim];
158 template <
typename... Ints>
159 constexpr
idx_t index( Ints... idx )
const {
160 return index_part<0>( idx... );
163 #if ATLAS_INDEXVIEW_BOUNDS_CHECKING 164 template <
typename... Ints>
165 void check_bounds( Ints... idx )
const {
166 static_assert(
sizeof...( idx ) == Rank,
"Expected number of indices is different from rank of array" );
167 return check_bounds_part<0>( idx... );
170 template <
typename... Ints>
171 void check_bounds( Ints... )
const {}
174 template <
typename... Ints>
175 void check_bounds_force( Ints... idx )
const {
176 static_assert(
sizeof...( idx ) == Rank,
"Expected number of indices is different from rank of array" );
177 return check_bounds_part<0>( idx... );
180 template <
int Dim,
typename Int,
typename... Ints>
181 void check_bounds_part( Int idx, Ints... next_idx )
const {
182 if (
idx_t( idx ) >= shape_[Dim] ) {
183 throw_OutOfRange(
"IndexView", array_dim<Dim>(), idx, shape_[Dim] );
185 check_bounds_part<Dim + 1>( next_idx... );
188 template <
int Dim,
typename Int>
189 void check_bounds_part( Int last_idx )
const {
190 if (
idx_t( last_idx ) >= shape_[Dim] ) {
191 throw_OutOfRange(
"IndexView", array_dim<Dim>(), last_idx, shape_[Dim] );
195 idx_t size()
const {
return shape_[0]; }
197 void dump( std::ostream& os )
const;
201 idx_t strides_[Rank];
205 template <
typename Value,
int Rank>
Definition: GridToolsIndexView.h:136
Index operator()(Idx... idx)
Multidimensional index operator: view(i,j,k,...)
Definition: NativeIndexView.h:134
const value_type operator()(Ints... idx) const
Multidimensional index operator: view(i,j,k,...)
Definition: NativeIndexView.h:141
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Multidimensional access to Array or Field objects containing index fields that are compatible with Fo...
Definition: GridToolsIndexView.h:74
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Definition: ArrayViewDefs.h:20