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  = 
27  * outPack = glib
28  * outFile = MappedFile
29  * strct   = GMappedFile
30  * realStrct=
31  * ctorStrct=
32  * clss    = MappedFile
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_mapped_file_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * structWrap:
50  * 	- GMappedFile* -> MappedFile
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module glib.MappedFile;
57 
58 public  import gtkc.glibtypes;
59 
60 private import gtkc.glib;
61 private import glib.ConstructionException;
62 
63 
64 private import glib.Str;
65 private import glib.ErrorG;
66 private import glib.GException;
67 
68 
69 
70 
71 /**
72  * Description
73  * There is a group of functions which wrap the common POSIX functions
74  * dealing with filenames (g_open(), g_rename(), g_mkdir(), g_stat(),
75  * g_unlink(), g_remove(), g_fopen(), g_freopen()). The point of these
76  * wrappers is to make it possible to handle file names with any Unicode
77  * characters in them on Windows without having to use ifdefs and the
78  * wide character API in the application code.
79  * The pathname argument should be in the GLib file name encoding. On
80  * POSIX this is the actual on-disk encoding which might correspond to
81  * the locale settings of the process (or the
82  * G_FILENAME_ENCODING environment variable), or not.
83  * On Windows the GLib file name encoding is UTF-8. Note that the
84  * Microsoft C library does not use UTF-8, but has separate APIs for
85  * current system code page and wide characters (UTF-16). The GLib
86  * wrappers call the wide character API if present (on modern Windows
87  * systems), otherwise convert to/from the system code page.
88  * Another group of functions allows to open and read directories
89  * in the GLib file name encoding. These are g_dir_open(),
90  * g_dir_read_name(), g_dir_rewind(), g_dir_close().
91  */
92 public class MappedFile
93 {
94 	
95 	/** the main Gtk struct */
96 	protected GMappedFile* gMappedFile;
97 	
98 	
99 	public GMappedFile* getMappedFileStruct()
100 	{
101 		return gMappedFile;
102 	}
103 	
104 	
105 	/** the main Gtk struct as a void* */
106 	protected void* getStruct()
107 	{
108 		return cast(void*)gMappedFile;
109 	}
110 	
111 	/**
112 	 * Sets our main struct and passes it to the parent class
113 	 */
114 	public this (GMappedFile* gMappedFile)
115 	{
116 		this.gMappedFile = gMappedFile;
117 	}
118 	
119 	/**
120 	 */
121 	
122 	/**
123 	 * Maps a file into memory. On UNIX, this is using the mmap() function.
124 	 * If writable is TRUE, the mapped buffer may be modified, otherwise
125 	 * it is an error to modify the mapped buffer. Modifications to the buffer
126 	 * are not visible to other processes mapping the same file, and are not
127 	 * written back to the file.
128 	 * Note that modifications of the underlying file might affect the contents
129 	 * of the GMappedFile. Therefore, mapping should only be used if the file
130 	 * will not be modified, or if all modifications of the file are done
131 	 * atomically (e.g. using g_file_set_contents()).
132 	 * Since 2.8
133 	 * Params:
134 	 * filename = The path of the file to load, in the GLib filename encoding
135 	 * writable = whether the mapping should be writable
136 	 * Throws: GException on failure.
137 	 * Throws: ConstructionException GTK+ fails to create the object.
138 	 */
139 	public this (string filename, int writable)
140 	{
141 		// GMappedFile * g_mapped_file_new (const gchar *filename,  gboolean writable,  GError **error);
142 		GError* err = null;
143 		
144 		auto p = g_mapped_file_new(Str.toStringz(filename), writable, &err);
145 		
146 		if (err !is null)
147 		{
148 			throw new GException( new ErrorG(err) );
149 		}
150 		
151 		if(p is null)
152 		{
153 			throw new ConstructionException("null returned by g_mapped_file_new(Str.toStringz(filename), writable, &err)");
154 		}
155 		this(cast(GMappedFile*) p);
156 	}
157 	
158 	/**
159 	 * Increments the reference count of file by one. It is safe to call
160 	 * this function from any thread.
161 	 * Since 2.22
162 	 * Returns: the passed in GMappedFile.
163 	 */
164 	public MappedFile doref()
165 	{
166 		// GMappedFile * g_mapped_file_ref (GMappedFile *file);
167 		auto p = g_mapped_file_ref(gMappedFile);
168 		
169 		if(p is null)
170 		{
171 			return null;
172 		}
173 		
174 		return new MappedFile(cast(GMappedFile*) p);
175 	}
176 	
177 	/**
178 	 * Decrements the reference count of file by one. If the reference count
179 	 * drops to 0, unmaps the buffer of file and frees it.
180 	 * It is safe to call this function from any thread.
181 	 * Since 2.22
182 	 */
183 	public void unref()
184 	{
185 		// void g_mapped_file_unref (GMappedFile *file);
186 		g_mapped_file_unref(gMappedFile);
187 	}
188 	
189 	/**
190 	 * Warning
191 	 * g_mapped_file_free has been deprecated since version 2.22 and should not be used in newly-written code. Use g_mapped_file_unref() instead.
192 	 * This call existed before GMappedFile had refcounting and is currently
193 	 * exactly the same as g_mapped_file_unref().
194 	 * Since 2.8
195 	 */
196 	public void free()
197 	{
198 		// void g_mapped_file_free (GMappedFile *file);
199 		g_mapped_file_free(gMappedFile);
200 	}
201 	
202 	/**
203 	 * Returns the length of the contents of a GMappedFile.
204 	 * Since 2.8
205 	 * Returns: the length of the contents of file.
206 	 */
207 	public gsize getLength()
208 	{
209 		// gsize g_mapped_file_get_length (GMappedFile *file);
210 		return g_mapped_file_get_length(gMappedFile);
211 	}
212 	
213 	/**
214 	 * Returns the contents of a GMappedFile.
215 	 * Note that the contents may not be zero-terminated,
216 	 * even if the GMappedFile is backed by a text file.
217 	 * If the file is empty then NULL is returned.
218 	 * Since 2.8
219 	 * Returns: the contents of file, or NULL.
220 	 */
221 	public string getContents()
222 	{
223 		// gchar * g_mapped_file_get_contents (GMappedFile *file);
224 		return Str.toString(g_mapped_file_get_contents(gMappedFile));
225 	}
226 }