unwrap_cube.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup unwrap_cube
  16. //! @{
  17. template<typename T1>
  18. struct unwrap_cube
  19. {
  20. typedef typename T1::elem_type eT;
  21. inline
  22. unwrap_cube(const T1& A)
  23. : M(A)
  24. {
  25. arma_extra_debug_sigprint();
  26. }
  27. const Cube<eT> M;
  28. template<typename eT2>
  29. arma_inline bool is_alias(const Cube<eT2>&) const { return false; }
  30. };
  31. template<typename eT>
  32. struct unwrap_cube< Cube<eT> >
  33. {
  34. inline
  35. unwrap_cube(const Cube<eT>& A)
  36. : M(A)
  37. {
  38. arma_extra_debug_sigprint();
  39. }
  40. const Cube<eT>& M;
  41. template<typename eT2>
  42. arma_inline bool is_alias(const Cube<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
  43. };
  44. //
  45. //
  46. //
  47. template<typename T1>
  48. struct unwrap_cube_check
  49. {
  50. typedef typename T1::elem_type eT;
  51. inline
  52. unwrap_cube_check(const T1& A, const Cube<eT>&)
  53. : M(A)
  54. {
  55. arma_extra_debug_sigprint();
  56. arma_type_check(( is_arma_cube_type<T1>::value == false ));
  57. }
  58. const Cube<eT> M;
  59. };
  60. template<typename eT>
  61. struct unwrap_cube_check< Cube<eT> >
  62. {
  63. inline
  64. unwrap_cube_check(const Cube<eT>& A, const Cube<eT>& B)
  65. : M_local( (&A == &B) ? new Cube<eT>(A) : 0 )
  66. , M ( (&A == &B) ? (*M_local) : A )
  67. {
  68. arma_extra_debug_sigprint();
  69. }
  70. inline
  71. ~unwrap_cube_check()
  72. {
  73. arma_extra_debug_sigprint();
  74. if(M_local)
  75. {
  76. delete M_local;
  77. }
  78. }
  79. // the order below is important
  80. const Cube<eT>* M_local;
  81. const Cube<eT>& M;
  82. };
  83. //! @}