Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:37

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<T>() : m_begin(), m_mgr() {}
0031 
0032   EZArrayFL<T>(MgrType* mgr) : m_begin(), m_mgr(mgr) {}
0033 
0034   EZArrayFL<T>(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   virtual ~EZArrayFL<T>() {}
0044 
0045   void resize() { assign(); }
0046 
0047   void assign(const T& t = T()) {
0048     assert(iterator() == m_begin);
0049     m_begin = m_mgr->assign(t);
0050   }
0051 
0052   const_iterator begin() const { return m_begin; }
0053   const_iterator end() const { return m_begin + m_mgr->subSize(); }
0054 
0055   reference operator[](const unsigned int i) {
0056     if (iterator() == m_begin)
0057       assign();
0058     return *(m_begin + i);
0059   }
0060 
0061   const_reference operator[](const unsigned int i) const { return *(m_begin + i); }
0062 
0063   bool uninitialized() const { return (iterator() == m_begin); }
0064 
0065   bool empty() const { return (0 == size()); }
0066 
0067   size_type size() const { return m_mgr->subSize(); }
0068 
0069   size_type capacity() const { return size(); }
0070 
0071 protected:
0072 private:
0073   //EZArrayFL( const EZArrayFL& ) ; //stop
0074   //EZArrayFL& operator=( const EZArrayFL& ) ; //stop
0075   iterator m_begin;
0076   MgrType* m_mgr;
0077 };
0078 
0079 #endif