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