// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #ifndef MED_SharedPtr_HeaderFile #define MED_SharedPtr_HeaderFile #include namespace MED { //! To extend the boost::shared_ptr to support such features automatic dynamic cast /*! All entities of the MEDWrapper package are handled as pointer. This class was introduced to provide correct and flexible memory management for all of the MEDWrapper objects. */ template class SharedPtr: public boost::shared_ptr { public: //! Default constructor SharedPtr() {} //! Construct the class by any type of a pointer template explicit SharedPtr(Y * p): boost::shared_ptr(p) {} //! Construct the class by any specialisation of the class template SharedPtr(SharedPtr const & r): boost::shared_ptr(boost::dynamic_pointer_cast(r)) {} //! Copy-constructor template SharedPtr& operator=(SharedPtr const & r) { SharedPtr(r).swap(*this); return *this; } //! Introduce a flexible way to reset the wrapped pointer template SharedPtr& operator()(Y * p) // Y must be complete { return operator=(SharedPtr(p)); } //! Introduce a flexible way to reset the wrapped pointer template SharedPtr& operator()(SharedPtr const & r) // Y must be complete { return operator=(SharedPtr(r)); } //! To provide a flexible way to use reference to the wrapped pointer (const version) operator const T& () const { return *(this->get()); } //! To provide a flexible way to use reference to the wrapped pointer operator T& () { return *(this->get()); } }; } #endif