Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:02

0001 #ifndef GEOMETRY_CALOGEOMETRY_EZArrayFL_H
0002 #define GEOMETRY_CALOGEOMETRY_EZArrayFL_H 1
0003 
0004 #include "Geometry/CaloGeometry/interface/EZMgrFL.h"
0005 
0006 /** \class EZArrayFL<T>
0007 
0008   stl-vector-LIKE Class designed to allow many small fixed-length
0009   containers to have a common memory managed by a single higher-level object.
0010 
0011   It has the usual common iterators (begin, end) and functions (size, capacity, etc)
0012   but is NOT actually an STL-vector.
0013 
0014   It practices 'on-demand', or 'lazy evaluation', only allocating
0015   memory when requested.
0016 
0017 */
0018 
0019 template <class T>
0020 class EZArrayFL {
0021 public:
0022   typedef EZMgrFL<T> MgrType;
0023   typedef typename MgrType::iterator iterator;
0024   typedef typename MgrType::const_iterator const_iterator;
0025   typedef typename MgrType::reference reference;
0026   typedef typename MgrType::const_reference const_reference;
0027   typedef typename MgrType::size_type size_type;
0028   typedef typename MgrType::value_type value_type;
0029 
0030   EZArrayFL() : m_begin(), m_mgr() {}
0031 
0032   EZArrayFL(MgrType* mgr) : m_begin(), m_mgr(mgr) {}
0033 
0034   EZArrayFL(MgrType* mgr, const_iterator start, const_iterator finis)
0035       : m_begin(0 == finis - start ? iterator() : mgr->assign()), m_mgr(mgr) {
0036     assert((finis - start) == m_mgr->subSize());
0037     iterator i(begin());
0038     for (const_iterator ic(start); ic != finis; ++ic) {
0039       (*i) = (*ic);
0040     }
0041   }
0042 
0043   void resize() { assign(); }
0044 
0045   void assign(const T& t = T()) {
0046     assert(iterator() == m_begin);
0047     m_begin = m_mgr->assign(t);
0048   }
0049 
0050   const_iterator begin() const { return m_begin; }
0051   const_iterator end() const { return m_begin + m_mgr->subSize(); }
0052 
0053   reference operator[](const unsigned int i) {
0054     if (iterator() == m_begin)
0055       assign();
0056     return *(m_begin + i);
0057   }
0058 
0059   const_reference operator[](const unsigned int i) const { return *(m_begin + i); }
0060 
0061   bool uninitialized() const { return (iterator() == m_begin); }
0062 
0063   bool empty() const { return (0 == size()); }
0064 
0065   size_type size() const { return m_mgr->subSize(); }
0066 
0067   size_type capacity() const { return size(); }
0068 
0069 protected:
0070 private:
0071   //EZArrayFL( const EZArrayFL& ) ; //stop
0072   //EZArrayFL& operator=( const EZArrayFL& ) ; //stop
0073   iterator m_begin;
0074   MgrType* m_mgr;
0075 };
0076 
0077 #endif