CMS 3D CMS Logo

EZArrayFL.h

Go to the documentation of this file.
00001 #ifndef GEOMETRY_CALOGEOMETRY_EZArrayFL_H
00002 #define GEOMETRY_CALOGEOMETRY_EZArrayFL_H 1
00003 
00004 #include "Geometry/CaloGeometry/interface/EZMgrFL.h"
00005 
00006 /*
00007 
00008   stl-vector-LIKE Class designed to allow many small fixed-length
00009   containers to have a common memory managed by a single higher-level object.
00010 
00011   It has the usual common iterators (begin, end) and functions (size, capacity, etc)
00012   but is NOT actually an STL-vector.
00013 
00014   It practices 'on-demand', or 'lazy evaluation', only allocating
00015   memory when requested.
00016 
00017 */
00018 
00019 
00020 template < class T >
00021 class EZArrayFL
00022 {
00023    public:
00024 
00025       typedef          EZMgrFL< T >             MgrType ;
00026       typedef typename MgrType::iterator        iterator ;
00027       typedef typename MgrType::const_iterator  const_iterator ;
00028       typedef typename MgrType::reference       reference ;
00029       typedef typename MgrType::const_reference const_reference ;
00030       typedef typename MgrType::size_type       size_type ;
00031       typedef typename MgrType::value_type      value_type ;
00032 
00033       EZArrayFL< T >( const MgrType* mgr  ) : m_begin ( 0 ) ,
00034                                               m_mgr   ( mgr )   {}
00035 
00036       EZArrayFL< T >( const MgrType* mgr   , 
00037                       const_iterator start ,
00038                       const_iterator finis       ) :
00039          m_begin ( 0==finis-start ? (iterator)0 : mgr->assign() ) ,
00040          m_mgr   ( mgr )
00041       {
00042          assert( ( finis - start ) == m_mgr->subSize() ) ;
00043          iterator i ( begin() ) ;
00044          for( const_iterator ic ( start ) ; ic != finis ; ++ic )
00045          {
00046             (*i) = (*ic) ;
00047          }
00048       }
00049 
00050       virtual ~EZArrayFL< T >() {}
00051 
00052       void resize() const { assign() ; }
00053 
00054       void assign( const T& t = T() ) const 
00055       {
00056          assert( (iterator)0 == m_begin ) ;
00057          m_begin = m_mgr->assign( t ) ;
00058       }
00059 
00060       const_iterator begin() const { return m_begin ; } 
00061       const_iterator end()   const { return m_begin + m_mgr->subSize() ; }
00062 
00063       reference operator[]( const unsigned int i ) 
00064       {
00065          if( (iterator)0 == m_begin ) assign() ;
00066          return *( m_begin + i ) ; 
00067       }
00068 
00069       const_reference operator[]( const unsigned int i ) const 
00070       {
00071          return *( m_begin + i ) ;
00072       }
00073 
00074       bool uninitialized() const { return ( (iterator)0 == m_begin ) ;  }
00075 
00076       bool empty()         const { return ( 0 == size() ) ;  }
00077 
00078       size_type size()     const { return m_mgr->subSize() ; }
00079 
00080       size_type capacity() const { return size() ; }
00081 
00082    protected:
00083 
00084    private:
00085 
00086       EZArrayFL< T >() ; //stop
00087       //EZArrayFL( const EZArrayFL& ) ; //stop
00088       //EZArrayFL& operator=( const EZArrayFL& ) ; //stop
00089       mutable iterator m_begin   ;
00090       const MgrType*   m_mgr   ;
00091 };
00092 
00093 #endif

Generated on Tue Jun 9 17:37:13 2009 for CMSSW by  doxygen 1.5.4