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