Glib/Timers のラッパー

てことで,書いた.(ちょうてきとう
これで少し楽になった.はっは.

#include <iostream>

#include <glib.h>
#include <unistd.h>

using namespace std;

class GTimerP
{
private:
  GTimer *Timer;
  gulong microseconds;
  gdouble time;
public:
  GTimerP() { Timer = g_timer_new(); }
  ~GTimerP() { g_timer_destroy(Timer); }
  void start() { g_timer_start(Timer); }
  void reset() { start(); }
  void stop() { g_timer_stop(Timer); }
  gdouble elapsed() {
    time = g_timer_elapsed(Timer, &microseconds);
    return time;
  }
  void cont() { g_timer_continue(Timer); }
};

int main(int argc, char *argv[])
{
  cout << "start:" << endl;
  GTimerP Timer;

  cout << "sleeping 3 sec." << endl; sleep(3);

  cout << Timer.elapsed() << endl;

  Timer.stop();

  cout << "sleeping 3 sec." << endl; sleep(3);

  cout << Timer.elapsed() << endl;

  Timer.cont();

  cout << "sleeping 3 sec." << endl; sleep(3);

  cout << Timer.elapsed() << endl;

  cout << "end:" << endl;
  return 0;
}

結果は同じ

start:
sleeping 3 sec.
3.00018
sleeping 3 sec.
3.00045
sleeping 3 sec.
6.00067
end: