Casting from a wrapped class to a possible implemented interface

Hi. I'm running into a bit of a programming puzzle: I just checked in some code (gstreamermm) in the attempts at implementing casting from Gst::Elements to possible interfaces that the elements might implement. Presently, some elements may implement certain interfaces and it may be desirable to cast from the element to the interface.

For example, an element created with the statement:

Glib::RefPtr<Gst::Element> element = Gst::ElementFactory::create("filesrc", "source");

will implement the Gst::URIHandler interface because elements from the "filesrc" factory will implement this interface. The puzzle (or question) is: Is it possible to cast a class that in its declaration does not by default implement a certain interface and then cast it's RefPtr to the interface (assuming that the C object implements the interface)?

In gstreamer, the GstImplementsInterface <> has functionality to test if an Element implements an interface (gst_element_implements_interface <>) and to cast to that interface if necessary (gst_implements_interface_cast() <>) and I thought maybe this functionality can be used to cast from a wrapped Gst::Element to a RefPtr of the interface. Would this make sense?

José Alburquerque
jaalburquerque cox net

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]