- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List

# wrap.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002
    00003 /* gstreamermm - a C++ wrapper for gstreamer
    00004  *
    00005  * Copyright 2008 The gstreamermm Development Team
    00006  *
    00007  * This library is free software; you can redistribute it and/or
    00008  * modify it under the terms of the GNU Lesser General Public
    00009  * License as published by the Free Software Foundation; either
    00010  * version 2.1 of the License, or (at your option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful,
    00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  * Lesser General Public License for more details.
    00016  *
    00017  * You should have received a copy of the GNU Lesser General Public
    00018  * License along with this library; if not, write to the Free
    00019  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00020  */
    00021
    00022 #ifndef _GSTREAMERMM_WRAP_H
    00023 #define _GSTREAMERMM_WRAP_H
    00024
    00025 #include <gst/gstminiobject.h>
    00026 #include <glibmm/refptr.h>
    00027 #include <gstreamermm/miniobject.h>
    00028
    00029 namespace Gst
    00030 {
    00031
    00032 #ifndef DOXYGEN_SHOULD_SKIP_THIS
    00033
    00034 class MiniObject;
    00035
    00036 // Type of the per-class wrap_new() functions.
    00037 typedef Gst::MiniObject* (*WrapNewFunction) (GstMiniObject*);
    00038
    00039 // Setup and free the structures used by wrap_register().
    00040 // Both functions might be called more than once.
    00041 void wrap_register_init();
    00042 void wrap_register_cleanup();
    00043
    00044 // Register a new type for auto allocation.
    00045 void wrap_register(GType type, WrapNewFunction func);
    00046
    00047 // Return the current C++ wrapper instance of the GstMiniObject,
    00048 // or automatically generate a new wrapper if there's none.
    00049 Gst::MiniObject* wrap_auto(GstMiniObject* object, bool take_copy = false);
    00050
    00055 Gst::MiniObject* wrap_create_new_wrapper_for_interface(GstMiniObject* object, GType interface_gtype);
    00056
    00057 // Return the current C++ wrapper instance of the GstMiniObject,
    00058 // or automatically generate a new wrapper if there's none.
    00059 template<class TInterface>
    00060 TInterface* wrap_auto_interface(GstMiniObject* object, bool take_copy = false)
    00061 {
    00062   if(!object)
    00063     return 0;
    00064
    00065   // Look up current C++ wrapper instance:
    00066   // GstMiniObject cannot associate a C++ instancce because it has object data: MiniObject* pCppObject = MiniObject::_get_current_wrapper(object);
    00067   MiniObject* pCppObject = 0; //MiniObject::_get_current_wrapper(object);
    00068
    00069   if(!pCppObject)
    00070   {
    00071     // There's not already a wrapper: generate a new C++ instance.
    00072     // We use exact_type_only=true avoid creating Gst::MiniObject for interfaces of unknown implementation,
    00073     // because we do not want a C++ object that does not dynamic_cast to the expected interface type.
    00074     pCppObject = wrap_create_new_wrapper_for_interface(object, TInterface::get_base_type());
    00075   }
    00076
    00077   //If no exact wrapper was created,
    00078   //create an instance of the interface,
    00079   //so we at least get the expected type:
    00080   TInterface* result = 0;
    00081   if(pCppObject)
    00082      result = dynamic_cast<TInterface*>(pCppObject);
    00083   else
    00084      result = new TInterface((typename TInterface::BaseObjectType*)object);
    00085
    00086   // take_copy=true is used where the GTK+ function doesn't do
    00087   // an extra ref for us, and always for plain struct members.
    00088   if(take_copy && result)
    00089     result->reference();
    00090
    00091   return result;
    00092 }
    00093
    00094 #endif //DOXYGEN_SHOULD_SKIP_THIS
    00095
    00096 // Get a C++ instance that wraps the C instance.
    00097 // This always returns the same C++ instance for the same C instance.
    00098 // Each wrapper has it's own override of Gst::wrap().
    00099 // use take_copy = true when wrapping a struct member.
    00101 Glib::RefPtr<Gst::MiniObject> wrap(GstMiniObject* object, bool take_copy = false);
    00102
    00103
    00107 template <class T> inline
    00108 typename T::BaseObjectType* unwrap(T* ptr)
    00109 {
    00110   return (ptr) ? ptr->gobj() : 0;
    00111 }
    00112
    00116 template <class T> inline
    00117 const typename T::BaseObjectType* unwrap(const T* ptr)
    00118 {
    00119   return (ptr) ? ptr->gobj() : 0;
    00120 }
    00121
    00125 template <class T> inline
    00126 typename T::BaseObjectType* unwrap(const Glib::RefPtr<T>& ptr)
    00127 {
    00128   return (ptr) ? ptr->gobj() : 0;
    00129 }
    00130
    00134 template <class T> inline
    00135 const typename T::BaseObjectType* unwrap(const Glib::RefPtr<const T>& ptr)
    00136 {
    00137   return (ptr) ? ptr->gobj() : 0;
    00138 }
    00139
    00144 template <class T> inline
    00145 typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<T>& ptr)
    00146 {
    00147   return (ptr) ? ptr->gobj_copy() : 0;
    00148 }
    00149
    00154 template <class T> inline
    00155 const typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<const T>& ptr)
    00156 {
    00157   return (ptr) ? ptr->gobj_copy() : 0;
    00158 }
    00159
    00160 extern GLIBMM_API GQuark quark_;
    00161 extern GLIBMM_API GQuark quark_cpp_wrapper_deleted_;
    00162
    00163 } // namespace Gst
    00164
    00165 #endif /* _GSTREAMERMM_WRAP_H */