1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef GeomAPI_Interface_H_
22 #define GeomAPI_Interface_H_
28 /**\class GeomAPI_Interface
30 * \brief General base class for all interfaces in this package
34 void GeomAPI_deleter( void* p ) {
35 delete reinterpret_cast<T*>(p);
38 class GeomAPI_Interface
41 std::shared_ptr<char> myImpl; ///< pointer to the internal impl object
44 /// None - constructor
45 GEOMAPI_EXPORT GeomAPI_Interface();
47 /// Constructor by the impl pointer (used for internal needs)
48 template<class T> explicit GeomAPI_Interface(T* theImpl)
50 myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
54 GEOMAPI_EXPORT virtual ~GeomAPI_Interface();
56 /// Returns the pointer to the impl
57 template<class T> inline T* implPtr()
59 return reinterpret_cast<T*>(myImpl.get());
61 /// Returns the pointer to the impl
62 template<class T> inline const T* implPtr() const
64 return reinterpret_cast<T*>(myImpl.get());
66 /// Returns the reference object of the impl
67 template<class T> inline const T& impl() const
69 return *(reinterpret_cast<T*>(myImpl.get()));
71 /// Updates the impl (deletes the old one)
72 template<class T> inline void setImpl(T* theImpl)
74 myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
77 /// Returns true if the impl is empty
78 GEOMAPI_EXPORT bool empty() const;