7
/* Copyright (C) 1998-2002 The gtkmm Development Team
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.
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.
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.
24
#include <glib-object.h>
25
#include <glibmm/refptr.h>
34
// Type of the per-class wrap_new() functions.
35
typedef Glib::ObjectBase* (*WrapNewFunction) (GObject*);
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();
42
// Register a new type for auto allocation.
43
void wrap_register(GType type, WrapNewFunction func);
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);
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);
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.
61
template <class T> inline
62
typename T::BaseObjectType* unwrap(T* ptr)
64
return (ptr) ? ptr->gobj() : 0;
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.
70
template <class T> inline
71
const typename T::BaseObjectType* unwrap(const T* ptr)
73
return (ptr) ? ptr->gobj() : 0;
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.
79
template <class T> inline
80
typename T::BaseObjectType* unwrap(const Glib::RefPtr<T>& ptr)
82
return (ptr) ? ptr->gobj() : 0;
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.
88
template <class T> inline
89
const typename T::BaseObjectType* unwrap(const Glib::RefPtr<const T>& ptr)
91
return (ptr) ? ptr->gobj() : 0;
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.
98
template <class T> inline
99
typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<T>& ptr)
101
return (ptr) ? ptr->gobj_copy() : 0;
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.
108
template <class T> inline
109
const typename T::BaseObjectType* unwrap_copy(const Glib::RefPtr<const T>& ptr)
111
return (ptr) ? ptr->gobj_copy() : 0;
117
#endif /* _GLIBMM_WRAP_H */