Salome HOME
gcc 4.9 compatibility
[modules/shaper.git] / src / GeomAPI / GeomAPI_Interface.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Interface.hxx
4 // Created:     23 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef GeomAPI_Interface_H_
8 #define GeomAPI_Interface_H_
9
10 #include <GeomAPI.h>
11
12 #include <memory>
13
14 /**\class GeomAPI_Interface
15  * \ingroup DataModel
16  * \brief General base class for all interfaces in this package
17  */
18
19 class GeomAPI_Interface
20 {
21  private:
22   std::shared_ptr<char> myImpl;  ///< pointer to the internal impl object
23
24  public:
25   /// None - constructor
26   GEOMAPI_EXPORT GeomAPI_Interface();
27
28   /// Constructor by the impl pointer (used for internal needs)
29   template<class T> explicit GeomAPI_Interface(T* theImpl)
30   {
31     myImpl.reset(reinterpret_cast<char*>(theImpl));
32   }
33
34   /// Destructor
35   GEOMAPI_EXPORT virtual ~GeomAPI_Interface();
36
37   /// Returns the pointer to the impl
38   template<class T> inline T* implPtr()
39   {
40     return reinterpret_cast<T*>(myImpl.get());
41   }
42   /// Returns the pointer to the impl
43   template<class T> inline const T* implPtr() const
44   {
45     return reinterpret_cast<T*>(myImpl.get());
46   }
47   /// Returns the reference object of the impl
48   template<class T> inline const T& impl() const
49   {
50     return *(reinterpret_cast<T*>(myImpl.get()));
51   }
52   /// Updates the impl (deletes the old one)
53   template<class T> inline void setImpl(T* theImpl)
54   {
55     myImpl.reset(reinterpret_cast<char*>(theImpl));
56   }
57
58   /// Returns true if the impl is empty
59   GEOMAPI_EXPORT bool empty() const;
60 };
61
62 #endif