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// `GStringChunk` provides efficient storage of groups of strings
14//
15// String chunks are used to store groups of strings. Memory is
16// allocated in blocks, and as strings are added to the `GStringChunk`
17// they are copied into the next free position in a block. When a block
18// is full a new block is allocated.
19//
20// When storing a large number of strings, string chunks are more
21// efficient than using [func@GLib.strdup] since fewer calls to `malloc()`
22// are needed, and less memory is wasted in memory allocation overheads.
23//
24// By adding strings with [method@GLib.StringChunk.insert_const] it is also
25// possible to remove duplicates.
26//
27// To create a new `GStringChunk` use [func@GLib.StringChunk.new].
28//
29// To add strings to a `GStringChunk` use [method@GLib.StringChunk.insert].
30//
31// To add strings to a `GStringChunk`, but without duplicating strings
32// which are already in the `GStringChunk`, use [method@GLib.StringChunk.insert_const].
33//
34// To free the entire `GStringChunk` use [method@GLib.StringChunk.free].
35// It is not possible to free individual strings.
36type StringChunk struct {
37 _ structs.HostLayout
38}
39
40func (x *StringChunk) GoPointer() uintptr {
41 return uintptr(unsafe.Pointer(x))
42}
43
44var xStringChunkClear func(uintptr)
45
46// Frees all strings contained within the #GStringChunk.
47// After calling g_string_chunk_clear() it is not safe to
48// access any of the strings which were contained within it.
49func (x *StringChunk) Clear() {
50
51 xStringChunkClear(x.GoPointer())
52
53}
54
55var xStringChunkFree func(uintptr)
56
57// Frees all memory allocated by the #GStringChunk.
58// After calling g_string_chunk_free() it is not safe to
59// access any of the strings which were contained within it.
60func (x *StringChunk) Free() {
61
62 xStringChunkFree(x.GoPointer())
63
64}
65
66var xStringChunkInsert func(uintptr, string) string
67
68// Adds a copy of @string to the #GStringChunk.
69// It returns a pointer to the new copy of the string
70// in the #GStringChunk. The characters in the string
71// can be changed, if necessary, though you should not
72// change anything after the end of the string.
73//
74// Unlike g_string_chunk_insert_const(), this function
75// does not check for duplicates. Also strings added
76// with g_string_chunk_insert() will not be searched
77// by g_string_chunk_insert_const() when looking for
78// duplicates.
79func (x *StringChunk) Insert(StringVar string) string {
80
81 cret := xStringChunkInsert(x.GoPointer(), StringVar)
82 return cret
83}
84
85var xStringChunkInsertConst func(uintptr, string) string
86
87// Adds a copy of @string to the #GStringChunk, unless the same
88// string has already been added to the #GStringChunk with
89// g_string_chunk_insert_const().
90//
91// This function is useful if you need to copy a large number
92// of strings but do not want to waste space storing duplicates.
93// But you must remember that there may be several pointers to
94// the same string, and so any changes made to the strings
95// should be done very carefully.
96//
97// Note that g_string_chunk_insert_const() will not return a
98// pointer to a string added with g_string_chunk_insert(), even
99// if they do match.
100func (x *StringChunk) InsertConst(StringVar string) string {
101
102 cret := xStringChunkInsertConst(x.GoPointer(), StringVar)
103 return cret
104}
105
106var xStringChunkInsertLen func(uintptr, string, int) string
107
108// Adds a copy of the first @len bytes of @string to the #GStringChunk.
109// The copy is nul-terminated.
110//
111// Since this function does not stop at nul bytes, it is the caller's
112// responsibility to ensure that @string has at least @len addressable
113// bytes.
114//
115// The characters in the returned string can be changed, if necessary,
116// though you should not change anything after the end of the string.
117func (x *StringChunk) InsertLen(StringVar string, LenVar int) string {
118
119 cret := xStringChunkInsertLen(x.GoPointer(), StringVar, LenVar)
120 return cret
121}
122
123func init() {
124 core.SetPackageName("GLIB", "glib-2.0")
125 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
126 var libs []uintptr
127 for _, libPath := range core.GetPaths("GLIB") {
128 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
129 if err != nil {
130 panic(err)
131 }
132 libs = append(libs, lib)
133 }
134
135 core.PuregoSafeRegister(&xStringChunkClear, libs, "g_string_chunk_clear")
136 core.PuregoSafeRegister(&xStringChunkFree, libs, "g_string_chunk_free")
137 core.PuregoSafeRegister(&xStringChunkInsert, libs, "g_string_chunk_insert")
138 core.PuregoSafeRegister(&xStringChunkInsertConst, libs, "g_string_chunk_insert_const")
139 core.PuregoSafeRegister(&xStringChunkInsertLen, libs, "g_string_chunk_insert_len")
140
141}