]> Dogcows Code - chaz/openbox/blobdiff - otk/timer.hh
prevent people from using timers except as pointers
[chaz/openbox] / otk / timer.hh
index 1d93f9145c5178f50655ba680d013b147e94e709..7e40aed73fb83947277ebc2a8cb9c931266bbc61 100644 (file)
@@ -7,21 +7,7 @@
 */
 
 extern "C" {
-#ifdef    TIME_WITH_SYS_TIME
-#  include <sys/time.h>
-#  include <time.h>
-#else // !TIME_WITH_SYS_TIME
-#  ifdef    HAVE_SYS_TIME_H
-#    include <sys/time.h>
-#  else // !HAVE_SYS_TIME_H
-#    include <time.h>
-#  endif // HAVE_SYS_TIME_H
-#endif // TIME_WITH_SYS_TIME
-
-#ifdef    HAVE_UNISTD_H
-#  include <sys/types.h>
-#  include <unistd.h>
-#endif // HAVE_UNISTD_H
+#include <ctime>
 }
 
 #include <queue>
@@ -44,9 +30,12 @@ private:
   struct TimerCompare {
      //! Compares two timeval structs
      inline bool operator()(const Timer *a, const Timer *b) const {
-       return timercmp(&a->_timeout, &b->_timeout, >);
+       return ((&a->_timeout)->tv_sec == (&b->_timeout)->tv_sec) ?
+         ((&a->_timeout)->tv_usec > (&b->_timeout)->tv_usec) :
+         ((&a->_timeout)->tv_sec > (&b->_timeout)->tv_sec);
      }
   };
+  friend struct TimerCompare; // give access to _timeout for shitty compilers
 
   typedef
   std::priority_queue<Timer*, std::vector<Timer*>, TimerCompare> TimerQ;
@@ -84,6 +73,9 @@ private:
   */
   static void timevalAdd(timeval &a, long msec);
 
+  // prevent people from using timers except as pointers
+  ~Timer() {}
+  
 public:
   //! Constructs a new running timer and queues it
   /*!
This page took 0.026026 seconds and 4 git commands to generate.