Proxy.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup Proxy
00018 //! @{
00019 
00020 
00021 
00022 template<typename T1>
00023 class Proxy
00024   {
00025   public:
00026   inline Proxy(const T1& A)
00027     {
00028     arma_type_check< is_arma_type<T1>::value == false >::apply();
00029     }
00030   };
00031 
00032 
00033 
00034 template<typename eT>
00035 class Proxy< Mat<eT> >
00036   {
00037   public:
00038   
00039   typedef eT                                       elem_type;
00040   typedef typename get_pod_type<elem_type>::result pod_type;
00041   typedef Mat<eT>                                  stored_type;
00042   
00043   const Mat<eT>& Q;
00044   
00045   const u32 n_rows;
00046   const u32 n_cols;
00047   const u32 n_elem;
00048   
00049   inline explicit Proxy(const Mat<eT>& A)
00050     : Q(A)
00051     , n_rows(A.n_rows)
00052     , n_cols(A.n_cols)
00053     , n_elem(A.n_elem)
00054     {
00055     arma_extra_debug_sigprint();
00056     }
00057   
00058   inline explicit Proxy(const u32 in_n_rows, const u32 in_n_cols)
00059     : Q(Q)
00060     , n_rows(in_n_rows)
00061     , n_cols(in_n_cols)
00062     , n_elem(in_n_rows*in_n_cols)
00063     {
00064     arma_extra_debug_sigprint();
00065     }
00066   
00067   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00068   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00069   };
00070 
00071 
00072 
00073 template<typename eT>
00074 class Proxy< Col<eT> >
00075   {
00076   public:
00077   
00078   typedef eT                                       elem_type;
00079   typedef typename get_pod_type<elem_type>::result pod_type;
00080   typedef Col<eT>                                  stored_type;
00081   
00082   const Col<eT>& Q;
00083   
00084   const u32 n_rows;
00085   const u32 n_cols;
00086   const u32 n_elem;
00087   
00088   inline explicit Proxy(const Col<eT>& A)
00089     : Q(A)
00090     , n_rows(A.n_rows)
00091     , n_cols(A.n_cols)
00092     , n_elem(A.n_elem)
00093     {
00094     arma_extra_debug_sigprint();
00095     }
00096   
00097   inline explicit Proxy(const u32 in_n_rows, const u32 in_n_cols)
00098     : Q(Q)
00099     , n_rows(in_n_rows)
00100     , n_cols(in_n_cols)
00101     , n_elem(in_n_rows*in_n_cols)
00102     {
00103     arma_extra_debug_sigprint();
00104     }
00105   
00106   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00107   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00108   };
00109 
00110 
00111 
00112 template<typename eT>
00113 class Proxy< Row<eT> >
00114   {
00115   public:
00116   
00117   typedef eT                                       elem_type;
00118   typedef typename get_pod_type<elem_type>::result pod_type;
00119   typedef Row<eT>                                  stored_type;
00120   
00121   const Row<eT>& Q;
00122   
00123   const u32 n_rows;
00124   const u32 n_cols;
00125   const u32 n_elem;
00126   
00127   inline explicit Proxy(const Row<eT>& A)
00128     : Q(A)
00129     , n_rows(A.n_rows)
00130     , n_cols(A.n_cols)
00131     , n_elem(A.n_elem)
00132     {
00133     arma_extra_debug_sigprint();
00134     }
00135   
00136   inline explicit Proxy(const u32 in_n_rows, const u32 in_n_cols)
00137     : Q(Q)
00138     , n_rows(in_n_rows)
00139     , n_cols(in_n_cols)
00140     , n_elem(in_n_rows*in_n_cols)
00141     {
00142     arma_extra_debug_sigprint();
00143     }
00144   
00145   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00146   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00147   };
00148 
00149 
00150 
00151 template<typename T1, typename op_type>
00152 class Proxy< Op<T1, op_type> >
00153   {
00154   public:
00155   
00156   typedef typename T1::elem_type                   elem_type;
00157   typedef typename get_pod_type<elem_type>::result pod_type;
00158   typedef Mat<elem_type>                           stored_type;
00159   
00160   const Mat<elem_type> Q;
00161   
00162   const u32 n_rows;
00163   const u32 n_cols;
00164   const u32 n_elem;
00165   
00166   inline explicit Proxy(const Op<T1, op_type>& A)
00167     : Q(A)
00168     , n_rows(Q.n_rows)
00169     , n_cols(Q.n_cols)
00170     , n_elem(Q.n_elem)
00171     {
00172     arma_extra_debug_sigprint();
00173     }
00174   
00175   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00176   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00177   };
00178 
00179 
00180 
00181 template<typename T1, typename T2, typename glue_type>
00182 class Proxy< Glue<T1, T2, glue_type> >
00183   {
00184   public:
00185   
00186   typedef typename T1::elem_type                   elem_type;
00187   typedef typename get_pod_type<elem_type>::result pod_type;
00188   typedef Mat<elem_type>                           stored_type;
00189   
00190   const Mat<elem_type> Q;
00191   
00192   const u32 n_rows;
00193   const u32 n_cols;
00194   const u32 n_elem;
00195   
00196   inline explicit Proxy(const Glue<T1, T2, glue_type>& A)
00197     : Q(A)
00198     , n_rows(Q.n_rows)
00199     , n_cols(Q.n_cols)
00200     , n_elem(Q.n_elem)
00201     {
00202     arma_extra_debug_sigprint();
00203     }
00204 
00205   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00206   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00207   };
00208 
00209 
00210 
00211 template<typename eT>
00212 class Proxy< subview<eT> >
00213   {
00214   public:
00215   
00216   typedef eT                                       elem_type;
00217   typedef typename get_pod_type<elem_type>::result pod_type;
00218   typedef subview<eT>                              stored_type;
00219   
00220   const subview<eT>& Q;
00221   
00222   const u32 n_rows;
00223   const u32 n_cols;
00224   const u32 n_elem;
00225   
00226   inline explicit Proxy(const subview<eT>& A)
00227     : Q(A)
00228     , n_rows(A.n_rows)
00229     , n_cols(A.n_cols)
00230     , n_elem(A.n_elem)
00231     {
00232     arma_extra_debug_sigprint();
00233     }
00234   
00235   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00236   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00237   };
00238 
00239 
00240 
00241 
00242 template<typename eT>
00243 class Proxy< diagview<eT> >
00244   {
00245   public:
00246   
00247   typedef eT                                       elem_type;
00248   typedef typename get_pod_type<elem_type>::result pod_type;
00249   typedef diagview<eT>                             stored_type;
00250   
00251   const diagview<eT>& Q;
00252   
00253   const u32 n_rows;
00254   const u32 n_cols;
00255   const u32 n_elem;
00256   
00257   inline explicit Proxy(const diagview<eT>& A)
00258     : Q(A)
00259     , n_rows(A.n_rows)
00260     , n_cols(A.n_cols)
00261     , n_elem(A.n_elem)
00262     {
00263     arma_extra_debug_sigprint();
00264     }
00265   
00266   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];           }
00267   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row, col); }
00268   };
00269 
00270 
00271 
00272 
00273 template<typename T1, typename eop_type>
00274 class Proxy< eOp<T1, eop_type > >
00275   {
00276   public:
00277   
00278   typedef typename T1::elem_type                   elem_type;
00279   typedef typename get_pod_type<elem_type>::result pod_type;
00280   typedef eOp<T1, eop_type>                        stored_type;
00281   
00282   const eOp<T1, eop_type>& Q;
00283   
00284   const u32 n_rows;
00285   const u32 n_cols;
00286   const u32 n_elem;
00287   
00288   inline explicit Proxy(const eOp<T1, eop_type>& A)
00289     : Q(A)
00290     , n_rows(A.P.n_rows)
00291     , n_cols(A.P.n_cols)
00292     , n_elem(A.P.n_elem)
00293     {
00294     arma_extra_debug_sigprint();
00295     }
00296   
00297   arma_inline elem_type operator[] (const u32 i)                  const { return eop_type::get_elem(Q, i);       }
00298   arma_inline elem_type at         (const u32 row, const u32 col) const { return eop_type::get_elem(Q, row,col); }
00299   };
00300 
00301 
00302 
00303 template<typename T1, typename T2, typename eglue_type>
00304 class Proxy< eGlue<T1, T2, eglue_type > >
00305   {
00306   public:
00307   
00308   typedef typename T1::elem_type                   elem_type;
00309   typedef typename get_pod_type<elem_type>::result pod_type;
00310   typedef eGlue<T1, T2, eglue_type>                stored_type;
00311   
00312   const eGlue<T1, T2, eglue_type>& Q;
00313   
00314   const u32 n_rows;
00315   const u32 n_cols;
00316   const u32 n_elem;
00317   
00318   inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A)
00319     : Q(A)
00320     , n_rows(A.P1.n_rows)
00321     , n_cols(A.P1.n_cols)
00322     , n_elem(A.P1.n_elem)
00323     {
00324     arma_extra_debug_sigprint();
00325     }
00326   
00327   arma_inline elem_type operator[] (const u32 i)                  const { return eglue_type::get_elem(Q, i);        }
00328   arma_inline elem_type at         (const u32 row, const u32 col) const { return eglue_type::get_elem(Q, row, col); }
00329   };
00330 
00331 
00332 
00333 template<typename out_eT, typename T1, typename op_type>
00334 class Proxy< mtOp<out_eT, T1, op_type> >
00335   {
00336   public:
00337   
00338   typedef          out_eT                       elem_type;
00339   typedef typename get_pod_type<out_eT>::result pod_type;
00340   typedef          Mat<out_eT>                  stored_type;
00341   
00342   const Mat<out_eT> Q;
00343   
00344   const u32 n_rows;
00345   const u32 n_cols;
00346   const u32 n_elem;
00347   
00348   inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A)
00349     : Q(A)
00350     , n_rows(Q.n_rows)
00351     , n_cols(Q.n_cols)
00352     , n_elem(Q.n_elem)
00353     {
00354     arma_extra_debug_sigprint();
00355     }
00356   
00357   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];          }
00358   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row,col); }
00359   };
00360 
00361 
00362 
00363 template<typename out_eT, typename T1, typename T2, typename glue_type>
00364 class Proxy< mtGlue<out_eT, T1, T2, glue_type > >
00365   {
00366   public:
00367   
00368   typedef          out_eT                       elem_type;
00369   typedef typename get_pod_type<out_eT>::result pod_type;
00370   typedef          Mat<out_eT>                  stored_type;
00371   
00372   const Mat<out_eT> Q;
00373   
00374   const u32 n_rows;
00375   const u32 n_cols;
00376   const u32 n_elem;
00377   
00378   inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A)
00379     : Q(A)
00380     , n_rows(Q.n_rows)
00381     , n_cols(Q.n_cols)
00382     , n_elem(Q.n_elem)
00383     {
00384     arma_extra_debug_sigprint();
00385     }
00386   
00387   arma_inline elem_type operator[] (const u32 i)                  const { return Q[i];          }
00388   arma_inline elem_type at         (const u32 row, const u32 col) const { return Q.at(row,col); }
00389   };
00390 
00391 
00392 
00393 //! @}