Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAPI / GeomAPI_Interface.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef GeomAPI_Interface_H_
21 #define GeomAPI_Interface_H_
22
23 #include <GeomAPI.h>
24
25 #include <memory>
26
27 /**\class GeomAPI_Interface
28  * \ingroup DataModel
29  * \brief General base class for all interfaces in this package
30  */
31
32 template <typename T>
33 void GeomAPI_deleter( void* p ) {
34    delete reinterpret_cast<T*>(p);
35 }
36
37 class GeomAPI_Interface
38 {
39  private:
40   std::shared_ptr<char> myImpl;  ///< pointer to the internal impl object
41
42  public:
43   /// None - constructor
44   GEOMAPI_EXPORT GeomAPI_Interface();
45
46   /// Constructor by the impl pointer (used for internal needs)
47   template<class T> explicit GeomAPI_Interface(T* theImpl)
48   {
49     myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
50   }
51
52   /// Destructor
53   GEOMAPI_EXPORT virtual ~GeomAPI_Interface();
54
55   /// Returns the pointer to the impl
56   template<class T> inline T* implPtr()
57   {
58     return reinterpret_cast<T*>(myImpl.get());
59   }
60   /// Returns the pointer to the impl
61   template<class T> inline const T* implPtr() const
62   {
63     return reinterpret_cast<T*>(myImpl.get());
64   }
65   /// Returns the reference object of the impl
66   template<class T> inline const T& impl() const
67   {
68     return *(reinterpret_cast<T*>(myImpl.get()));
69   }
70   /// Updates the impl (deletes the old one)
71   template<class T> inline void setImpl(T* theImpl)
72   {
73     myImpl = std::shared_ptr<char>(reinterpret_cast<char*>(theImpl), GeomAPI_deleter<T>);
74   }
75
76   /// Returns true if the impl is empty
77   GEOMAPI_EXPORT bool empty() const;
78 };
79
80 #endif