1 dnl $Id: class_boxedtype.m4 413 2007-05-14 19:28:31Z murrayc $
4 dnl _CLASS_BOXEDTYPE(Region, GdkRegion, gdk_region_new, gdk_region_copy, gdk_region_destroy)
7 define(`_CLASS_BOXEDTYPE',`dnl
10 dnl Define the args for later macros
11 define(`__CPPNAME__',`$1')
12 define(`__CNAME__',`$2')
13 define(`__BOXEDTYPE_FUNC_NEW',`$3')
14 define(`__BOXEDTYPE_FUNC_COPY',`$4')
15 define(`__BOXEDTYPE_FUNC_FREE',`$5')
17 define(`_CUSTOM_DEFAULT_CTOR',`dnl
19 dnl Define this macro to be tested for later.
20 define(`__BOOL_CUSTOM_DEFAULT_CTOR__',`$1')
26 _SECTION(SECTION_CLASS2)
27 ') dnl End of _CLASS_BOXEDTYPE.
29 dnl Some of the Gdk types are unions - e.g. GdkEvent.
30 define(`_CUSTOM_STRUCT_PROTOTYPE',`dnl
32 dnl Define this macro to be tested for later.
33 define(`__BOOL_CUSTOM_STRUCT_PROTOTYPE__',`$1')
38 dnl _END_CLASS_BOXEDTYPE()
39 dnl denotes the end of a class
41 define(`_END_CLASS_BOXEDTYPE',`
42 _SECTION(SECTION_HEADER1)
43 ifdef(`__BOOL_CUSTOM_STRUCT_PROTOTYPE__',`dnl
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 extern "C" { typedef struct _`'__CNAME__ __CNAME__; }
50 _SECTION(SECTION_HEADER3)
54 /** @relates __NAMESPACE__::__CPPNAME__
55 * @param lhs The left-hand side
56 * @param rhs The right-hand side
58 inline void swap(__CPPNAME__& lhs, __CPPNAME__& rhs)
65 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
68 /** A Glib::wrap() method for this object.
70 * @param object The C instance.
71 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
72 * @result A C++ instance that wraps this C instance.
74 * @relates __NAMESPACE__::__CPPNAME__
76 __NAMESPACE__::__CPPNAME__ wrap(__CNAME__* object, bool take_copy = false);
77 ')dnl endif __BOOL_NO_WRAP_FUNCTION__
79 #ifndef DOXYGEN_SHOULD_SKIP_THIS
81 class Value<__NAMESPACE__::__CPPNAME__> : public Glib::Value_Boxed<__NAMESPACE__::__CPPNAME__>
83 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
87 _SECTION(SECTION_SRC_GENERATED)
89 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
94 __NAMESPACE__::__CPPNAME__ wrap(__CNAME__* object, bool take_copy)
96 return __NAMESPACE__::__CPPNAME__`'(object, take_copy);
106 dnl The implementation:
110 GType __CPPNAME__::get_type()
112 return _GET_TYPE_FUNC(__CNAME__);
115 ifdef(`__BOOL_CUSTOM_DEFAULT_CTOR__',`dnl
117 __CPPNAME__::__CPPNAME__`'()
119 ifelse(__BOXEDTYPE_FUNC_NEW,NONE,`dnl
120 gobject_ (0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.
122 gobject_ (__BOXEDTYPE_FUNC_NEW`'())
125 ')dnl endif __BOOL_CUSTOM_DEFAULT_CTOR__
127 __CPPNAME__::__CPPNAME__`'(const __CPPNAME__& other)
129 gobject_ ((other.gobject_) ? __BOXEDTYPE_FUNC_COPY`'(other.gobject_) : 0)
132 __CPPNAME__::__CPPNAME__`'(__CNAME__* gobject, bool make_a_copy)
134 // For BoxedType wrappers, make_a_copy is true by default. The static
135 // BoxedType wrappers must always take a copy, thus make_a_copy = true
136 // ensures identical behaviour if the default argument is used.
137 gobject_ ((make_a_copy && gobject) ? __BOXEDTYPE_FUNC_COPY`'(gobject) : gobject)
140 __CPPNAME__& __CPPNAME__::operator=(const __CPPNAME__`'& other)
142 __CPPNAME__ temp (other);
147 __CPPNAME__::~__CPPNAME__`'()
149 dnl This could be a free or an unref, we do not need to know.
151 __BOXEDTYPE_FUNC_FREE`'(gobject_);
154 void __CPPNAME__::swap(__CPPNAME__& other)
156 __CNAME__ *const temp = gobject_;
157 gobject_ = other.gobject_;
158 other.gobject_ = temp;
161 __CNAME__* __CPPNAME__::gobj_copy() const
163 return __BOXEDTYPE_FUNC_COPY`'(gobject_);
178 dnl The actual class, e.g. Pango::FontDescription, declaration:
180 _IMPORT(SECTION_CLASS1)
182 #ifndef DOXYGEN_SHOULD_SKIP_THIS
183 typedef __CPPNAME__ CppObjectType;
184 typedef __CNAME__ BaseObjectType;
186 static GType get_type() G_GNUC_CONST;
187 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
189 ifdef(`__BOOL_CUSTOM_DEFAULT_CTOR__',`dnl
194 explicit __CPPNAME__`'(__CNAME__* gobject, bool make_a_copy = true);
196 __CPPNAME__`'(const __CPPNAME__& other);
197 __CPPNAME__& operator=(const __CPPNAME__& other);
201 void swap(__CPPNAME__& other);
203 ///Provides access to the underlying C instance.
204 __CNAME__* gobj() { return gobject_; }
206 ///Provides access to the underlying C instance.
207 const __CNAME__* gobj() const { return gobject_; }
209 ///Provides access to the underlying C instance. The caller is responsible for freeing it. Use when directly setting fields in structs.
210 __CNAME__* gobj_copy() const;
216 _IMPORT(SECTION_CLASS2)