1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Caches.html
27  * outPack = glib
28  * outFile = Cache
29  * strct   = GCache
30  * realStrct=
31  * ctorStrct=
32  * clss    = Cache
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_cache_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * overrides:
50  */
51 
52 module glib.Cache;
53 
54 public  import gtkc.glibtypes;
55 
56 private import gtkc.glib;
57 private import glib.ConstructionException;
58 
59 
60 
61 
62 
63 
64 /**
65  * Description
66  * A GCache allows sharing of complex data structures, in order to
67  * save system resources.
68  * GTK+ uses caches for GtkStyles and GdkGCs. These consume a lot of
69  * resources, so a GCache is used to see if a GtkStyle or GdkGC with
70  * the required properties already exists. If it does, then the
71  * existing object is used instead of creating a new one.
72  * GCache uses keys and values. A GCache key describes the properties
73  * of a particular resource. A GCache value is the actual resource.
74  */
75 public class Cache
76 {
77 	
78 	/** the main Gtk struct */
79 	protected GCache* gCache;
80 	
81 	
82 	public GCache* getCacheStruct()
83 	{
84 		return gCache;
85 	}
86 	
87 	
88 	/** the main Gtk struct as a void* */
89 	protected void* getStruct()
90 	{
91 		return cast(void*)gCache;
92 	}
93 	
94 	/**
95 	 * Sets our main struct and passes it to the parent class
96 	 */
97 	public this (GCache* gCache)
98 	{
99 		this.gCache = gCache;
100 	}
101 	
102 	/**
103 	 */
104 	
105 	/**
106 	 * Creates a new GCache.
107 	 * Params:
108 	 * valueNewFunc = a function to create a new object given a key.
109 	 * This is called by g_cache_insert() if an object
110 	 * with the given key does not already exist.
111 	 * valueDestroyFunc = a function to destroy an object. It is called
112 	 * by g_cache_remove() when the object is no
113 	 * longer needed (i.e. its reference count drops
114 	 * to 0).
115 	 * keyDupFunc = a function to copy a key. It is called by
116 	 * g_cache_insert() if the key does not already exist in
117 	 * the GCache.
118 	 * keyDestroyFunc = a function to destroy a key. It is called by
119 	 * g_cache_remove() when the object is no longer
120 	 * needed (i.e. its reference count drops to 0).
121 	 * hashKeyFunc = a function to create a hash value from a key.
122 	 * hashValueFunc = a function to create a hash value from a value.
123 	 * keyEqualFunc = a function to compare two keys. It should return
124 	 * TRUE if the two keys are equivalent.
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this (GCacheNewFunc valueNewFunc, GCacheDestroyFunc valueDestroyFunc, GCacheDupFunc keyDupFunc, GCacheDestroyFunc keyDestroyFunc, GHashFunc hashKeyFunc, GHashFunc hashValueFunc, GEqualFunc keyEqualFunc)
128 	{
129 		// 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);
130 		auto p = g_cache_new(valueNewFunc, valueDestroyFunc, keyDupFunc, keyDestroyFunc, hashKeyFunc, hashValueFunc, keyEqualFunc);
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by g_cache_new(valueNewFunc, valueDestroyFunc, keyDupFunc, keyDestroyFunc, hashKeyFunc, hashValueFunc, keyEqualFunc)");
134 		}
135 		this(cast(GCache*) p);
136 	}
137 	
138 	/**
139 	 * Gets the value corresponding to the given key, creating it if
140 	 * necessary. It first checks if the value already exists in the
141 	 * GCache, by using the key_equal_func function passed to
142 	 * g_cache_new(). If it does already exist it is returned, and its
143 	 * reference count is increased by one. If the value does not currently
144 	 * exist, if is created by calling the value_new_func. The key is
145 	 * duplicated by calling key_dup_func and the duplicated key and value
146 	 * are inserted into the GCache.
147 	 * Params:
148 	 * key = a key describing a GCache object.
149 	 * Returns: a pointer to a GCache value.
150 	 */
151 	public void* insert(void* key)
152 	{
153 		// gpointer g_cache_insert (GCache *cache,  gpointer key);
154 		return g_cache_insert(gCache, key);
155 	}
156 	
157 	/**
158 	 * Decreases the reference count of the given value. If it drops to 0
159 	 * then the value and its corresponding key are destroyed, using the
160 	 * value_destroy_func and key_destroy_func passed to g_cache_new().
161 	 * Params:
162 	 * value = the value to remove.
163 	 */
164 	public void remove(void* value)
165 	{
166 		// void g_cache_remove (GCache *cache,  gconstpointer value);
167 		g_cache_remove(gCache, value);
168 	}
169 	
170 	/**
171 	 * Frees the memory allocated for the GCache.
172 	 * Note that it does not destroy the keys and values which were
173 	 * contained in the GCache.
174 	 */
175 	public void destroy()
176 	{
177 		// void g_cache_destroy (GCache *cache);
178 		g_cache_destroy(gCache);
179 	}
180 	
181 	/**
182 	 * Calls the given function for each of the keys in the GCache.
183 	 * NOTE func is passed three parameters, the value and key of a cache
184 	 * entry and the user_data. The order of value and key is different
185 	 * from the order in which g_hash_table_foreach() passes key-value
186 	 * pairs to its callback function !
187 	 * Params:
188 	 * func = the function to call with each GCache key.
189 	 * userData = user data to pass to the function.
190 	 */
191 	public void keyForeach(GHFunc func, void* userData)
192 	{
193 		// void g_cache_key_foreach (GCache *cache,  GHFunc func,  gpointer user_data);
194 		g_cache_key_foreach(gCache, func, userData);
195 	}
196 	
197 	/**
198 	 * Warning
199 	 * 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
200 	 *  data structures to func; use g_cache_key_foreach()
201 	 *  instead
202 	 * Calls the given function for each of the values in the GCache.
203 	 * Params:
204 	 * func = the function to call with each GCache value.
205 	 * userData = user data to pass to the function.
206 	 */
207 	public void valueForeach(GHFunc func, void* userData)
208 	{
209 		// void g_cache_value_foreach (GCache *cache,  GHFunc func,  gpointer user_data);
210 		g_cache_value_foreach(gCache, func, userData);
211 	}
212 }