ivl 679
ivl/details/array/impl/specialization/row_elem_func_class_2d.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 #if 0
00025 //TODO: rewrite, correct and then include
00031 template <class T,
00032                  class F,
00033                  class A,
00034                  class DERIVED_INFO
00035              >
00036 class array<T, data::row_elem_func_2d<F, A, DERIVED_INFO> > :
00037 
00038 public array_base<T, typename data::row_elem_func_2d<F, A>,
00039                 typename types::derive <array <T, data::row_elem_func_2d<F, A>,
00040                         DERIVED_INFO> >::type>,
00041 
00042 public array_common_base<array<T, data::row_elem_func_2d<F, A>, DERIVED_INFO> >
00043 
00044 {
00045 
00046 private:
00047         typedef array_common_base<array<T,
00048                 data::row_elem_func_2d<F, A>, DERIVED_INFO> > common_base_class;
00049 
00050         typedef typename array_details::elem_func_tools<T,
00051                 array::has_random_access::value> tool;
00052 
00053         friend class tool::not_a_type; // allow disabled types only in our class
00054 
00055 protected:
00056 
00057         const A* in;
00058         size_t in_dim;
00059         size_t len;
00060 
00061         void set_input(const A* in_a, size_t d)
00062         {
00063                 in = in_a;
00064                 in_dim = d;
00065                 len = in->size(1 - in_dim);
00066         }
00067 
00068 public:
00069 
00070         typedef data::row_elem_func_2d<F, A> data_type;
00071 
00072         typedef array <T, data_type, DERIVED_INFO> this_type;
00073 
00074         typedef this_type this_array_type;
00075 
00076         typedef this_type array_type;
00077 
00078         typedef T elem_type;
00079 
00080         typedef typename types::derive<this_type>::type derived_type;
00081 
00082         typedef typename common_base_class::base_class base_class;
00083 
00085         typedef size_t size_type;
00086 
00088         typedef ptrdiff_t diff_type;
00089 
00090         using base_class::derived;
00091 
00092         typedef typename array::has_random_access has_random_access;
00093 
00094 
00095         class const_iterator
00096         {
00097         private:
00098                 typedef typename A::const_iterator iter;
00099                 iter it;
00100                 const A* in;
00101                 size_t in_dim;
00102 
00103                 typedef typename tool::template
00104                         rnd_it<const_iterator>::type rnd_iter;
00105 
00106         public:
00107 
00108                 // iterator_traits
00109                 typedef typename types::t_if<has_random_access,
00110                         std::random_access_iterator_tag,
00111                         std::bidirectional_iterator_tag>::type iterator_category;
00112 
00113                 typedef T value_type;
00114                 typedef ptrdiff_t difference_type;
00115                 typedef const T* pointer;
00116                 typedef const T& reference;
00117 
00118                 // constructors
00119                 const_iterator() { }
00120 
00121                 const_iterator(const iter& it, const A* in, size_t in_dim)
00122                         : it(it), in(in), in_dim(in_dim) { }
00123 
00124                 const_iterator(const const_iterator& it)
00125                         : it(it.it), in(it.in), in_dim(it.in_dim) { }
00126 
00127                 // members
00128                 T operator *() const
00129                 {
00130                         return F::calculate(const_iter_array(in->_iter(in_dim, it)));
00131                 }
00132 
00133                 // optional random access in iterator
00134                 typename tool::brackets_ret_type operator[]
00135                         (typename tool::brackets_arg j) const
00136                 {
00137                         return F::calculate(const_iter_array(in->_iter(in_dim,
00138                                 tool::add_op_void(it, j))));
00139                 }
00140 
00141                 // increment-decrement
00142                 const_iterator& operator++()
00143                 {
00144                         ++it;
00145                         return *this;
00146                 }
00147                 const_iterator& operator--()
00148                 {
00149                         --it;
00150                         return *this;
00151                 }
00152 
00153                 const_iterator operator++(int)
00154                         { const_iterator tmp(*this); ++(*this); return tmp; }
00155 
00156                 const_iterator operator--(int)
00157                         { const_iterator tmp(*this); --(*this); return tmp; }
00158 
00159                 // random access. enabled only if 'has_random_access'
00160                 const_iterator& operator +=(typename tool::brackets_arg j)
00161                 {
00162                         tool::add_asgn(it, j);
00163                         return *this;
00164                 }
00165                 const_iterator& operator -=(typename tool::brackets_arg j)
00166                 {
00167                         tool::sub_asgn(it, j);
00168                         return *this;
00169                 }
00170                 inline rnd_iter operator +(typename tool::brackets_arg j) const
00171                 {
00172                         return rnd_iter(tool::add_op(it, j), in, in_dim);
00173                 }
00174                 inline rnd_iter operator -(typename tool::brackets_arg j) const
00175                 {
00176                         return rnd_iter(tool::sub_op(it, j), in, in_dim);
00177                 }
00178 
00179                 // difference
00180                 difference_type operator -(const rnd_iter& a) const
00181                 {
00182                         return tool::dif_op_it(*this, a);
00183                 }
00184 
00185                 //copy same type iterator
00186                 const_iterator& operator=(const const_iterator& o)
00187                 {
00188                         it = o.it;
00189                         in = o.in;
00190                         in_dim = o.in_dim;
00191                         return *this;
00192                 }
00193 
00194                 bool operator==(const const_iterator& o) const { return (it == o.it); }
00195                 bool operator!=(const const_iterator& o) const { return (it != o.it); }
00196         };
00197 
00198         typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00199 
00200         typedef typename const_iterator::reference const_reference;
00201         typedef const_reference best_reference;
00202         typedef const_iterator best_iterator;
00203 
00204         const_iterator begin() const
00205         {
00206                 return const_iterator(in->_begin(1 - in_dim), in, in_dim);
00207         }
00208         const_iterator end() const
00209         {
00210                 return const_iterator(in->_end(1 - in_dim), in, in_dim);
00211         }
00212 
00213         const_reverse_iterator rbegin() const
00214         {
00215                 return const_reverse_iterator(in->_rbegin(), in, in_dim);
00216         }
00217         const_reverse_iterator rend() const
00218         {
00219                 return const_reverse_iterator(in->_rend(), in, in_dim);
00220         }
00221 
00222 
00225 
00226 
00227         size_t length() const
00228         {
00229                 return len;
00230         }
00231 
00233         size_type size() const { return length(); }
00235         size_t numel() const { return length(); }
00244 
00245 
00246         T operator[](
00247                 typename tool::brackets_arg i) const
00248         {
00249                 CHECK(i >= 0 && i < length(), erange);
00250 
00251                 return tool::brackets(in->_begin(), i);
00252         }
00258 
00259         array() { }
00260 
00262         array(const array& o)
00263                 { in = o.in; in_dim = o.in_dim; len = o.len; }
00264 
00267 
00268         ~array() { }
00269 
00270 
00271 };
00272 
00273 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations