1 /*
2     Copyright (C) 2010 Collabora Ltd. <info@collabora.co.uk>
3       @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
4 
5     This library is free software; you can redistribute it and/or modify
6     it under the terms of the GNU Lesser General Public License as published
7     by the Free Software Foundation; either version 2.1 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef QGLIB_WRAP_H
19 #define QGLIB_WRAP_H
20 
21 #include "global.h"
22 
23 namespace QGlib {
24 
25 class RefCountedObject;
26 class Type;
27 
28 /*! This function constructs a RefCountedObject that wraps the given \a instance,
29  * which is of type \a instanceType. It returns a C++ wrapper class that inherits
30  * RefCountedObject and wraps \a instanceType objects in the best possible way.
31  *
32  * This function is provided for implementing bindings that use QtGLib. It is only
33  * needed if those bindings have some reference counted instance type that is not
34  * an Object or Interface or ParamSpec (like QGst::MiniObject and QGst::Caps).
35  * You should \em not otherwise call this function directly.
36  */
37 QTGLIB_EXPORT RefCountedObject *constructWrapper(Type instanceType, void *instance);
38 
39 template <typename T, typename Enable = void>
40 struct WrapImpl {};
41 
42 #define QGLIB_REGISTER_WRAPIMPL_FOR_SUBCLASSES_OF(BaseClass, WrapFunc) \
43     namespace QGlib { \
44         template <typename T> \
45         struct WrapImpl<T, typename boost::enable_if< boost::is_base_of<BaseClass, T> >::type > \
46         { \
47             static inline RefCountedObject *wrap(typename T::CType *object) \
48             { \
49                 return WrapFunc(object); \
50             } \
51         }; \
52     } //namespace QGlib
53 
54 #define QGLIB_REGISTER_INTERFACE(IfaceClass) \
55     namespace QGlib { \
56         template <> \
57         struct WrapImpl<IfaceClass, void> \
58         { \
59             static inline RefCountedObject *wrap(IfaceClass::CType *object) \
60             { \
61                 return Private::wrapInterface(GetType<IfaceClass>(), object); \
62             } \
63         }; \
64     } //namespace QGlib
65 
66 namespace Private {
67 
68 QTGLIB_EXPORT RefCountedObject *wrapObject(void *gobject);
69 QTGLIB_EXPORT RefCountedObject *wrapParamSpec(void *param);
70 QTGLIB_EXPORT RefCountedObject *wrapInterface(Type interfaceType, void *gobject);
71 
72 } //namespace Private
73 } //namespace QGlib
74 
75 
76 #endif // QGLIB_WRAP_H
77