ivl 679
ivl/details/array_nd/impl/specialization/wrap_array_nd_class.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 
00025 
00036 template <class T,
00037                  class A,
00038                  class ATTR,
00039                  class DERIVED_INFO
00040              >
00041 class array_nd<T, data::wrap_array<A, ATTR, DERIVED_INFO> >:
00042         public
00043         array_common_base<array_nd<T,
00044                 data::wrap_array<A, ATTR, DERIVED_INFO> > >
00045 {
00046 private:
00047         typedef array_nd prv_this_type;
00048         typedef typename prv_this_type::common_base_class common_base_class;
00049 
00050         typedef typename A::this_array_nd_type a_t;
00051 
00052         typedef typename types::best_iterator<a_t>::type best_iter_t;
00053         typedef typename types::best_iterator<a_t>::type::reference reference_t;
00054         typedef typename a_t::const_iterator::reference const_reference_t;
00055 
00056         typename A::derived_type& a_d() { return this->a_ptr->derived(); }
00057         const typename A::derived_type& a_d() const
00058                 { return this->a_ptr->derived(); }
00059         a_t& a_nd() { return static_cast<a_t&>(a_d()); }
00060         const a_t& a_nd() const { return static_cast<const a_t&>(a_d()); }
00061 
00062 public:
00063         typedef array_nd this_type;
00064 
00065         typedef this_type this_array_nd_type;
00066 
00067         typedef typename types::derive<this_type>::type derived_type;
00068 
00069         typedef typename common_base_class::base_class base_class;
00070 
00071         typedef this_type array_type;
00072 
00074         typedef typename a_t::size_type size_type;
00075 
00077         typedef typename a_t::size_nd_ref_type size_nd_ref_type;
00078 
00080         typedef typename a_t::stride_ref_type stride_ref_type;
00081 
00083         /*
00084         typedef typename a_t::has_1d_parenthesis has_1d_parenthesis;
00085         typedef typename a_t::has_2d_parenthesis has_2d_parenthesis;
00086         typedef typename a_t::has_3d_parenthesis has_3d_parenthesis;
00087         typedef typename a_t::has_nd_parenthesis has_nd_parenthesis;
00088         */
00089 
00090         using base_class::derived;
00091 
00093         base_class& base() { return *this; }
00094         const base_class& base() const { return *this; }
00095 
00096 
00099         typedef typename array_nd::const_iterator const_iterator;
00100 
00101         typedef typename types::best_iterator_nd<a_t>::type best_iterator_nd;
00102         typedef typename types::best_iterator_nd<a_t, 0, false>
00103                 ::type best_fast_iterator_nd;
00104         typedef typename types::best_reverse_iterator_nd<a_t>::type
00105                 best_reverse_iterator_nd;
00106 
00107         typedef typename types::t_if<types::t_not<typename a_t::is_writeable>,
00108                 types::not_a_type, best_iterator_nd>::type iterator_nd;
00109         typedef typename types::t_if<types::t_not<typename a_t::is_writeable>,
00110                 types::not_a_type, best_fast_iterator_nd>::type _fast_iterator_nd;
00111         typedef typename types::t_if<types::t_not<typename a_t::is_writeable>,
00112                 types::not_a_type, best_reverse_iterator_nd>::type reverse_iterator_nd;
00113 
00114         typedef typename a_t::const_iterator_nd const_iterator_nd;
00115         typedef typename a_t::_fast_const_iterator_nd _fast_const_iterator_nd;
00116         typedef typename a_t::const_reverse_iterator_nd const_reverse_iterator_nd;
00117 
00118         // best
00119         best_iterator_nd _begin(size_t d) { return a_d()._begin(d); }
00120         best_iterator_nd _begin(size_t d, const best_iterator_nd& it_nd)
00121                 { return a_d()._begin(d, it_nd); }
00122         best_iterator_nd _iter(size_t d, const best_iter_t& it)
00123                 { return a_d()._iter(d, it); }
00124         template<class S>
00125         best_iterator_nd _iter(size_t d, array<size_t, S> ind)
00126                 { return a_d()._iter(d, ind); }
00127         best_iterator_nd _next(size_t d, const best_iterator_nd& it_nd)
00128                 { return a_d()._next(d, it_nd); }
00129         best_iterator_nd _end(size_t d) { return a_d()._end(d); }
00130         best_iterator_nd _last(size_t d) { return a_d()._last(d); }
00131         // const
00132         const_iterator_nd _begin(size_t d) const { return a_d()._begin(d); }
00133         const_iterator_nd _begin(size_t d, const const_iterator_nd& it_nd) const
00134                 { return a_d()._begin(d, it_nd); }
00135         const_iterator_nd _iter(size_t d, const const_iterator& it) const
00136                 { return a_d()._iter(d, it); }
00137         template<class S>
00138         const_iterator_nd _iter(size_t d, array<size_t, S> ind) const
00139                 { return a_d()._iter(d, ind); }
00140         const_iterator_nd _next(size_t d, const const_iterator_nd& it_nd) const
00141                 { return a_d()._next(d, it_nd); }
00142         const_iterator_nd _end(size_t d) const { return a_d()._end(d); }
00143         const_iterator_nd _last(size_t d) const { return a_d()._last(d); }
00144 
00145         // r-best
00146         best_reverse_iterator_nd _rbegin(size_t d) { return a_d()._rbegin(d); }
00147         best_reverse_iterator_nd _rbegin(size_t d,
00148                         const best_reverse_iterator_nd& it_nd)
00149                 { return a_d()._rbegin(d, it_nd); }
00150         best_reverse_iterator_nd _riter(size_t d, const best_iter_t& it)
00151                 { return a_d()._riter(d, it); }
00152         template<class S>
00153         best_reverse_iterator_nd  _riter(size_t d, array<size_t, S> ind)
00154                 { return a_d()._riter(d, ind); }
00155         best_reverse_iterator_nd _rnext(size_t d,
00156                         const best_reverse_iterator_nd& it_nd)
00157                 { return a_d()._rnext(d, it_nd); }
00158         best_iterator_nd _rend(size_t d) { return a_d()._rend(d); }
00159         best_iterator_nd _rlast(size_t d) { return a_d()._rlast(d); }
00160         // r-const
00161         const_reverse_iterator_nd _rbegin(size_t d) const
00162                 { return a_d()._rbegin(d); }
00163         const_reverse_iterator_nd _rbegin(size_t d,
00164                         const const_reverse_iterator_nd& it_nd) const
00165                 { return a_d()._rbegin(d, it_nd); }
00166         const_reverse_iterator_nd _riter(size_t d, const const_iterator& it) const
00167                 { return a_d()._riter(d, it); }
00168         template<class S>
00169         const_reverse_iterator_nd _riter(size_t d, array<size_t, S> ind) const
00170                 { return a_d()._riter(d, ind); }
00171         const_reverse_iterator_nd _rnext(size_t d, const
00172                         const_reverse_iterator_nd& it_nd) const
00173                 { return a_d()._rnext(d, it_nd); }
00174         const_reverse_iterator_nd _rend(size_t d) const { return a_d()._rend(d); }
00175         const_reverse_iterator_nd _rlast(size_t d) const { return a_d()._rlast(d); }
00176         // fast
00177         best_fast_iterator_nd _fast_begin(size_t d) { return a_d()._fast_begin(d); }
00178         best_fast_iterator_nd _fast_last(size_t d) { return a_d()._fast_last(d); }
00179         _fast_const_iterator_nd _fast_begin(size_t d) const
00180                 { return a_d()._fast_begin(d); }
00181         _fast_const_iterator_nd _fast_last(size_t d) const
00182                 { return a_d()._fast_last(d); }
00183 
00184         using common_base_class::first_to_last;
00185         using common_base_class::begin_to_end;
00186 
00187         typedef typename a_t::iter_nd_border_walker iter_nd_border_walker;
00188 
00189         iter_nd_border_walker first_to_last(size_t d)
00190                 { return a_d().first_to_last(d); }
00191         iter_nd_border_walker begin_to_end(size_t d)
00192                 { return a_d().begin_to_end(d); }
00201         using base_class::operator[];
00202         using base_class::length;
00203         using base_class::numel;
00210 
00211         //todo: add extension overloaded operator ()
00212         using common_base_class::operator();
00213 
00214         template<class S>
00215         reference_t operator()(const array<size_t, S>& indx)
00216                 { return derived().operator()[indx]; }
00219         template<class S>
00220         const_reference_t operator()(const array<size_t, S>& indx) const
00221                 { return derived()[sub2ind(derived(), indx)]; }
00222 /*
00223         const T& operator()(size_t s1) const;
00224         const T& operator()(size_t s1, size_t s2) const;
00225         const T& operator()(size_t s1, size_t s2, size_t s3) const;
00226         const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4) const;
00227         const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5) const;
00228         const T& operator()(size_t s1, size_t s2, size_t s3, size_t s4, size_t s5, size_t s6) const;
00231         template<class S>
00232         typename array_nd::const_iterator::reference operator()
00233                 (const array<size_t, S>& indx) const
00234                 { return derived()[sub2ind(derived(), indx)]; }
00235 */
00237 
00241 
00242         size_nd_ref_type size_nd() const { return a_nd().size_nd(); }
00243 
00245         size_t size_nd(size_t d) const { return a_nd().size_nd(d); }
00246 
00248         stride_ref_type stride() const { return a_nd().stride(); }
00249 
00251         size_t stride(size_t dim) const { return a_nd().stride(dim); }
00252 
00254         size_type size() const { return a_nd().size(); }
00255 
00257         size_t size(size_t d) const { return a_nd().size(d); }
00258 
00260         size_t ndims() const { return a_nd().ndims(); }
00265 
00266         template <class S>
00267         void resize(const array<size_t, S>& newsize, const T& s)
00268         {
00269                 if(array_details::
00270                         wrap_array_resize_details<typename array_nd::is_resizeable>
00271                         ::resize(a_nd(), newsize, s)) {
00272                                 this->a_begin = a_nd()->begin(); this->len = a_nd()->length();
00273                         }
00274         }
00275 
00277         template <class S>
00278         void resize(const array<size_t, S>& newsize)
00279         {
00280                 if(array_details::
00281                         wrap_array_resize_details<typename array_nd::is_resizeable>
00282                         ::resize(a_nd(), newsize)) {
00283                                 this->a_begin = a_nd()->begin(); this->len = a_nd()->length();
00284                         }
00285         }
00286 //
00287 
00289         template <class S>
00290         void reshape(const array<size_t, S>& newsize, const T& s)
00291         {
00292                 if(array_details::
00293                         wrap_array_resize_details<typename array_nd::is_resizeable>
00294                         ::reshape(a_nd(), newsize, s)) {
00295                                 this->a_begin = a_nd()->begin(); this->len = a_nd()->length();
00296                         }
00297         }
00298 
00300         template <class S>
00301         void reshape(const array<size_t, S>& newsize)
00302         {
00303                 if(array_details::
00304                         wrap_array_resize_details<typename array_nd::is_resizeable>
00305                         ::reshape(a_nd(), newsize)) {
00306                                 this->a_begin = a_nd()->begin(); this->len = a_nd()->length();
00307                         }
00308         }
00309 
00315 
00316         array_nd() { }
00317 
00319         array_nd(A& a1) { this->setref(a1); }
00320 
00322         array_nd(const array_nd& a) : common_base_class(a) { }
00328         // Construct by defining an element count.
00329         explicit array_nd(size_t count) { }
00330 
00331         // Construct by defining an element count and a sigle default value
00332         array_nd(size_t count, const T& s) { }
00333 
00334         // Construct by defining an element count and a pointer to data.
00335         array_nd(size_t count, const T *data) { }
00336 
00337         // Construct from a size_array containing the dimension sizes
00338         template<class S>
00339         array_nd(const array<size_t, S>& sz) { }
00340 
00341         // construct from a size_array containing the dimension sizes and scalar
00342         template<class S>
00343         array_nd(const array<size_t, S>& sz, const T& s) { }
00344 
00345         //Construct from a size_array and pointer
00346         template<class S>
00347         array_nd(const array<size_t, S>& sz, const T* ptr) { }
00348 
00349         //Construct from a size_array and an array with the values.
00350         template<class S, class J, class D>
00351         array_nd(const array<size_t, S>& sz, const array<J, D>& a) { }
00352 
00353         // Constructor using another form of array_nd
00354         template<class J, class S>
00355         array_nd(const array_nd<J, S>& a) : common_base_class(a) { }
00356 
00358         template <class J, class S>
00359         array_nd(array_nd<J, S>& a) : common_base_class(a) {}
00360 
00366         using common_base_class::operator=;
00367 
00369         this_type& operator=(const this_type& in)
00370         { common_base_class::operator=(in); return *this; }
00371 
00374 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations