podarray_meat.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 podarray
00017 //! @{
00018 
00019 
00020 template<typename T1>
00021 inline
00022 podarray<T1>::~podarray()
00023   {
00024   arma_extra_debug_sigprint_this(this);
00025   
00026   if(n_elem > sizeof(mem_local)/sizeof(T1) )
00027     {
00028     delete [] mem;
00029     }
00030 
00031   if(arma_config::debug == true)
00032     {
00033     access::rw(mem) = 0;
00034     }
00035   }
00036 
00037 
00038 
00039 template<typename T1>
00040 inline
00041 podarray<T1>::podarray()
00042   : n_elem(0)
00043   , mem(0)
00044   {
00045   arma_extra_debug_sigprint_this(this);
00046   }
00047   
00048   
00049 
00050 template<typename T1>
00051 inline
00052 podarray<T1>::podarray(const podarray& x)
00053   : n_elem(0)
00054   , mem(0)
00055   {
00056   arma_extra_debug_sigprint();
00057   
00058   this->operator=(x);
00059   }
00060   
00061   
00062   
00063 template<typename T1>
00064 inline
00065 const podarray<T1>&
00066 podarray<T1>::operator=(const podarray& x)
00067   {
00068   arma_extra_debug_sigprint();
00069   
00070   if(this != &x)
00071     {
00072     init(x.n_elem);
00073     
00074     for(u32 i=0; i<n_elem; ++i)
00075       {
00076       access::rw(mem[i]) = x.mem[i];
00077       }
00078     }
00079         
00080   return *this;
00081   }
00082   
00083 
00084 
00085 template<typename T1>
00086 arma_inline
00087 podarray<T1>::podarray(const u32 new_n_elem)
00088   : n_elem(0)
00089   , mem(0)
00090   {
00091   arma_extra_debug_sigprint_this(this);
00092   
00093   init(new_n_elem);
00094   }
00095 
00096 
00097 template<typename T1>
00098 arma_inline
00099 T1
00100 podarray<T1>::operator[] (const u32 i) const
00101   {
00102   return mem[i];
00103   }
00104 
00105 
00106 
00107 template<typename T1>
00108 arma_inline
00109 T1&
00110 podarray<T1>::operator[] (const u32 i)
00111   {
00112   return access::rw(mem[i]);
00113   }
00114   
00115   
00116   
00117 template<typename T1>
00118 arma_inline
00119 T1
00120 podarray<T1>::operator() (const u32 i) const
00121   {
00122   arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds");
00123   return mem[i];
00124   }
00125 
00126 
00127 
00128 template<typename T1>
00129 arma_inline
00130 T1&
00131 podarray<T1>::operator() (const u32 i)
00132   {
00133   arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds");
00134   return access::rw(mem[i]);
00135   }
00136 
00137 
00138 
00139 template<typename T1>
00140 inline
00141 void
00142 podarray<T1>::set_size(const u32 new_n_elem)
00143   {
00144   arma_extra_debug_sigprint();
00145   
00146   init(new_n_elem);
00147   }
00148 
00149 
00150 
00151 template<typename T1>
00152 inline
00153 void
00154 podarray<T1>::fill(const T1 val)
00155   {
00156   arma_extra_debug_sigprint();
00157   
00158   for(u32 i=0; i<n_elem; ++i)
00159     {
00160     access::rw(mem[i]) = val;
00161     }
00162   }
00163 
00164 
00165 
00166 template<typename T1>
00167 inline
00168 void
00169 podarray<T1>::zeros()
00170   {
00171   arma_extra_debug_sigprint();
00172   
00173   fill(0);
00174   }
00175 
00176 
00177 
00178 template<typename T1>
00179 inline
00180 void
00181 podarray<T1>::zeros(const u32 new_n_elem)
00182   {
00183   arma_extra_debug_sigprint();
00184   
00185   init(new_n_elem);
00186   fill(0);
00187   }
00188 
00189 
00190 
00191 template<typename T1>
00192 arma_inline
00193 T1*
00194 podarray<T1>::memptr()
00195   {
00196   return const_cast<T1*>(mem);
00197   }
00198   
00199   
00200 
00201 template<typename T1>
00202 arma_inline
00203 const T1*
00204 podarray<T1>::memptr() const
00205   {
00206   return mem;
00207   }
00208 
00209 
00210 
00211 template<typename T1>
00212 inline
00213 void
00214 podarray<T1>::init(const u32 new_n_elem)
00215   {
00216   arma_extra_debug_sigprint();
00217   
00218   if(n_elem == new_n_elem)
00219     {
00220     return;
00221     }
00222     
00223   if(n_elem > sizeof(mem_local)/sizeof(T1) )
00224     {
00225     delete [] mem;
00226     }
00227   
00228   if(new_n_elem <= sizeof(mem_local)/sizeof(T1) )
00229     {
00230     access::rw(mem) = mem_local;
00231     }
00232   else
00233     {
00234     access::rw(mem) = new T1[new_n_elem];
00235     }
00236   
00237   access::rw(n_elem) = new_n_elem;
00238   
00239   
00240   }
00241 
00242 //! @}