1 #ifndef _GLIBMM_TIMER_H 2 #define _GLIBMM_TIMER_H 3 4 /* timer.h 5 * 6 * Copyright (C) 2002 The gtkmm Development Team 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #include <glibmmconfig.h> 23 24 extern "C" { 25 using GTimer = struct _GTimer; 26 } 27 28 namespace Glib 29 { 30 31 /** Portable stop watch interface. 32 * This resembles a convient and portable timer with microseconds resolution. 33 */ 34 class GLIBMM_API Timer 35 { 36 public: 37 /** Create a new timer. 38 * Also starts timing by calling start() implicitly. 39 */ 40 Timer(); 41 ~Timer() noexcept; 42 43 // not copyable 44 Timer(const Timer&) = delete; 45 Timer& operator=(const Timer&) = delete; 46 47 void start(); 48 void stop(); 49 void reset(); 50 51 /** Get the elapsed time. 52 * @return The value in seconds. 53 */ 54 double elapsed() const; 55 56 /** Get the elapsed time. 57 * @return The value in seconds. Also fills @p microseconds 58 * with the corresponding @htmlonlyµs@endhtmlonly value. 59 */ 60 double elapsed(unsigned long& microseconds) const; 61 62 #ifndef DOXYGEN_SHOULD_SKIP_THIS gobj()63 GTimer* gobj() { return gobject_; } gobj()64 const GTimer* gobj() const { return gobject_; } 65 #endif 66 67 private: 68 GTimer* gobject_; 69 }; 70 71 GLIBMM_API 72 void usleep(unsigned long microseconds); 73 74 } // namespace Glib 75 76 #endif /* _GLIBMM_TIMER_H */ 77