blob: c9f4f910c3a4ab737170b06a71153e6005d652a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// QtQuickStreamer, QML bindings for the GStreamer multimedia framework
// Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US
//
// Author: Mathias Hasselmann <mathias@taschenorakel.de>
//
#ifndef QQUICKSTREAMER_OBJECTREFERENCE_H
#define QQUICKSTREAMER_OBJECTREFERENCE_H
#include <glib-object.h>
typedef struct _GstElementFactory GstElementFactory;
namespace QQuickStreamer {
namespace Private {
template<class T>
struct TypeClassHelper
{
typedef GType InitializerType;
static T *addReference(GType type)
{
return static_cast<T *>(g_type_class_ref(type));
}
static void removeReference(T *p)
{
g_type_class_unref(p);
}
};
template<class T>
struct ObjectHelper
{
typedef T *InitializerType;
static T *addReference(T *p)
{
return static_cast<T *>(g_object_ref(p));
}
static void removeReference(T *p)
{
g_object_unref(p);
}
};
template<class T> struct ReferenceHelper { };
template<> struct ReferenceHelper<GObjectClass> : public TypeClassHelper<GObjectClass> { };
template<> struct ReferenceHelper<GEnumClass> : public TypeClassHelper<GEnumClass> { };
template<> struct ReferenceHelper<GFlagsClass> : public TypeClassHelper<GFlagsClass> { };
template<> struct ReferenceHelper<GstElementFactory> : public ObjectHelper<GstElementFactory> { };
} // namespace Private
template<class T>
class ObjectReference
{
typedef Private::ReferenceHelper<T> TypeHelper;
public:
explicit ObjectReference(typename TypeHelper::InitializerType init)
: d(TypeHelper::addReference(init))
{
}
~ObjectReference()
{
TypeHelper::removeReference(d);
}
operator T *() const
{
return d;
}
T *operator ->() const
{
return d;
}
private:
T *const d;
};
template<class T>
inline ObjectReference<T> makeReference(T *p)
{
return ObjectReference<T>(p);
}
} // namespace QQuickStreamer
#endif // QQUICKSTREAMER_OBJECTREFERENCE_H
|