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