QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
type.cpp
1 /*
2  Copyright (C) 2009-2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
3  Copyright (C) 2010 Collabora Ltd.
4  @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation; either version 2.1 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "type.h"
20 #include "quark.h"
21 #include <glib-object.h>
22 
23 namespace QGlib {
24 
25 Type Type::fromInstance(void *instance)
26 {
27  if (!instance) {
28  return Invalid;
29  } else {
30  return G_TYPE_FROM_INSTANCE(instance);
31  }
32 }
33 
34 Type Type::fromName(const char *name)
35 {
36  return g_type_from_name(name);
37 }
38 
39 QString Type::name() const
40 {
41  return QString::fromUtf8(g_type_name(m_type));
42 }
43 
44 Quark Type::nameQuark() const
45 {
46  return g_type_qname(m_type);
47 }
48 
49 bool Type::isValid() const
50 {
51  return m_type != Type::Invalid;
52 }
53 
54 bool Type::isAbstract() const
55 {
56  return G_TYPE_IS_ABSTRACT(m_type);
57 }
58 
59 bool Type::isDerived() const
60 {
61  return G_TYPE_IS_DERIVED(m_type);
62 }
63 
64 bool Type::isFundamental() const
65 {
66  return G_TYPE_IS_FUNDAMENTAL(m_type);
67 }
68 
69 bool Type::isValueType() const
70 {
71  return G_TYPE_IS_VALUE_TYPE(m_type);
72 }
73 
74 bool Type::hasValueTable() const
75 {
76  return G_TYPE_HAS_VALUE_TABLE(m_type);
77 }
78 
79 bool Type::isClassed() const
80 {
81  return G_TYPE_IS_CLASSED(m_type);
82 }
83 
84 bool Type::isInstantiatable() const
85 {
86  return G_TYPE_IS_INSTANTIATABLE(m_type);
87 }
88 
89 bool Type::isDerivable() const
90 {
91  return G_TYPE_IS_DERIVABLE(m_type);
92 }
93 
94 bool Type::isDeepDerivable() const
95 {
96  return G_TYPE_IS_DEEP_DERIVABLE(m_type);
97 }
98 
99 bool Type::isInterface() const
100 {
101  return G_TYPE_IS_INTERFACE(m_type);
102 }
103 
104 Type Type::fundamental() const
105 {
106  return G_TYPE_FUNDAMENTAL(m_type);
107 }
108 
109 Type Type::parent() const
110 {
111  return g_type_parent(m_type);
112 }
113 
114 uint Type::depth() const
115 {
116  return g_type_depth(m_type);
117 }
118 
119 Type Type::nextBase(Type rootType) const
120 {
121  return g_type_next_base(m_type, rootType);
122 }
123 
124 bool Type::isA(Type is_a_type) const
125 {
126  return g_type_is_a(m_type, is_a_type);
127 }
128 
129 static inline QList<Type> gtypeArrayToList(GType *array, uint n)
130 {
131  QList<Type> result;
132  for(uint i = 0; i<n; ++i) {
133  result.append(array[i]);
134  }
135  g_free(array);
136  return result;
137 }
138 
139 QList<Type> Type::children() const
140 {
141  uint n;
142  GType *a = g_type_children(m_type, &n);
143  return gtypeArrayToList(a, n);
144 }
145 
146 QList<Type> Type::interfaces() const
147 {
148  uint n;
149  GType *a = g_type_interfaces(m_type, &n);
150  return gtypeArrayToList(a, n);
151 }
152 
153 QList<Type> Type::interfacePrerequisites() const
154 {
155  uint n;
156  GType *a = g_type_interface_prerequisites(m_type, &n);
157  return gtypeArrayToList(a, n);
158 }
159 
160 void *Type::quarkData(const Quark & qname) const
161 {
162  return g_type_get_qdata(m_type, qname);
163 }
164 
165 void Type::setQuarkData(const Quark & qname, void *data)
166 {
167  g_type_set_qdata(m_type, qname, data);
168 }
169 
170 }