Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / zypp / zyppng / base / zyppglobal.h
1 #ifndef ZYPP_NG_BASE_ZYPPGLOBAL_H_INCLUDED
2 #define ZYPP_NG_BASE_ZYPPGLOBAL_H_INCLUDED
3
4 #include <zypp/base/Easy.h>
5
6 #ifndef EXPORT_EXPERIMENTAL_API
7 #define LIBZYPP_NG_EXPORT
8 #define LIBZYPP_NG_NO_EXPORT
9 #else
10 #include <zypp-ng_export.h>
11 #endif
12
13 /*
14  * \note those macros are inspired by the Qt framework
15  */
16
17 template <typename T> inline T *zyppGetPtrHelper(T *ptr) { return ptr; }
18 template <typename Ptr> inline auto zyppGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
19 template <typename Ptr> inline auto zyppGetPtrHelper(Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
20
21 #define ZYPP_DECLARE_PRIVATE(Class) \
22     inline Class##Private* d_func() \
23     { return reinterpret_cast<Class##Private *>(zyppGetPtrHelper(d_ptr)); } \
24     inline const Class##Private* d_func() const \
25     { return reinterpret_cast<const Class##Private *>(zyppGetPtrHelper(d_ptr)); } \
26     friend class Class##Private;
27
28 #define ZYPP_FWD_DECLARE_PRIVATE(Class) \
29     Class##Private* d_func();\
30     const Class##Private* d_func() const; \
31     friend class Class##Private;
32
33 #define ZYPP_IMPL_PRIVATE(Class) \
34     Class##Private* Class::d_func() \
35     { return reinterpret_cast<Class##Private *>(zyppGetPtrHelper(d_ptr)); } \
36     const Class##Private* Class::d_func() const \
37     { return reinterpret_cast<const Class##Private *>(zyppGetPtrHelper(d_ptr)); }
38
39 #define ZYPP_DECLARE_PUBLIC(Class)                                    \
40     inline Class* z_func() { return static_cast<Class *>(z_ptr); } \
41     inline const Class* z_func() const { return static_cast<const Class *>(z_ptr); } \
42     friend class Class;
43
44 #define Z_D() auto const d = d_func()
45 #define Z_Z() auto const z = z_func()
46
47 #endif