1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// A `GRelation` is a table of data which can be indexed on any number
14// of fields, rather like simple database tables. A `GRelation` contains
15// a number of records, called tuples. Each record contains a number of
16// fields. Records are not ordered, so it is not possible to find the
17// record at a particular index.
18//
19// Note that `GRelation` tables are currently limited to 2 fields.
20//
21// To create a `GRelation`, use [func@GLib.Relation.new].
22//
23// To specify which fields should be indexed, use [method@GLib.Relation.index].
24// Note that this must be called before any tuples are added to the
25// `GRelation`.
26//
27// To add records to a `GRelation` use [method@GLib.Relation.insert].
28//
29// To determine if a given record appears in a `GRelation`, use
30// [method@GLib.Relation.exists]. Note that fields are compared directly, so
31// pointers must point to the exact same position (i.e. different
32// copies of the same string will not match.)
33//
34// To count the number of records which have a particular value in a
35// given field, use [method@GLib.Relation.count].
36//
37// To get all the records which have a particular value in a given
38// field, use [method@GLib.Relation.select]. To access fields of the resulting
39// records, use [method@GLib.Tuples.index]. To free the resulting records use
40// [method@GLib.Tuples.destroy].
41//
42// To delete all records which have a particular value in a given
43// field, use [method@GLib.Relation.delete].
44//
45// To destroy the `GRelation`, use [method@GLib.Relation.destroy].
46//
47// To help debug `GRelation` objects, use [method@GLib.Relation.print].
48//
49// `GRelation` has been marked as deprecated, since this API has never
50// been fully implemented, is not very actively maintained and rarely
51// used.
52type Relation struct {
53 _ structs.HostLayout
54}
55
56func (x *Relation) GoPointer() uintptr {
57 return uintptr(unsafe.Pointer(x))
58}
59
60var xRelationCount func(uintptr, uintptr, int) int
61
62// Returns the number of tuples in a #GRelation that have the given
63// value in the given field.
64func (x *Relation) Count(KeyVar uintptr, FieldVar int) int {
65
66 cret := xRelationCount(x.GoPointer(), KeyVar, FieldVar)
67 return cret
68}
69
70var xRelationDelete func(uintptr, uintptr, int) int
71
72// Deletes any records from a #GRelation that have the given key value
73// in the given field.
74func (x *Relation) Delete(KeyVar uintptr, FieldVar int) int {
75
76 cret := xRelationDelete(x.GoPointer(), KeyVar, FieldVar)
77 return cret
78}
79
80var xRelationDestroy func(uintptr)
81
82// Destroys the #GRelation, freeing all memory allocated. However, it
83// does not free memory allocated for the tuple data, so you should
84// free that first if appropriate.
85func (x *Relation) Destroy() {
86
87 xRelationDestroy(x.GoPointer())
88
89}
90
91var xRelationExists func(uintptr, ...interface{}) bool
92
93// Returns %TRUE if a record with the given values exists in a
94// #GRelation. Note that the values are compared directly, so that, for
95// example, two copies of the same string will not match.
96func (x *Relation) Exists(varArgs ...interface{}) bool {
97
98 cret := xRelationExists(x.GoPointer(), varArgs...)
99 return cret
100}
101
102var xRelationIndex func(uintptr, int, uintptr, uintptr)
103
104// Creates an index on the given field. Note that this must be called
105// before any records are added to the #GRelation.
106func (x *Relation) Index(FieldVar int, HashFuncVar *HashFunc, KeyEqualFuncVar *EqualFunc) {
107
108 var HashFuncVarRef uintptr
109 if HashFuncVar != nil {
110 HashFuncVarPtr := uintptr(unsafe.Pointer(HashFuncVar))
111 if cbRefPtr, ok := GetCallback(HashFuncVarPtr); ok {
112 HashFuncVarRef = cbRefPtr
113 } else {
114 fcb := func(arg0 uintptr) uint {
115 cbFn := *HashFuncVar
116 return cbFn(arg0)
117 }
118 HashFuncVarRef = purego.NewCallback(fcb)
119 SaveCallbackWithClosure(HashFuncVarPtr, HashFuncVarRef, HashFuncVar)
120 }
121 }
122
123 var KeyEqualFuncVarRef uintptr
124 if KeyEqualFuncVar != nil {
125 KeyEqualFuncVarPtr := uintptr(unsafe.Pointer(KeyEqualFuncVar))
126 if cbRefPtr, ok := GetCallback(KeyEqualFuncVarPtr); ok {
127 KeyEqualFuncVarRef = cbRefPtr
128 } else {
129 fcb := func(arg0 uintptr, arg1 uintptr) bool {
130 cbFn := *KeyEqualFuncVar
131 return cbFn(arg0, arg1)
132 }
133 KeyEqualFuncVarRef = purego.NewCallback(fcb)
134 SaveCallbackWithClosure(KeyEqualFuncVarPtr, KeyEqualFuncVarRef, KeyEqualFuncVar)
135 }
136 }
137
138 xRelationIndex(x.GoPointer(), FieldVar, HashFuncVarRef, KeyEqualFuncVarRef)
139
140}
141
142var xRelationInsert func(uintptr, ...interface{})
143
144// Inserts a record into a #GRelation.
145func (x *Relation) Insert(varArgs ...interface{}) {
146
147 xRelationInsert(x.GoPointer(), varArgs...)
148
149}
150
151var xRelationPrint func(uintptr)
152
153// Outputs information about all records in a #GRelation, as well as
154// the indexes. It is for debugging.
155func (x *Relation) Print() {
156
157 xRelationPrint(x.GoPointer())
158
159}
160
161var xRelationSelect func(uintptr, uintptr, int) *Tuples
162
163// Returns all of the tuples which have the given key in the given
164// field. Use g_tuples_index() to access the returned records. The
165// returned records should be freed with g_tuples_destroy().
166func (x *Relation) Select(KeyVar uintptr, FieldVar int) *Tuples {
167
168 cret := xRelationSelect(x.GoPointer(), KeyVar, FieldVar)
169 return cret
170}
171
172// The #GTuples struct is used to return records (or tuples) from the
173// #GRelation by g_relation_select(). It only contains one public
174// member - the number of records that matched. To access the matched
175// records, you must use g_tuples_index().
176type Tuples struct {
177 _ structs.HostLayout
178
179 Len uint
180}
181
182func (x *Tuples) GoPointer() uintptr {
183 return uintptr(unsafe.Pointer(x))
184}
185
186var xTuplesDestroy func(uintptr)
187
188// Frees the records which were returned by g_relation_select(). This
189// should always be called after g_relation_select() when you are
190// finished with the records. The records are not removed from the
191// #GRelation.
192func (x *Tuples) Destroy() {
193
194 xTuplesDestroy(x.GoPointer())
195
196}
197
198var xTuplesIndex func(uintptr, int, int) uintptr
199
200// Gets a field from the records returned by g_relation_select(). It
201// returns the given field of the record at the given index. The
202// returned value should not be changed.
203func (x *Tuples) Index(IndexVar int, FieldVar int) uintptr {
204
205 cret := xTuplesIndex(x.GoPointer(), IndexVar, FieldVar)
206 return cret
207}
208
209func init() {
210 core.SetPackageName("GLIB", "glib-2.0")
211 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
212 var libs []uintptr
213 for _, libPath := range core.GetPaths("GLIB") {
214 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
215 if err != nil {
216 panic(err)
217 }
218 libs = append(libs, lib)
219 }
220
221 core.PuregoSafeRegister(&xRelationCount, libs, "g_relation_count")
222 core.PuregoSafeRegister(&xRelationDelete, libs, "g_relation_delete")
223 core.PuregoSafeRegister(&xRelationDestroy, libs, "g_relation_destroy")
224 core.PuregoSafeRegister(&xRelationExists, libs, "g_relation_exists")
225 core.PuregoSafeRegister(&xRelationIndex, libs, "g_relation_index")
226 core.PuregoSafeRegister(&xRelationInsert, libs, "g_relation_insert")
227 core.PuregoSafeRegister(&xRelationPrint, libs, "g_relation_print")
228 core.PuregoSafeRegister(&xRelationSelect, libs, "g_relation_select")
229
230 core.PuregoSafeRegister(&xTuplesDestroy, libs, "g_tuples_destroy")
231 core.PuregoSafeRegister(&xTuplesIndex, libs, "g_tuples_index")
232
233}