#define _MOOF_TIMER_HH_
/**
- * @file Timer.hh
+ * \file timer.hh
* Functions for measuring time in a friendly unit.
*/
#include <boost/bind.hpp>
#include <boost/function.hpp>
-#include <Moof/Math.hh>
+#include <moof/math.hh>
-namespace Mf {
+namespace moof {
-class Timer
+class timer
{
public:
- enum Mode
+ enum mode
{
- INVALID = -1,
- NORMAL = 0,
- ACTUAL = 1,
- REPEAT = 2
+ invalid = -1,
+ normal = 0,
+ absolute = 1,
+ repeat = 2
};
- typedef boost::function<void(Timer&,Scalar)> Function;
+ typedef boost::function<void(timer&,scalar)> function;
- Timer() :
- mMode(INVALID) {}
+ timer() :
+ mode_(invalid) {}
- Timer(const Function& function, Scalar seconds, Mode mode = NORMAL)
+ timer(const function& function, scalar seconds, mode mode = normal)
{
init(function, seconds, mode);
}
- ~Timer()
+ ~timer()
{
invalidate();
}
- void init(const Function& function, Scalar seconds,
- Mode mode = NORMAL);
+ void init(const function& function, scalar seconds, mode mode = normal);
- bool isValid() const;
+ bool is_valid() const;
void invalidate();
void fire();
- Scalar getSecondsRemaining() const;
- bool isExpired() const;
- bool isRepeating() const;
+ scalar seconds_remaining() const;
+ bool is_expired() const;
+ bool is_repeating() const;
/**
* Get the number of seconds since a fixed, arbitrary point in the
* past.
- * @return Seconds.
+ * \return Seconds.
*/
-
- static Scalar getTicks();
+ static scalar ticks();
/**
* sleep if sleep was interrupted by a signal. Therefore, calling this
* function is guaranteed to sleep for the requested amount of time
* (and maybe longer).
+ * \param seconds Number of seconds.
+ * \param mode The timer mode.
*/
-
- static void sleep(Scalar seconds, Mode mode = NORMAL);
+ static void sleep(scalar seconds, mode mode = normal);
- static Scalar getNextFire()
+ static scalar next_expiration()
{
return gNextFire;
}
- static void fireIfExpired();
- static void fireIfExpired(Scalar t);
+ static void fire_expired_timers();
+ static void fire_expired_timers(scalar t);
+
private:
- static unsigned getNewID();
- static Scalar findNextFire();
+ static unsigned new_identifier();
+ static scalar find_next_expiration();
- Function mFunction;
- Mode mMode;
- Scalar mAbsolute;
- Scalar mInterval;
- unsigned mId;
+ function function_;
+ mode mode_;
+ scalar absolute_;
+ scalar interval_;
+ unsigned id_;
- static Scalar gNextFire;
- static std::map<unsigned,Timer*> gTimers;
+ static scalar gNextFire;
+ static std::map<unsigned,timer*> gTimers;
};
-} // namespace Mf
+} // namespace moof
#endif // _MOOF_TIMER_HH_