wrap.h

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

Generated on Sat Jan 26 11:53:53 2008 for gstreamermm by  doxygen 1.5.1