1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) 4 // Copyright 2008-2016 National ICT Australia (NICTA) 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ------------------------------------------------------------------------ 17 18 19 //! \addtogroup subview_field 20 //! @{ 21 22 23 //! Class for storing data required to construct or apply operations to a subfield 24 //! (ie. where the subfield starts and ends as well as a reference/pointer to the original field), 25 template<typename oT> 26 class subview_field 27 { 28 public: 29 30 typedef oT object_type; 31 32 const field<oT>& f; 33 34 const uword aux_row1; 35 const uword aux_col1; 36 const uword aux_slice1; 37 38 const uword n_rows; 39 const uword n_cols; 40 const uword n_slices; 41 const uword n_elem; 42 43 44 protected: 45 46 arma_inline subview_field(const field<oT>& in_f, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); 47 arma_inline subview_field(const field<oT>& in_f, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); 48 49 50 public: 51 52 inline ~subview_field(); 53 inline subview_field() = delete; 54 55 inline void operator= (const field<oT>& x); 56 inline void operator= (const subview_field& x); 57 58 arma_inline oT& operator[](const uword i); 59 arma_inline const oT& operator[](const uword i) const; 60 61 arma_inline oT& operator()(const uword i); 62 arma_inline const oT& operator()(const uword i) const; 63 64 arma_inline oT& at(const uword row, const uword col); 65 arma_inline const oT& at(const uword row, const uword col) const; 66 67 arma_inline oT& at(const uword row, const uword col, const uword slice); 68 arma_inline const oT& at(const uword row, const uword col, const uword slice) const; 69 70 arma_inline oT& operator()(const uword row, const uword col); 71 arma_inline const oT& operator()(const uword row, const uword col) const; 72 73 arma_inline oT& operator()(const uword row, const uword col, const uword slice); 74 arma_inline const oT& operator()(const uword row, const uword col, const uword slice) const; 75 76 arma_inline bool is_empty() const; 77 78 inline bool check_overlap(const subview_field& x) const; 79 80 inline void print(const std::string extra_text = "") const; 81 inline void print(std::ostream& user_stream, const std::string extra_text = "") const; 82 83 template<typename functor> inline void for_each(functor F); 84 template<typename functor> inline void for_each(functor F) const; 85 86 inline void fill(const oT& x); 87 88 inline static void extract(field<oT>& out, const subview_field& in); 89 90 91 friend class field<oT>; 92 }; 93 94 95 //! @} 96