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 Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 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  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library 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 /* $Id: wrap.h 447 2007-10-03 09:51:41Z murrayc $ */
00026 
00027 /* Copyright (C) 1998-2002 The gtkmm Development Team
00028  *
00029  * This library is free software; you can redistribute it and/or
00030  * modify it under the terms of the GNU Library General Public
00031  * License as published by the Free Software Foundation; either
00032  * version 2 of the License, or (at your option) any later version.
00033  *
00034  * This library is distributed in the hope that it will be useful,
00035  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00036  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00037  * Library General Public License for more details.
00038  *
00039  * You should have received a copy of the GNU Library General Public
00040  * License along with this library; if not, write to the Free
00041  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00042  */
00043 
00044 #include <gst/gstminiobject.h>
00045 #include <glibmm/refptr.h>
00046 #include <gstreamermm/miniobject.h>
00047 
00048 namespace Gst
00049 {
00050 
00051 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00052 
00053 class MiniObject;
00054 
00055 // Type of the per-class wrap_new() functions.
00056 typedef Gst::MiniObject* (*WrapNewFunction) (GstMiniObject*);
00057 
00058 // Setup and free the structures used by wrap_register().
00059 // Both functions might be called more than once.
00060 void wrap_register_init();
00061 void wrap_register_cleanup();
00062 
00063 // Register a new type for auto allocation.
00064 void wrap_register(GType type, WrapNewFunction func);
00065 
00066 // Return the current C++ wrapper instance of the GstMiniObject,
00067 // or automatically generate a new wrapper if there's none.
00068 Gst::MiniObject* wrap_auto(GstMiniObject* object, bool take_copy = false);
00069 
00074 Gst::MiniObject* wrap_create_new_wrapper_for_interface(GstMiniObject* object, GType interface_gtype);
00075 
00076 // Return the current C++ wrapper instance of the GstMiniObject,
00077 // or automatically generate a new wrapper if there's none.
00078 template<class TInterface>
00079 TInterface* wrap_auto_interface(GstMiniObject* object, bool take_copy = false)
00080 {
00081   if(!object)
00082     return 0;
00083 
00084   // Look up current C++ wrapper instance:
00085   // GstMiniObject cannot associate a C++ instancce because it has object data: MiniObject* pCppObject = MiniObject::_get_current_wrapper(object);
00086   MiniObject* pCppObject = 0; //MiniObject::_get_current_wrapper(object);
00087 
00088   if(!pCppObject)
00089   {
00090     // There's not already a wrapper: generate a new C++ instance.
00091     // We use exact_type_only=true avoid creating Gst::MiniObject for interfaces of unknown implementation,
00092     // because we do not want a C++ object that does not dynamic_cast to the expected interface type.
00093     pCppObject = wrap_create_new_wrapper_for_interface(object, TInterface::get_base_type());
00094   }
00095 
00096   //If no exact wrapper was created, 
00097   //create an instance of the interface, 
00098   //so we at least get the expected type:
00099   TInterface* result = 0;
00100   if(pCppObject)
00101      result = dynamic_cast<TInterface*>(pCppObject);
00102   else
00103      result = new TInterface((typename TInterface::BaseObjectType*)object);
00104 
00105   // take_copy=true is used where the GTK+ function doesn't do
00106   // an extra ref for us, and always for plain struct members.
00107   if(take_copy && result)
00108     result->reference();
00109 
00110   return result;
00111 }
00112 
00113 #endif //DOXYGEN_SHOULD_SKIP_THIS
00114 
00115 // Get a C++ instance that wraps the C instance.
00116 // This always returns the same C++ instance for the same C instance.
00117 // Each wrapper has it's own override of Gst::wrap().
00118 // use take_copy = true when wrapping a struct member.
00120 Glib::RefPtr<Gst::MiniObject> wrap(GstMiniObject* object, bool take_copy = false);
00121 
00122 
00126 template <class T> inline
00127 typename T::BaseObjectType* unwrap(T* ptr)
00128 {
00129   return (ptr) ? ptr->gobj() : 0;
00130 }
00131 
00135 template <class T> inline
00136 const typename T::BaseObjectType* unwrap(const T* ptr)
00137 {
00138   return (ptr) ? ptr->gobj() : 0;
00139 }
00140 
00144 template <class T> inline
00145 typename T::BaseObjectType* unwrap(const Glib::RefPtr<T>& ptr)
00146 {
00147   return (ptr) ? ptr->gobj() : 0;
00148 }
00149 
00153 template <class T> inline
00154 const typename T::BaseObjectType* unwrap(const Glib::RefPtr<const T>& ptr)
00155 {
00156   return (ptr) ? ptr->gobj() : 0;
00157 }
00158 
00163 template <class T> inline
00164 typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<T>& ptr)
00165 {
00166   return (ptr) ? ptr->gobj_copy() : 0;
00167 }
00168 
00173 template <class T> inline
00174 const typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<const T>& ptr)
00175 {
00176   return (ptr) ? ptr->gobj_copy() : 0;
00177 }
00178 
00179 extern GLIBMM_API GQuark quark_;
00180 extern GLIBMM_API GQuark quark_cpp_wrapper_deleted_;
00181 
00182 } // namespace Gst
00183 
00184 
00185 #endif /* _GSTREAMERMM_WRAP_H */
00186 

Generated on Sun Jul 27 17:07:20 2008 for gstreamermm by  doxygen 1.5.4