CMS 3D CMS Logo

PtrVectorBase.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_PtrVectorBase_h
00002 #define DataFormats_Common_PtrVectorBase_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Common
00006 // Class  :     PtrVectorBase
00007 // 
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Wed Oct 24 15:26:45 EDT 2007
00019 // $Id: PtrVectorBase.h,v 1.8 2008/05/16 15:49:13 chrjones Exp $
00020 //
00021 
00022 // system include files
00023 #include <vector>
00024 #include <typeinfo>
00025 
00026 // user include files
00027 #include "DataFormats/Common/interface/RefCore.h"
00028 
00029 // forward declarations
00030 
00031 namespace edm {
00032   class PtrVectorBase {
00033     
00034   public:
00035     typedef unsigned long key_type;
00036     typedef key_type size_type;
00037     
00038     virtual ~PtrVectorBase();
00039     
00040     // ---------- const member functions ---------------------
00042     bool isNull() const {return !isNonnull(); }
00043     
00045     //bool isNonnull() const {return id().isValid(); }
00046     bool isNonnull() const { return core_.isNonnull(); }
00047     
00049     bool operator!() const {return isNull();}
00050     
00052     ProductID id() const {return core_.id();}
00053     
00055     EDProductGetter const* productGetter() const {return core_.productGetter();}
00056     
00057     bool hasCache() const { return !cachedItems_.empty(); }
00058     
00061     bool isAvailable() const{ return core_.isAvailable(); }
00062 
00064     bool empty() const {return indicies_.empty();}
00065     
00067     size_type size() const {return indicies_.size();}
00068     
00070     size_type capacity() const {return indicies_.capacity();}
00071 
00073     void clear() { core_ = RefCore(); indicies_.clear(); cachedItems_.clear(); }
00074     
00075     bool operator==(PtrVectorBase const& iRHS) const;
00076     // ---------- static member functions --------------------
00077     
00078     // ---------- member functions ---------------------------
00080     void reserve(size_type n) {indicies_.reserve(n); cachedItems_.reserve(n);}
00081     
00082     void setProductGetter(EDProductGetter* iGetter) const { core_.setProductGetter(iGetter); }
00083 
00084     bool isTransient() const {return core_.isTransient();}
00085 
00086   protected:
00087     PtrVectorBase();
00088 
00090     void swap(PtrVectorBase& other);
00091 
00092     void push_back_base(RefCore const& core, key_type iKey, void const* iData);
00093     
00094     std::vector<void const*>::const_iterator void_begin() const {
00095       getProduct_();
00096       return cachedItems_.begin();
00097     }
00098     std::vector<void const*>::const_iterator void_end() const {
00099       getProduct_();
00100       return cachedItems_.end();
00101     }
00102     
00103     template<typename TPtr>
00104     TPtr makePtr(unsigned long iIndex) const {
00105       if (isTransient()) {
00106         return TPtr(reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
00107                   indicies_[iIndex]);
00108       }
00109       if (hasCache()) {
00110         return TPtr(this->id(),
00111                   reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
00112                   indicies_[iIndex]);
00113       }
00114       return TPtr(this->id(), indicies_[iIndex], productGetter());
00115     }
00116     
00117     template<typename TPtr>
00118     TPtr makePtr(std::vector<void const*>::const_iterator const iIt) const {
00119       if (isTransient()) {
00120         return TPtr(reinterpret_cast<typename TPtr::value_type const*>(*iIt),
00121                   indicies_[iIt - cachedItems_.begin()]);
00122       }
00123       if (hasCache()) {
00124         return TPtr(this->id(),
00125                   reinterpret_cast<typename TPtr::value_type const*>(*iIt),
00126                   indicies_[iIt - cachedItems_.begin()]);
00127       }
00128       return TPtr(this->id(), indicies_[iIt - cachedItems_.begin()], productGetter());
00129     }
00130     
00131   private:
00132     void getProduct_() const;
00133     virtual std::type_info const& typeInfo() const=0;
00134     // ---------- member data --------------------------------
00135     RefCore core_;
00136     std::vector<key_type> indicies_;
00137     mutable std::vector<void const*> cachedItems_; 
00138   };
00139 }
00140 
00141 #endif

Generated on Tue Jun 9 17:29:39 2009 for CMSSW by  doxygen 1.5.4