Add subclasses to QGst::Message so that it is possible to create and parse the variou...
authorGeorge Kiagiadakis <kiagiadakis.george@gmail.com>
Tue, 13 Jul 2010 19:19:03 +0000 (22:19 +0300)
committerGeorge Kiagiadakis <kiagiadakis.george@gmail.com>
Tue, 13 Jul 2010 19:19:03 +0000 (22:19 +0300)
commit98b6196d9cc742ccd7031107f814fd653eb052eb
tree03288df1ee0d052d41a1c38a41f8cf68a72d8653
parentf9a006e11265d1be5c87a7a11f2ea0f2a9f2456d
Add subclasses to QGst::Message so that it is possible to create and parse the various types of messages.

This commit also adds two helper template structures:
QGlib::Private::CanConvertTo and QGlib::Private::CanConvertFrom.
These are used to abstract away the conversion check from RefPointer::dynamicCast()
and the conversion sanity checks from ValueBase::set() and ValueBase::get().
This is required to make the Message subclasses work properly with these
functions, since they are not real Gst classes and do not have registered GTypes.
Each Message subclass gets a specialization for these structures which lets
RefPointer::dynamicCast() check the message type to determine whether to allow
the cast and ValueBase::set() to treat the subclass as if it was a Message.
ValueBase::get() will fail to compile if used with one of those subclasses
and this is done in purpose, since a Value can never contain one of these
(it will contain a Message, which has a GType!) and get() is not supposed to
allow upcasts, like dynamicCast() does.

So, to sum up, this trick allows you to do:

  QGst::MessagePtr msg = getSomeMessage();
  QGst::EosMessagePtr eosMsg = msg.dynamicCast<QGst::EosMessage>(); //checks if msg->type() == QGst::MessageEos

and

  QGlib::Value v;
  v.init<QGst::Message>();
  QGst::EosMessagePtr eosMsg = getSomeEosMessage();
  value.set(eosMsg); //will not fail, it will treat EosMessage as a Message

but not

  QGlib::Value v = getSomeValue();
  QGst::EosMessagePtr eosMsg = v.get<QGst::EosMessagePtr>(); //compilation error
src/QGlib/global.h
src/QGlib/refpointer.h
src/QGlib/type.h
src/QGlib/value.h
src/QGst/enums.h
src/QGst/global.h
src/QGst/message.cpp
src/QGst/message.h
tests/refpointertest.cpp