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