guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gtimer.hpp
1 //
2 // Timers
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_Timer_hpp
9 #define Guit_Timer_hpp
10 #include <gint.hpp>
11 namespace guit {
12 
58 class GTimer : public GInt {
59 public:
60  enum {Infinite = -1, OneShot = -2};
61 
62  GTimer(GTime delay = 0, int repetitions = Infinite);
63  GTimer(GString const& format);
64  ~GTimer();
65 
69  void start(bool yes = true);
70  void stop() {start(false);}
72 
74  void restart();
75 
77  GTimer& operator=(int value) {set(value); return *this;}
78  GTimer& operator=(GInt const& value) {set(value); return *this;}
79  GTimer& operator=(GString const& value) {set(value); return *this;}
80 
82  GTimer& operator<<(GCond& c) {add(c); return *this;}
83 
86 
91  GInt& addBeat(int timer_count, int max_value);
92  GInt& addBeat(GInt& beat, int timer_count, int max_value);
94 
95  bool isRunning() const {return running_;}
96 
97  GTime delay() const {return duration_;}
98  GTimer& setDelay(GTime);
99 
102  int repetitions() const {return count_;}
103  GTimer& setRepetitions(int);
104 
105  int waitingCalls() const {return waitingcalls_;}
106 
107  using GType = GPropType_<GTimer,GInt>;
108  static GType& Type();
109  GType& type() const override {return Type();}
110 
114  virtual void timerCB();
115  bool running_{};
116  int count_{}, waitingcalls_{};
117  GTime duration_{}, nexttime_{};
118  class GNatTimer* nattimer_{};
119  gprotect<GTimer> self_;
120  // @}
121 };
122 
125 GTimer& Timer();
126 GTimer& Timer(GTime delay = 0, int repetitions = GTimer::Infinite);
127 GTimer& Timer(GString const& value);
129 
130 }
131 #endif