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