1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17 
18 
19 //! \addtogroup unwrap_cube
20 //! @{
21 
22 
23 
24 template<typename T1>
25 struct unwrap_cube
26   {
27   typedef typename T1::elem_type eT;
28 
29   inline
unwrap_cubeunwrap_cube30   unwrap_cube(const T1& A)
31     : M(A)
32     {
33     arma_extra_debug_sigprint();
34     }
35 
36   const Cube<eT> M;
37 
38   template<typename eT2>
is_aliasunwrap_cube39   constexpr bool is_alias(const Cube<eT2>&) const { return false; }
40   };
41 
42 
43 
44 template<typename eT>
45 struct unwrap_cube< Cube<eT> >
46   {
47   inline
unwrap_cubeunwrap_cube48   unwrap_cube(const Cube<eT>& A)
49     : M(A)
50     {
51     arma_extra_debug_sigprint();
52     }
53 
54   const Cube<eT>& M;
55 
56   template<typename eT2>
is_aliasunwrap_cube57   arma_inline bool is_alias(const Cube<eT2>& X) const { return (void_ptr(&M) == void_ptr(&X)); }
58   };
59 
60 
61 
62 //
63 //
64 //
65 
66 
67 
68 template<typename T1>
69 struct unwrap_cube_check
70   {
71   typedef typename T1::elem_type eT;
72 
73   inline
unwrap_cube_checkunwrap_cube_check74   unwrap_cube_check(const T1& A, const Cube<eT>&)
75     : M(A)
76     {
77     arma_extra_debug_sigprint();
78 
79     arma_type_check(( is_arma_cube_type<T1>::value == false ));
80     }
81 
82   inline
unwrap_cube_checkunwrap_cube_check83   unwrap_cube_check(const T1& A, const bool)
84     : M(A)
85     {
86     arma_extra_debug_sigprint();
87 
88     arma_type_check(( is_arma_cube_type<T1>::value == false ));
89     }
90 
91   const Cube<eT> M;
92   };
93 
94 
95 
96 template<typename eT>
97 struct unwrap_cube_check< Cube<eT> >
98   {
99   inline
unwrap_cube_checkunwrap_cube_check100   unwrap_cube_check(const Cube<eT>& A, const Cube<eT>& B)
101     : M_local( (&A == &B) ? new Cube<eT>(A) : nullptr )
102     , M      ( (&A == &B) ? (*M_local)      : A       )
103     {
104     arma_extra_debug_sigprint();
105     }
106 
107 
108   inline
unwrap_cube_checkunwrap_cube_check109   unwrap_cube_check(const Cube<eT>& A, const bool is_alias)
110     : M_local( is_alias ? new Cube<eT>(A) : nullptr )
111     , M      ( is_alias ? (*M_local)      : A       )
112     {
113     arma_extra_debug_sigprint();
114     }
115 
116 
117   inline
~unwrap_cube_checkunwrap_cube_check118   ~unwrap_cube_check()
119     {
120     arma_extra_debug_sigprint();
121 
122     if(M_local)  { delete M_local; }
123     }
124 
125 
126   // the order below is important
127   const Cube<eT>* M_local;
128   const Cube<eT>& M;
129   };
130 
131 
132 
133 //! @}
134