SHAPER  9.12.0
GeomAPI_Interface.h
1 // Copyright (C) 2014-2023 CEA, EDF
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 
32 template <typename T>
33 void GeomAPI_deleter( void* p ) {
34  delete reinterpret_cast<T*>(p);
35 }
36 
38 {
39  private:
40  std::shared_ptr<char> myImpl;
41 
42  public:
44  GEOMAPI_EXPORT GeomAPI_Interface();
45 
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 
53  GEOMAPI_EXPORT virtual ~GeomAPI_Interface();
54 
56  template<class T> inline T* implPtr()
57  {
58  return reinterpret_cast<T*>(myImpl.get());
59  }
61  template<class T> inline const T* implPtr() const
62  {
63  return reinterpret_cast<T*>(myImpl.get());
64  }
66  template<class T> inline const T& impl() const
67  {
68  return *(reinterpret_cast<T*>(myImpl.get()));
69  }
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 
77  GEOMAPI_EXPORT bool empty() const;
78 };
79 
80 #endif
General base class for all interfaces in this package.
Definition: GeomAPI_Interface.h:38
T * implPtr()
Returns the pointer to the impl.
Definition: GeomAPI_Interface.h:56
virtual GEOMAPI_EXPORT ~GeomAPI_Interface()
Destructor.
Definition: GeomAPI_Interface.cpp:27
GEOMAPI_EXPORT bool empty() const
Returns true if the impl is empty.
Definition: GeomAPI_Interface.cpp:32
GeomAPI_Interface(T *theImpl)
Constructor by the impl pointer (used for internal needs)
Definition: GeomAPI_Interface.h:47
void setImpl(T *theImpl)
Updates the impl (deletes the old one)
Definition: GeomAPI_Interface.h:71
const T * implPtr() const
Returns the pointer to the impl.
Definition: GeomAPI_Interface.h:61
const T & impl() const
Returns the reference object of the impl.
Definition: GeomAPI_Interface.h:66
GEOMAPI_EXPORT GeomAPI_Interface()
None - constructor.
Definition: GeomAPI_Interface.cpp:22