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 module glib.Timer;
26 
27 private import glib.ConstructionException;
28 private import gtkc.glib;
29 public  import gtkc.glibtypes;
30 
31 
32 /**
33  * Opaque datatype that records a start time.
34  */
35 public class Timer
36 {
37 	/** the main Gtk struct */
38 	protected GTimer* gTimer;
39 	protected bool ownedRef;
40 
41 	/** Get the main Gtk struct */
42 	public GTimer* getTimerStruct()
43 	{
44 		return gTimer;
45 	}
46 
47 	/** the main Gtk struct as a void* */
48 	protected void* getStruct()
49 	{
50 		return cast(void*)gTimer;
51 	}
52 
53 	/**
54 	 * Sets our main struct and passes it to the parent class.
55 	 */
56 	public this (GTimer* gTimer, bool ownedRef = false)
57 	{
58 		this.gTimer = gTimer;
59 		this.ownedRef = ownedRef;
60 	}
61 
62 
63 	/**
64 	 * Resumes a timer that has previously been stopped with
65 	 * g_timer_stop(). g_timer_stop() must be called before using this
66 	 * function.
67 	 *
68 	 * Since: 2.4
69 	 */
70 	public void continu()
71 	{
72 		g_timer_continue(gTimer);
73 	}
74 
75 	/**
76 	 * Destroys a timer, freeing associated resources.
77 	 */
78 	public void destroy()
79 	{
80 		g_timer_destroy(gTimer);
81 	}
82 
83 	/**
84 	 * If @timer has been started but not stopped, obtains the time since
85 	 * the timer was started. If @timer has been stopped, obtains the
86 	 * elapsed time between the time it was started and the time it was
87 	 * stopped. The return value is the number of seconds elapsed,
88 	 * including any fractional part. The @microseconds out parameter is
89 	 * essentially useless.
90 	 *
91 	 * Params:
92 	 *     microseconds = return location for the fractional part of seconds
93 	 *         elapsed, in microseconds (that is, the total number
94 	 *         of microseconds elapsed, modulo 1000000), or %NULL
95 	 *
96 	 * Return: seconds elapsed as a floating point value, including any
97 	 *     fractional part.
98 	 */
99 	public double elapsed(gulong* microseconds)
100 	{
101 		return g_timer_elapsed(gTimer, microseconds);
102 	}
103 
104 	/**
105 	 * This function is useless; it's fine to call g_timer_start() on an
106 	 * already-started timer to reset the start time, so g_timer_reset()
107 	 * serves no purpose.
108 	 */
109 	public void reset()
110 	{
111 		g_timer_reset(gTimer);
112 	}
113 
114 	/**
115 	 * Marks a start time, so that future calls to g_timer_elapsed() will
116 	 * report the time since g_timer_start() was called. g_timer_new()
117 	 * automatically marks the start time, so no need to call
118 	 * g_timer_start() immediately after creating the timer.
119 	 */
120 	public void start()
121 	{
122 		g_timer_start(gTimer);
123 	}
124 
125 	/**
126 	 * Marks an end time, so calls to g_timer_elapsed() will return the
127 	 * difference between this end time and the start time.
128 	 */
129 	public void stop()
130 	{
131 		g_timer_stop(gTimer);
132 	}
133 
134 	/**
135 	 * Creates a new timer, and starts timing (i.e. g_timer_start() is
136 	 * implicitly called for you).
137 	 *
138 	 * Return: a new #GTimer.
139 	 *
140 	 * Throws: ConstructionException GTK+ fails to create the object.
141 	 */
142 	public this()
143 	{
144 		auto p = g_timer_new();
145 		
146 		if(p is null)
147 		{
148 			throw new ConstructionException("null returned by new");
149 		}
150 		
151 		this(cast(GTimer*) p);
152 	}
153 }