From 29121937c3a568ef8113b8d3f2cc7f7e06781c71 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 17 Nov 2012 17:47:35 -0500 Subject: [PATCH] Turned timeout into a single implementation style object. Therefore, now it can be declared as a type timeout rather than timeout::kernel_1a. --HG-- rename : dlib/timeout/timeout_kernel_1.h => dlib/timeout/timeout.h rename : dlib/timeout/timeout_kernel_abstract.h => dlib/timeout/timeout_abstract.h --- dlib/timeout.h | 21 +------------ .../timeout/{timeout_kernel_1.h => timeout.h} | 31 ++++++++++--------- ...t_kernel_abstract.h => timeout_abstract.h} | 2 +- 3 files changed, 19 insertions(+), 35 deletions(-) rename dlib/timeout/{timeout_kernel_1.h => timeout.h} (85%) rename dlib/timeout/{timeout_kernel_abstract.h => timeout_abstract.h} (98%) diff --git a/dlib/timeout.h b/dlib/timeout.h index c8ee03137..2c3590e46 100644 --- a/dlib/timeout.h +++ b/dlib/timeout.h @@ -3,26 +3,7 @@ #ifndef DLIB_TIMEOUt_ #define DLIB_TIMEOUt_ -#include "timeout/timeout_kernel_1.h" - -namespace dlib -{ - - class timeout - { - timeout() {} - - - public: - - //----------- kernels --------------- - - // kernel_1a - typedef timeout_kernel_1 - kernel_1a; - - }; -} +#include "timeout/timeout.h" #endif // DLIB_TIMEOUt_ diff --git a/dlib/timeout/timeout_kernel_1.h b/dlib/timeout/timeout.h similarity index 85% rename from dlib/timeout/timeout_kernel_1.h rename to dlib/timeout/timeout.h index 735a6cb99..e6c586870 100644 --- a/dlib/timeout/timeout_kernel_1.h +++ b/dlib/timeout/timeout.h @@ -6,7 +6,7 @@ #include "../threads.h" #include "../algs.h" #include "../misc_api.h" -#include "timeout_kernel_abstract.h" +#include "timeout_abstract.h" #include "../uintn.h" #include "../timer.h" @@ -23,7 +23,7 @@ namespace dlib // ---------------------------------------------------------------------------------------- - class timeout_kernel_1 + class timeout { /*! INITIAL VALUE @@ -62,15 +62,18 @@ namespace dlib public: + // This typedef is here for backwards compatibility with previous versions of dlib. + typedef timeout kernel_1a; + template < typename T > - timeout_kernel_1 ( + timeout ( T& object, void (T::*callback_function)(), unsigned long ms_to_timeout ): - t(*this,&timeout_kernel_1::trigger_timeout) + t(*this,&timeout::trigger_timeout) { zero* B = new zero; b = B; @@ -84,13 +87,13 @@ namespace dlib typename T, typename U > - timeout_kernel_1 ( + timeout ( T& object, void (T::*callback_function)(U callback_function_argument), unsigned long ms_to_timeout, U callback_function_argument ): - t(*this,&timeout_kernel_1::trigger_timeout) + t(*this,&timeout::trigger_timeout) { one* B = new one; b = B; @@ -104,12 +107,12 @@ namespace dlib template < typename T > - timeout_kernel_1 ( + timeout ( T& object, int (T::*callback_function)(), unsigned long ms_to_timeout ): - t(*this,&timeout_kernel_1::trigger_timeout) + t(*this,&timeout::trigger_timeout) { zero* B = new zero; b = B; @@ -123,13 +126,13 @@ namespace dlib typename T, typename U > - timeout_kernel_1 ( + timeout ( T& object, int (T::*callback_function)(U callback_function_argument), unsigned long ms_to_timeout, U callback_function_argument ): - t(*this,&timeout_kernel_1::trigger_timeout) + t(*this,&timeout::trigger_timeout) { one* B = new one; b = B; @@ -140,7 +143,7 @@ namespace dlib t.start(); } - virtual ~timeout_kernel_1 ( + virtual ~timeout ( ) { t.stop_and_wait(); @@ -155,12 +158,12 @@ namespace dlib t.stop(); } - dlib::timer::kernel_2a t; + dlib::timer::kernel_2a t; bind* b; // restricted functions - timeout_kernel_1(const timeout_kernel_1&); // copy constructor - timeout_kernel_1& operator=(const timeout_kernel_1&); // assignment operator + timeout(const timeout&); // copy constructor + timeout& operator=(const timeout&); // assignment operator }; diff --git a/dlib/timeout/timeout_kernel_abstract.h b/dlib/timeout/timeout_abstract.h similarity index 98% rename from dlib/timeout/timeout_kernel_abstract.h rename to dlib/timeout/timeout_abstract.h index 0c07d49f9..b66796894 100644 --- a/dlib/timeout/timeout_kernel_abstract.h +++ b/dlib/timeout/timeout_abstract.h @@ -20,7 +20,7 @@ namespace dlib connection* con = a connection from somewhere; { // setup a timer that will call con->shutdown() in 10 seconds - timeout::kernel_1a t(*con,&connection::shutdown,10000); + timeout t(*con,&connection::shutdown,10000); // Now call read on the connection. If this call to read() takes // more than 10 seconds then the t timeout will trigger and shutdown // the connection. If read completes in less than 10 seconds then