alternative to assert
[gtkD.git] / src / glib / Cache.d
blobda44a0fec337b9d4087067a3f41fac197d9e6daf
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Caches.html
26 * outPack = glib
27 * outFile = Cache
28 * strct = GCache
29 * realStrct=
30 * ctorStrct=
31 * clss = Cache
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_cache_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.HashTable
45 * structWrap:
46 * - GHashTable* -> HashTable
47 * local aliases:
50 module glib.Cache;
52 private import glib.glibtypes;
54 private import lib.glib;
56 private import glib.HashTable;
58 /**
59 * Description
60 * A GCache allows sharing of complex data structures, in order to save
61 * system resources.
62 * GTK+ uses caches for GtkStyles and GdkGCs. These consume a lot of
63 * resources, so a GCache is used to see if a GtkStyle or GdkGC with the
64 * required properties already exists. If it does, then the existing
65 * object is used instead of creating a new one.
66 * GCache uses keys and values.
67 * A GCache key describes the properties of a particular resource.
68 * A GCache value is the actual resource.
70 public class Cache
73 /** the main Gtk struct */
74 protected GCache* gCache;
77 public GCache* getCacheStruct()
79 return gCache;
83 /** the main Gtk struct as a void* */
84 protected void* getStruct()
86 return cast(void*)gCache;
89 /**
90 * Sets our main struct and passes it to the parent class
92 public this (GCache* gCache)
94 this.gCache = gCache;
97 /**
102 * Creates a new GCache.
103 * value_new_func:
104 * a function to create a new object given a key.
105 * This is called by g_cache_insert() if an object with the given key
106 * does not already exist.
107 * value_destroy_func:
108 * a function to destroy an object. It is
109 * called by g_cache_remove() when the object is no longer needed (i.e. its
110 * reference count drops to 0).
111 * key_dup_func:
112 * a function to copy a key. It is called by
113 * g_cache_insert() if the key does not already exist in the GCache.
114 * key_destroy_func:
115 * a function to destroy a key. It is
116 * called by g_cache_remove() when the object is no longer needed (i.e. its
117 * reference count drops to 0).
118 * hash_key_func:
119 * a function to create a hash value from a key.
120 * hash_value_func:
121 * a function to create a hash value from a value.
122 * key_equal_func:
123 * a function to compare two keys. It should return TRUE if
124 * the two keys are equivalent.
125 * Returns:
126 * a new GCache.
128 public this (GCacheNewFunc valueNewFunc, GCacheDestroyFunc valueDestroyFunc, GCacheDupFunc keyDupFunc, GCacheDestroyFunc keyDestroyFunc, GHashFunc hashKeyFunc, GHashFunc hashValueFunc, GEqualFunc keyEqualFunc)
130 // GCache* g_cache_new (GCacheNewFunc value_new_func, GCacheDestroyFunc value_destroy_func, GCacheDupFunc key_dup_func, GCacheDestroyFunc key_destroy_func, GHashFunc hash_key_func, GHashFunc hash_value_func, GEqualFunc key_equal_func);
131 this(cast(GCache*)g_cache_new(valueNewFunc, valueDestroyFunc, keyDupFunc, keyDestroyFunc, hashKeyFunc, hashValueFunc, keyEqualFunc) );
135 * Gets the value corresponding to the given key, creating it if necessary.
136 * It first checks if the value already exists in the GCache, by using
137 * the key_equal_func function passed to g_cache_new().
138 * If it does already exist it is returned, and its reference count is increased
139 * by one.
140 * If the value does not currently exist, if is created by calling the
141 * value_new_func. The key is duplicated by calling
142 * key_dup_func and the duplicated key and value are inserted
143 * into the GCache.
144 * cache:
145 * a GCache.
146 * key:
147 * a key describing a GCache object.
148 * Returns:
149 * a pointer to a GCache value.
151 public void* insert(void* key)
153 // gpointer g_cache_insert (GCache *cache, gpointer key);
154 return g_cache_insert(gCache, key);
158 * Decreases the reference count of the given value.
159 * If it drops to 0 then the value and its corresponding key are destroyed,
160 * using the value_destroy_func and key_destroy_func passed to g_cache_new().
161 * cache:
162 * a GCache.
163 * value:
164 * the value to remove.
166 public void remove(void* value)
168 // void g_cache_remove (GCache *cache, gconstpointer value);
169 g_cache_remove(gCache, value);
173 * Frees the memory allocated for the GCache.
174 * Note that it does not destroy the keys and values which were contained in the
175 * GCache.
176 * cache:
177 * a GCache.
179 public void destroy()
181 // void g_cache_destroy (GCache *cache);
182 g_cache_destroy(gCache);
186 * Calls the given function for each of the keys in the GCache.
187 * Note
188 * func is passed three parameters, the value and key of a
189 * cache entry and the user_data. The order of value and key is different
190 * from the order in which g_hash_table_foreach() passes key-value pairs
191 * to its callback function !
192 * cache:
193 * a GCache.
194 * func:
195 * the function to call with each GCache key.
196 * user_data:
197 * user data to pass to the function.
199 public void keyForeach(GHFunc func, void* userData)
201 // void g_cache_key_foreach (GCache *cache, GHFunc func, gpointer user_data);
202 g_cache_key_foreach(gCache, func, userData);
206 * Warning
207 * g_cache_value_foreach has been deprecated since version 2.10 and should not be used in newly-written code. The reason is that it passes pointers to internal data
208 * structures to func; use g_cache_key_foreach() instead
209 * Calls the given function for each of the values in the GCache.
210 * cache:
211 * a GCache.
212 * func:
213 * the function to call with each GCache value.
214 * user_data:
215 * user data to pass to the function.
217 public void valueForeach(GHFunc func, void* userData)
219 // void g_cache_value_foreach (GCache *cache, GHFunc func, gpointer user_data);
220 g_cache_value_foreach(gCache, func, userData);