QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
object.h
1 /*
2  Copyright (C) 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 #ifndef QGLIB_OBJECT_H
20 #define QGLIB_OBJECT_H
21 
22 #include "global.h"
23 #include "refpointer.h"
24 #include "paramspec.h"
25 #include "value.h"
26 #include "type.h"
27 #include <QtCore/QList>
28 
29 namespace QGlib {
30 
38 class QTGLIB_EXPORT ObjectBase : public RefCountedObject
39 {
40 public:
44  ParamSpecPtr findProperty(const char *name) const;
45 
47  QList<ParamSpecPtr> listProperties() const;
48 
52  Value property(const char *name) const;
53 
58  template <class T> void setProperty(const char *name, const T & value);
59 
65  void setProperty(const char *name, const Value & value);
66 
67  void *data(const char *key) const;
68  void *stealData(const char *key) const;
69  void setData(const char *key, void *data, void (*destroyCallback)(void*) = NULL);
70 
71  void *quarkData(const Quark & quark) const;
72  void *stealQuarkData(const Quark & quark) const;
73  void setQuarkData(const Quark & quark, void *data, void (*destroyCallback)(void*) = NULL);
74 
75 protected:
76  ObjectBase() {}
77  virtual ~ObjectBase() {}
78  Q_DISABLE_COPY(ObjectBase);
79 
80  virtual void ref(bool increaseRef);
81  virtual void unref();
82 };
83 
89 class QTGLIB_EXPORT Object : virtual public ObjectBase
90 {
91  QGLIB_WRAPPER(Object)
92 };
93 
99 class QTGLIB_EXPORT Interface : virtual public ObjectBase
100 {
101  QGLIB_WRAPPER_DIFFERENT_C_CLASS(Interface, Object)
102 };
103 
104 
105 template <class T>
106 void ObjectBase::setProperty(const char *name, const T & value)
107 {
108  ParamSpecPtr param = findProperty(name);
109  if (param) {
110  Value v;
111  v.init(param->valueType());
112  v.set<T>(value);
113  setProperty(name, v);
114  }
115 }
116 
117 } //namespace QGlib
118 
119 QGLIB_REGISTER_TYPE(QGlib::Object)
120 QGLIB_REGISTER_TYPE(QGlib::Interface)
121 QGLIB_REGISTER_WRAPIMPL_FOR_SUBCLASSES_OF(QGlib::Object, QGlib::Private::wrapObject)
122 
123 #endif
Common virtual base class for Object and Interface.
Definition: object.h:38
Smart pointer class for working with wrapper classes that support reference counting.
Definition: global.h:56
Wrapper class for GValue.
Definition: value.h:74
void setProperty(const char *name, const T &value)
Definition: object.h:106
Base class for interface wrappers.
Definition: object.h:99
void init(Type type)
Definition: value.cpp:239
ParamSpecPtr findProperty(const char *name) const
Definition: object.cpp:39
void set(const T &data)
Definition: value.h:325
Base class for all the reference-counted object wrappers.
Definition: refpointer.h:179
Wrapper class for GObject.
Definition: object.h:89
Wrapper class for GQuark.
Definition: quark.h:42