unwrap_cube.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup unwrap_cube
00017 //! @{
00018 
00019 
00020 
00021 template<typename T1>
00022 class unwrap_cube
00023   {
00024   public:
00025   inline unwrap_cube(const T1& A)
00026     {
00027     arma_type_check< is_arma_cube_type<T1>::value == false >::apply();
00028     }
00029   };
00030 
00031 
00032 
00033 template<typename eT>
00034 class unwrap_cube< Cube<eT> >
00035   {
00036   public:
00037 
00038   inline unwrap_cube(const Cube<eT>& A)
00039     : M(A)
00040     {
00041     arma_extra_debug_sigprint();
00042     }
00043 
00044   const Cube<eT>& M;
00045   
00046   };
00047 
00048 
00049 
00050 template<typename T1, typename op_type>
00051 class unwrap_cube< OpCube<T1, op_type> >
00052   {
00053   public:
00054 
00055   inline unwrap_cube(const OpCube<T1, op_type>& A)
00056     : M(A)
00057     {
00058     arma_extra_debug_sigprint();
00059     }
00060 
00061   typedef typename T1::elem_type elem_type;
00062   const Cube<elem_type> M;
00063   
00064   };
00065 
00066 
00067 
00068 template<typename T1, typename T2, typename glue_cube_type>
00069 class unwrap_cube< GlueCube<T1, T2, glue_cube_type> >
00070   {
00071   public:
00072 
00073   inline unwrap_cube(const GlueCube<T1, T2, glue_cube_type>& A)
00074     : M(A)
00075     {
00076     arma_extra_debug_sigprint();
00077     }
00078 
00079   typedef typename T1::elem_type elem_type;
00080   const Cube<elem_type> M;
00081   
00082   };
00083 
00084 
00085 
00086 template<typename eT>
00087 class unwrap_cube< subview_cube<eT> >
00088   {
00089   public:
00090 
00091   inline unwrap_cube(const subview_cube<eT>& A)
00092     : M(A)
00093     {
00094     arma_extra_debug_sigprint();
00095     }
00096 
00097   const Cube<eT> M;
00098   
00099   };
00100 
00101 
00102 
00103 //
00104 //
00105 //
00106 
00107 
00108 
00109 template<typename T1>
00110 class unwrap_cube_check
00111   {
00112   private:
00113   template<typename eT> inline unwrap_cube_check(const T1& A, const Cube<eT>& B);
00114   template<typename eT> inline unwrap_cube_check(const T1& A, const subview_cube<eT>&  B);
00115   };
00116 
00117 
00118 
00119 template<typename eT>
00120 class unwrap_cube_check< Cube<eT> >
00121   {
00122   public:
00123 
00124   inline
00125   unwrap_cube_check(const Cube<eT>& A, const Cube<eT>& B)
00126     : M_local( (&A == reinterpret_cast<const Cube<eT>*>(&B)) ? new Cube<eT>(A) : 0 )
00127     , M      ( (&A == reinterpret_cast<const Cube<eT>*>(&B)) ? (*M_local)      : A )
00128     {
00129     arma_extra_debug_sigprint();
00130     }
00131   
00132   
00133   inline
00134   unwrap_cube_check(const Cube<eT>& A, const subview_cube<eT>& B)
00135     : M_local( (&A == reinterpret_cast<const Cube<eT>*>(&B.m)) ? new Cube<eT>(A) : 0 )
00136     , M      ( (&A == reinterpret_cast<const Cube<eT>*>(&B.m)) ? (*M_local)      : A )
00137     {
00138     arma_extra_debug_sigprint();
00139     }
00140 
00141 
00142   inline
00143   ~unwrap_cube_check()
00144     {
00145     arma_extra_debug_sigprint();
00146     
00147     if(M_local)
00148       {
00149       delete M_local;
00150       }
00151     }
00152   
00153   
00154   // the order below is important
00155   const Cube<eT>* M_local;
00156   const Cube<eT>& M;
00157   
00158   };
00159 
00160 
00161 
00162 template<typename T1, typename op_type>
00163 class unwrap_cube_check< OpCube<T1, op_type> >
00164   {
00165   public:
00166   typedef typename T1::elem_type elem_type;
00167 
00168   inline
00169   unwrap_cube_check(const OpCube<T1,op_type>& A, const Cube<elem_type>& B)
00170     : M(A)
00171     {
00172     arma_extra_debug_sigprint();
00173     }
00174   
00175   
00176   inline
00177   ~unwrap_cube_check()
00178     {
00179     arma_extra_debug_sigprint();
00180     }
00181   
00182   const Cube<elem_type> M;
00183   
00184   };
00185 
00186 
00187 
00188 template<typename T1, typename T2, typename glue_cube_type>
00189 class unwrap_cube_check< GlueCube<T1, T2, glue_cube_type> >
00190   {
00191   public:
00192   typedef typename T1::elem_type elem_type;
00193 
00194   inline
00195   unwrap_cube_check(const GlueCube<T1, T2, glue_cube_type>& A, const Cube<elem_type>& B)
00196     : M(A)
00197     {
00198     arma_extra_debug_sigprint();
00199     }
00200   
00201   
00202   inline
00203   ~unwrap_cube_check()
00204     {
00205     arma_extra_debug_sigprint();
00206     }
00207   
00208   
00209   const Cube<elem_type> M;
00210   
00211   };
00212 
00213 
00214 
00215 template<typename eT>
00216 class unwrap_cube_check< subview_cube<eT> >
00217   {
00218   public:
00219 
00220   template<typename T2>
00221   inline unwrap_cube_check(const subview_cube<eT>& A, const T2& junk)
00222     : M(A)
00223     {
00224     arma_extra_debug_sigprint();
00225     }
00226 
00227   const Cube<eT> M;
00228   
00229   };
00230 
00231 
00232 
00233 //! if the given object in not a cube, unwrap it into the given 'out' cube (i.e. do not create another cube)
00234 //! and provide a reference to the 'out' cube.
00235 //! if the given object is a cube, set the size of the 'out' cube to be the same as the given object
00236 //! and provide a reference to the given object.
00237 
00238 template<typename T1>
00239 class unwrap_cube_write
00240   {
00241   private:
00242   template<typename eT> inline unwrap_cube_write(Cube<eT>& out, const T1& in);
00243   };
00244 
00245 
00246 //template <>
00247 template<typename eT>
00248 class unwrap_cube_write< Cube<eT> >
00249   {
00250   public:
00251   
00252   inline
00253   unwrap_cube_write(Cube<eT>& out, const Cube<eT>& A)
00254     : M(A)
00255     {
00256     arma_extra_debug_sigprint();
00257     out.copy_size(A);
00258     }
00259   
00260   
00261   inline
00262   ~unwrap_cube_write()
00263     {
00264     arma_extra_debug_sigprint();
00265     }
00266   
00267   
00268   const Cube<eT>& M;
00269   };
00270 
00271 
00272 
00273 template<typename T1, typename op_type>
00274 class unwrap_cube_write< OpCube<T1, op_type> >
00275   {
00276   public:
00277   typedef typename T1::elem_type eT;
00278 
00279   //template<typename eT>
00280   inline
00281   unwrap_cube_write(Cube<eT>& out, const OpCube<T1,op_type>& A)
00282     : M(out)
00283     {
00284     arma_extra_debug_sigprint();
00285     out = A;
00286     }
00287   
00288   
00289   inline
00290   ~unwrap_cube_write()
00291     {
00292     arma_extra_debug_sigprint();
00293     }
00294   
00295   const Cube<eT>& M;
00296   };
00297 
00298 
00299 
00300 template<typename T1, typename T2, typename glue_type>
00301 class unwrap_cube_write< GlueCube<T1, T2, glue_type> >
00302   {
00303   public:
00304   typedef typename T1::elem_type eT;
00305   
00306   inline
00307   unwrap_cube_write(Cube<eT>& out, const GlueCube<T1, T2, glue_type>& A)
00308     : M(out)
00309     {
00310     arma_extra_debug_sigprint();
00311     out = A;
00312     }
00313   
00314   
00315   inline
00316   ~unwrap_cube_write()
00317     {
00318     arma_extra_debug_sigprint();
00319     }
00320   
00321   
00322   const Cube<eT>& M;
00323   };
00324 
00325 
00326 
00327 
00328 //template<>
00329 template<typename eT>
00330 class unwrap_cube_write< subview_cube<eT> >
00331   {
00332   public:
00333   
00334   inline
00335   unwrap_cube_write(Cube<eT>& out, const subview_cube<eT>& A)
00336     : M(out)
00337     {
00338     arma_extra_debug_sigprint();
00339     out = A;
00340     }
00341   
00342   
00343   inline
00344   ~unwrap_cube_write()
00345     {
00346     arma_extra_debug_sigprint();
00347     }
00348   
00349   
00350   const Cube<eT>& M;
00351   };
00352 
00353 
00354 
00355 //! @}