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-Timers.html
27  * outPack = glib
28  * outFile = Timer
29  * strct   = GTimer
30  * realStrct=
31  * ctorStrct=
32  * clss    = Timer
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_timer_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- gtkc.Loader
47  * 	- gtkc.paths
48  * structWrap:
49  * 	- GTimer* -> Timer
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.Timer;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 private import gtkc.Loader;
63 private import gtkc.paths;
64 
65 
66 
67 /**
68  * GTimer records a start time, and counts microseconds elapsed since
69  * that time. This is done somewhat differently on different platforms,
70  * and can be tricky to get exactly right, so GTimer provides a
71  * portable/convenient interface.
72  */
73 public class Timer
74 {
75 	
76 	/** the main Gtk struct */
77 	protected GTimer* gTimer;
78 	
79 	
80 	/** Get the main Gtk struct */
81 	public GTimer* getTimerStruct()
82 	{
83 		return gTimer;
84 	}
85 	
86 	
87 	/** the main Gtk struct as a void* */
88 	protected void* getStruct()
89 	{
90 		return cast(void*)gTimer;
91 	}
92 	
93 	/**
94 	 * Sets our main struct and passes it to the parent class
95 	 */
96 	public this (GTimer* gTimer)
97 	{
98 		this.gTimer = gTimer;
99 	}
100 	
101 	~this ()
102 	{
103 		if ( Linker.isLoaded(LIBRARY.GLIB) && gTimer !is null )
104 		{
105 			g_timer_destroy(gTimer);
106 		}
107 	}
108 	
109 	/**
110 	 */
111 	
112 	/**
113 	 * Creates a new timer, and starts timing (i.e. g_timer_start() is
114 	 * implicitly called for you).
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this ()
118 	{
119 		// GTimer * g_timer_new (void);
120 		auto p = g_timer_new();
121 		if(p is null)
122 		{
123 			throw new ConstructionException("null returned by g_timer_new()");
124 		}
125 		this(cast(GTimer*) p);
126 	}
127 	
128 	/**
129 	 * Marks a start time, so that future calls to g_timer_elapsed() will
130 	 * report the time since g_timer_start() was called. g_timer_new()
131 	 * automatically marks the start time, so no need to call
132 	 * g_timer_start() immediately after creating the timer.
133 	 */
134 	public void start()
135 	{
136 		// void g_timer_start (GTimer *timer);
137 		g_timer_start(gTimer);
138 	}
139 	
140 	/**
141 	 * Marks an end time, so calls to g_timer_elapsed() will return the
142 	 * difference between this end time and the start time.
143 	 */
144 	public void stop()
145 	{
146 		// void g_timer_stop (GTimer *timer);
147 		g_timer_stop(gTimer);
148 	}
149 	
150 	/**
151 	 * Resumes a timer that has previously been stopped with
152 	 * g_timer_stop(). g_timer_stop() must be called before using this
153 	 * function.
154 	 * Since 2.4
155 	 */
156 	public void continu()
157 	{
158 		// void g_timer_continue (GTimer *timer);
159 		g_timer_continue(gTimer);
160 	}
161 	
162 	/**
163 	 * If timer has been started but not stopped, obtains the time since
164 	 * the timer was started. If timer has been stopped, obtains the
165 	 * elapsed time between the time it was started and the time it was
166 	 * stopped. The return value is the number of seconds elapsed,
167 	 * including any fractional part. The microseconds out parameter is
168 	 * essentially useless.
169 	 * Params:
170 	 * microseconds = return location for the fractional part of seconds
171 	 * elapsed, in microseconds (that is, the total number
172 	 * of microseconds elapsed, modulo 1000000), or NULL
173 	 * Returns: seconds elapsed as a floating point value, including any fractional part.
174 	 */
175 	public double elapsed(out gulong microseconds)
176 	{
177 		// gdouble g_timer_elapsed (GTimer *timer,  gulong *microseconds);
178 		return g_timer_elapsed(gTimer, &microseconds);
179 	}
180 	
181 	/**
182 	 * This function is useless; it's fine to call g_timer_start() on an
183 	 * already-started timer to reset the start time, so g_timer_reset()
184 	 * serves no purpose.
185 	 */
186 	public void reset()
187 	{
188 		// void g_timer_reset (GTimer *timer);
189 		g_timer_reset(gTimer);
190 	}
191 	
192 	/**
193 	 * Destroys a timer, freeing associated resources.
194 	 */
195 	public void destroy()
196 	{
197 		// void g_timer_destroy (GTimer *timer);
198 		g_timer_destroy(gTimer);
199 	}
200 }