Update of /cvsroot/boost/boost/boost
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25293
Modified Files:
timer.hpp
Log Message:
Introduced exception class for std::clock() failures; minor: added trailing
slash to doc url, reordered #includes
Index: timer.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/timer.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- timer.hpp 25 Jul 2004 12:00:07 -0000 1.7
+++ timer.hpp 7 Jun 2006 18:17:17 -0000 1.8
@@ -4,9 +4,10 @@
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-// See http://www.boost.org/libs/timer for documentation.
+// See http://www.boost.org/libs/timer/ for documentation.
// Revision History
+// 07 Jun 06 Introduced exception class for std::clock() failures (G. Prota)
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
// 12 Jan 01 Change to inline implementation to allow use without library
// builds. See docs for more rationale. (Beman Dawes)
@@ -17,8 +18,9 @@
#ifndef BOOST_TIMER_HPP
#define BOOST_TIMER_HPP
-#include <boost/config.hpp>
#include <ctime>
+#include <exception>
+#include <boost/config.hpp>
#include <boost/limits.hpp>
# ifdef BOOST_NO_STDC_NAMESPACE
@@ -44,11 +46,32 @@
class timer
{
public:
- timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
+
+ // exception class to report construction or restart failure
+ //
+ class availability_error : public std::exception
+ {
+ public:
+ availability_error() throw() {}
+ availability_error(const availability_error&) throw() {}
+ availability_error& operator=(const availability_error&) throw() {
return *this; }
+ virtual const char* what() const throw()
+ { return static_cast<const char*>("boost:timer cannot start"); }
+ virtual ~availability_error() throw() {}
+ };
+
+
+ timer() { restart(); } // postcondition: elapsed()==0
+
// timer( const timer& src ); // post: elapsed()==src.elapsed()
// ~timer(){}
// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
- void restart() { _start_time = std::clock(); } // post: elapsed()==0
+
+ void restart() // post: elapsed()==0
+ {
+ if ((_start_time = std::clock()) == ((std::clock_t) -1))
+ throw availability_error();
+ }
double elapsed() const // return elapsed time in seconds
{ return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
@@ -57,7 +80,7 @@
// where std::clock_t overflows or resets at surprising values.
{
return (double((std::numeric_limits<std::clock_t>::max)())
- - double(_start_time)) / double(CLOCKS_PER_SEC);
+ - double(_start_time)) / double(CLOCKS_PER_SEC);
}
double elapsed_min() const // return minimum value for elapsed()
@@ -65,6 +88,7 @@
private:
std::clock_t _start_time;
+
}; // timer
} // namespace boost
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs