advance compilation to include plugin_ui.cc
[ardour.git] / libs / glibmm2 / glibmm / wrap.h
1 // -*- c++ -*-
2 #ifndef _GLIBMM_WRAP_H
3 #define _GLIBMM_WRAP_H
4
5 /* $Id$ */
6
7 /* Copyright (C) 1998-2002 The gtkmm Development Team
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the Free
21  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include <glib-object.h>
25 #include <glibmm/refptr.h>
26
27
28 namespace Glib
29 {
30
31 class ObjectBase;
32 class Object;
33
34 // Type of the per-class wrap_new() functions.
35 typedef Glib::ObjectBase* (*WrapNewFunction) (GObject*);
36
37 // Setup and free the structures used by wrap_register().
38 // Both functions might be called more than once.
39 void wrap_register_init();
40 void wrap_register_cleanup();
41
42 // Register a new type for auto allocation.
43 void wrap_register(GType type, WrapNewFunction func);
44
45 // Return the current C++ wrapper instance of the GObject,
46 // or automatically generate a new wrapper if there's none.
47 Glib::ObjectBase* wrap_auto(GObject* object, bool take_copy = false);
48
49 // Get a C++ instance that wraps the C instance.
50 // This always returns the same C++ instance for the same C instance.
51 // Each wrapper has it's own override of Glib::wrap().
52 // use take_copy = true when wrapping a struct member.
53 // TODO: move to object.h ?
54 /** @relates Glib::Object */
55 Glib::RefPtr<Glib::Object> wrap(GObject* object, bool take_copy = false);
56
57
58 /** Get the underlying C instance from the C++ instance.  This is just
59  * like calling gobj(), but it does its own check for a NULL pointer.
60  */
61 template <class T> inline
62 typename T::BaseObjectType* unwrap(T* ptr)
63 {
64   return (ptr) ? ptr->gobj() : 0;
65 }
66
67 /** Get the underlying C instance from the C++ instance.  This is just
68  * like calling gobj(), but it does its own check for a NULL pointer.
69  */
70 template <class T> inline
71 const typename T::BaseObjectType* unwrap(const T* ptr)
72 {
73   return (ptr) ? ptr->gobj() : 0;
74 }
75
76 /** Get the underlying C instance from the C++ instance.  This is just
77  * like calling gobj(), but it does its own check for a NULL pointer.
78  */
79 template <class T> inline
80 typename T::BaseObjectType* unwrap(const Glib::RefPtr<T>& ptr)
81 {
82   return (ptr) ? ptr->gobj() : 0;
83 }
84
85 /** Get the underlying C instance from the C++ instance.  This is just
86  * like calling gobj(), but it does its own check for a NULL pointer.
87  */
88 template <class T> inline
89 const typename T::BaseObjectType* unwrap(const Glib::RefPtr<const T>& ptr)
90 {
91   return (ptr) ? ptr->gobj() : 0;
92 }
93
94 /** Get the underlying C instance from the C++ instance and acquire a
95  * reference.  This is just like calling gobj_copy(), but it does its own
96  * check for a NULL pointer.
97  */
98 template <class T> inline
99 typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<T>& ptr)
100 {
101   return (ptr) ? ptr->gobj_copy() : 0;
102 }
103
104 /** Get the underlying C instance from the C++ instance and acquire a
105  * reference.  This is just like calling gobj_copy(), but it does its own
106  * check for a NULL pointer.
107  */
108 template <class T> inline
109 const typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<const T>& ptr)
110 {
111   return (ptr) ? ptr->gobj_copy() : 0;
112 }
113
114 } // namespace Glib
115
116
117 #endif /* _GLIBMM_WRAP_H */
118