ivl 679
ivl/details/array_2d/impl/common/array_2d_common_base.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 #ifndef IVL_ARRAY_2D_DETAILS_ARRAY_2D_COMMON_BASE_HPP
00025 #define IVL_ARRAY_2D_DETAILS_ARRAY_2D_COMMON_BASE_HPP
00026 
00027 namespace ivl {
00028 
00029 template <class T, class OPTS>
00030 class array_common_base<array_2d<T, OPTS> >
00031 :
00032 public
00033         array_nd<T, typename types::derive_opts<array_2d<T, OPTS> >::type>,
00034 public
00035         array_common_base<common_container_base<T, array_2d<T, OPTS> > >
00036 {
00037 private:
00038         // the type of the array_2d
00039         typedef array_2d<T, OPTS> t;
00040 
00041         typedef array_nd<T, typename types::derive_opts<
00042                 array_2d<T, OPTS> >::type> prv_base_class;
00043         typedef array_common_base<common_container_base<T,
00044                 array_2d<T, OPTS> > > prv_common;
00045 
00046         typedef ivl::array<typename
00047                 data::wrap_2d_iterator<prv_base_class>::value_type,
00048                 ref_iterator<data::wrap_2d_iterator<prv_base_class> > > wrap_2d_t;
00049         typedef data::wrap_2d_iterator<prv_base_class> wrap_it;
00050 
00051         typedef ivl::array<typename
00052                 data::wrap_2d_iterator<const prv_base_class>::value_type,
00053                 data::ref_iterator<data::wrap_2d_iterator<const prv_base_class> >
00054                         > const_wrap_2d_t;
00055         typedef data::wrap_2d_iterator<const prv_base_class> const_wrap_it;
00056 
00057         typedef ivl::array<typename
00058                 data::wrap_2d_iterator<prv_base_class>::value_type,
00059                 data::ref_iterator<data::wrap_2d_iterator<prv_base_class, 0, 1> >
00060                         > wrap_2d_r_t;
00061         typedef data::wrap_2d_iterator<prv_base_class, 0, 1> wrap_it_r;
00062 
00063         typedef ivl::array<typename
00064                 data::wrap_2d_iterator<const prv_base_class>::value_type,
00065                 data::ref_iterator<data::wrap_2d_iterator<const prv_base_class, 0, 1> >
00066                         > const_wrap_2d_r_t;
00067         typedef data::wrap_2d_iterator<const prv_base_class, 0, 1> const_wrap_it_r;
00068 
00069 public:
00070         typedef t array_2d_type;
00071         typedef t array_nd_or_2d_type;
00072         typedef t current_type;
00073         typedef t container_type;
00074 
00075         typedef typename prv_base_class::all_init_arg all_init_arg;
00076         typedef typename prv_base_class::data_init_arg data_init_arg;
00077 
00078         t& to_current() { return static_cast<t&>(*this); }
00079         const t& to_current() const { return static_cast<const t&>(*this); }
00080         t& to_array_2d() { return static_cast<t&>(*this); }
00081         const t& to_array_2d() const { return static_cast<const t&>(*this); }
00082 
00083         typedef typename types::derive<t>::type derived_type;
00084 
00085         t& derived() { return static_cast<derived_type&>(to_array_2d()); }
00086         const t& derived() const
00087                 { return static_cast<const derived_type&>(to_array_2d()); }
00088 
00089         typedef prv_base_class base_class;
00090 
00092         array_common_base() { }
00093 
00095         array_common_base(const array_common_base& o) : base_class(o) { }
00096 
00098         array_common_base(all_init_arg y) : base_class(y) { }
00099 
00101         template <class S>
00102         array_common_base(const array<size_t, S>& sz) : base_class(sz) { }
00103 
00105         template <class S>
00106         array_common_base(const array<size_t, S>& sz, const T* x)
00107                 : base_class(sz, x) { }
00108 
00110         template <class S>
00111         array_common_base(const array<size_t, S>& sz, const T& x)
00112                 : base_class(sz, x) { }
00113 
00115         template <class S>
00116         array_common_base(const array<size_t, S>& sz, const data_init_arg& y)
00117         : base_class(sz, y) { }
00118 
00120         template <class S, class J, class D>
00121         array_common_base(const array<size_t, S>& sz, const array<J, D>& a)
00122                 : base_class(sz, a) { }
00123 
00125         template <class J, class D>
00126         array_common_base(const array_nd<J, D>& a)
00127                 : base_class(a) { }
00128 
00130         template <class J, class D>
00131         array_common_base(array_nd<J, D>& a)
00132                 : base_class(a) { }
00133 
00134         //propagation of operator =
00135         using base_class::operator=;
00136         array_common_base& operator=(const array_common_base& a)
00137         {
00138                 base_class::operator=(a);
00139                 return *this;
00140         }
00141 
00142         // special object for matrix-based operations
00143         using base_class::operator();
00144 
00145         core_details::matrix_based<const t&> operator()() const
00146                 { return to_current(); }
00147 
00148         array_2d<T, ivl::normal_2d> operator()(const core_details::transpose_arg& c) const;
00149 
00150 
00151 //      wrap_2d_t wrap() { return wrap_2d_t(to_array_2d()); }
00152 
00153 //      const_wrap_2d_t wrap() const { return const_wrap_2d_t(to_array_2d()); }
00154 
00155         wrap_2d_r_t as_rows()
00156                 { return wrap_2d_r_t(wrap_it_r(to_array_2d()), to_array_2d().rows()); }
00157         const_wrap_2d_r_t as_rows() const
00158                 { return const_wrap_2d_r_t(const_wrap_it_r(to_array_2d()), to_array_2d().rows()); }
00159 
00160         //const_wrap_2d_r_t as_rows() const
00161         //      { return const_wrap_2d_r_t(to_array_2d()); }
00162 
00163         wrap_2d_t as_columns()
00164                 { return wrap_2d_t(wrap_it(to_array_2d()), to_array_2d().columns()); }
00165         const_wrap_2d_t as_columns() const
00166                 { return const_wrap_2d_t(const_wrap_it(to_array_2d()), to_array_2d().columns()); }
00167 
00168         //const_wrap_2d_t as_columns() const
00169 //              { return const_wrap_2d_t(to_array_2d()); }
00170 
00171 
00172         using prv_common::operator-;
00173         using prv_common::operator+;
00174         using prv_common::operator|;
00175         using prv_common::operator~;
00176         using prv_common::operator!;
00177         using prv_common::operator*;
00178         using prv_common::operator->*;
00179 
00180 
00181 };
00182 
00183 } /* namespace ivl */
00184 
00185 #endif // IVL_ARRAY_2D_DETAILS_ARRAY_2D_COMMON_BASE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations