Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:01

0001 #ifndef Fireworks_Core_FWEvePtr_h
0002 #define Fireworks_Core_FWEvePtr_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Core
0006 // Class  :     FWEvePtr
0007 //
0008 /**\class FWEvePtr FWEvePtr.h Fireworks/Core/interface/FWEvePtr.h
0009 
0010    Description: Smart pointer which properly deals with TEveElement reference counting
0011 
0012    Usage:
0013     <usage>
0014 
0015  */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Wed Nov 12 11:08:49 EST 2008
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include "TEveElement.h"
0024 
0025 // user include files
0026 
0027 // forward declarations
0028 
0029 template <typename T>
0030 class FWEvePtr {
0031 public:
0032   FWEvePtr() {}
0033   explicit FWEvePtr(T* iElement) : m_container(new TEveElementList()) { m_container->AddElement(iElement); }
0034   // ---------- const member functions ---------------------
0035   T* operator->() const {
0036     return m_container && m_container->HasChildren() ? static_cast<T*>(m_container->FirstChild()) : static_cast<T*>(0);
0037   }
0038   T& operator*() const { return *(operator->()); }
0039 
0040   T* get() const { return (operator->()); }
0041 
0042   operator bool() const { return m_container && m_container->HasChildren(); }
0043   // ---------- static member functions --------------------
0044 
0045   // ---------- member functions ---------------------------
0046   void reset() { m_container.reset(); }
0047   void reset(T* iNew) {
0048     FWEvePtr<T> temp(iNew);
0049     swap(temp);
0050   }
0051   void destroyElement() {
0052     if (m_container) {
0053       m_container->DestroyElements();
0054     }
0055     reset();
0056   }
0057 
0058   void swap(FWEvePtr<T>& iOther) { m_container.swap(iOther.m_container); }
0059 
0060 private:
0061   //FWEvePtr(const FWEvePtr&); // stop default
0062 
0063   //const FWEvePtr& operator=(const FWEvePtr&); // stop default
0064 
0065   // ---------- member data --------------------------------
0066   std::shared_ptr<TEveElement> m_container;
0067 };
0068 
0069 #endif