1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef GeomAPI_Interface_H_
21 #define GeomAPI_Interface_H_
27 /**\class GeomAPI_Interface
29 * \brief General base class for all interfaces in this package
33 void GeomAPI_deleter( void* p ) {
34 delete reinterpret_cast<T*>(p);
37 class GeomAPI_Interface
40 std::shared_ptr<char> myImpl; ///< pointer to the internal impl object
43 /// None - constructor
44 GEOMAPI_EXPORT GeomAPI_Interface();
46 /// Constructor by the impl pointer (used for internal needs)
47 template<class T> explicit GeomAPI_Interface(T* theImpl)
49 myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
53 GEOMAPI_EXPORT virtual ~GeomAPI_Interface();
55 /// Returns the pointer to the impl
56 template<class T> inline T* implPtr()
58 return reinterpret_cast<T*>(myImpl.get());
60 /// Returns the pointer to the impl
61 template<class T> inline const T* implPtr() const
63 return reinterpret_cast<T*>(myImpl.get());
65 /// Returns the reference object of the impl
66 template<class T> inline const T& impl() const
68 return *(reinterpret_cast<T*>(myImpl.get()));
70 /// Updates the impl (deletes the old one)
71 template<class T> inline void setImpl(T* theImpl)
73 myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
76 /// Returns true if the impl is empty
77 GEOMAPI_EXPORT bool empty() const;