podarray_proto.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 
00022 //! A lightweight array for POD types. If the amount of memory requested is small, the stack is used.
00023 
00024 template<typename eT>
00025 class podarray
00026   {
00027   public:
00028   
00029   arma_aligned const u32       n_elem; //!< number of elements held
00030   arma_aligned const eT* const mem;    //!< pointer to memory used by the object
00031   
00032   
00033   protected:
00034   //! Internal memory, to avoid calling the 'new' operator for small amounts of memory.
00035   arma_aligned eT mem_local[ 16 ];
00036   
00037   
00038   public:
00039   
00040   inline ~podarray();
00041   inline  podarray();
00042   
00043   inline                 podarray (const podarray& x);
00044   inline const podarray& operator=(const podarray& x);
00045   
00046   arma_inline explicit podarray(const u32 new_N);
00047   
00048   arma_inline explicit podarray(const eT* X, const u32 new_N);
00049   
00050   arma_inline eT& operator[] (const u32 i);
00051   arma_inline eT  operator[] (const u32 i) const;
00052   
00053   arma_inline eT& operator() (const u32 i);
00054   arma_inline eT  operator() (const u32 i) const;
00055   
00056   inline void set_size(const u32 new_n_elem);
00057   
00058   inline void fill(const eT val);
00059   
00060   inline void zeros();
00061   inline void zeros(const u32 new_n_elem);
00062   
00063   arma_inline       eT* memptr();
00064   arma_inline const eT* memptr() const;
00065   
00066   
00067   protected:
00068   
00069   inline void init(const u32 new_n_elem);
00070   
00071   };
00072 
00073 
00074 
00075 //! @}