Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74765 - in trunk: boost/timer libs/filesystem/v3/test/msvc10 libs/timer/build libs/timer/src libs/timer/test libs/timer/test/msvc10 libs/timer/test/msvc10/chrono_dll libs/timer/test/msvc10/cpu_timer_test libs/timer/test/msvc10/system_dll libs/timer/test/msvc10/timer_dll
From: bdawes_at_[hidden]
Date: 2011-10-06 16:50:49


Author: bemandawes
Date: 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
New Revision: 74765
URL: http://svn.boost.org/trac/boost/changeset/74765

Log:
Eliminate default_format from header. This eliminates initialization issues at the cost of some additional overloads. Docs to follow. Suggested by Rob. This change was made simpler by combining and reorganizing so there are now only two source files.
Removed:
   trunk/libs/timer/src/auto_timers.cpp
Text files modified:
   trunk/boost/timer/timer.hpp | 34 ++++++------
   trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln | 2
   trunk/libs/timer/build/Jamfile.v2 | 2
   trunk/libs/timer/src/auto_timers_construction.cpp | 13 ++++
   trunk/libs/timer/src/cpu_timer.cpp | 104 ++++++++++++++++++++++++++++++++++++++-
   trunk/libs/timer/test/cpu_timer_test.cpp | 2
   trunk/libs/timer/test/msvc10/chrono_dll/chrono_dll.vcxproj | 16 ++++++
   trunk/libs/timer/test/msvc10/common.props | 2
   trunk/libs/timer/test/msvc10/cpu_timer_test/cpu_timer_test.vcxproj | 1
   trunk/libs/timer/test/msvc10/system_dll/system_dll.vcxproj | 16 ++++++
   trunk/libs/timer/test/msvc10/timer_dll/timer_dll.vcxproj | 17 ++++++
   11 files changed, 181 insertions(+), 28 deletions(-)

Modified: trunk/boost/timer/timer.hpp
==============================================================================
--- trunk/boost/timer/timer.hpp (original)
+++ trunk/boost/timer/timer.hpp 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -53,29 +53,27 @@
   const short default_places = 6;
 
   BOOST_TIMER_DECL
- const std::string& default_format();
+ std::string format(const cpu_times& times, short places, const std::string& fmt);
 
   BOOST_TIMER_DECL
- std::string format(const cpu_times& times,
- short places = default_places,
- const std::string& fmt = default_format());
+ std::string format(const cpu_times& times, short places = default_places);
 
-// cpu_timer ---------------------------------------------------------------------//
+// cpu_timer -------------------------------------------------------------------------//
 
   class BOOST_TIMER_DECL cpu_timer
   {
   public:
 
- // constructors, destructor
+ // constructor
     cpu_timer() { start(); }
- ~cpu_timer() {}
 
     // observers
     bool is_stopped() const { return m_is_stopped; }
     cpu_times elapsed() const; // does not stop()
- std::string format(int places = default_places,
- const std::string& format = default_format()) const
- { return timer::format(elapsed(), places, format); }
+ std::string format(short places, const std::string& format) const
+ { return ::boost::timer::format(elapsed(), places, format); }
+ std::string format(short places = default_places) const
+ { return ::boost::timer::format(elapsed(), places); }
     // actions
     void start();
     const cpu_times& stop();
@@ -96,15 +94,15 @@
     // require including <iostream>, with its high costs, even when the standard
     // streams are not actually used.
 
- explicit auto_cpu_timer(short places = default_places,
- const std::string& format = default_format());
- explicit auto_cpu_timer(const std::string& format);
- explicit auto_cpu_timer(std::ostream& os,
- short places = default_places,
- const std::string& format = default_format())
+ explicit auto_cpu_timer(short places = default_places); // #1
+ auto_cpu_timer(short places, const std::string& format); // #2
+ explicit auto_cpu_timer(const std::string& format); // #3
+ auto_cpu_timer(std::ostream& os, short places,
+ const std::string& format) // #4
                                    : m_places(places), m_os(os), m_format(format)
                                    { start(); }
- auto_cpu_timer(std::ostream& os, const std::string& format)
+ explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
+ auto_cpu_timer(std::ostream& os, const std::string& format) // #6
                                    : m_places(default_places), m_os(os), m_format(format)
                                    { start(); }
 
@@ -113,7 +111,7 @@
     void report();
 
   private:
- int m_places;
+ short m_places;
     std::ostream& m_os;
     std::string m_format;
   };

Modified: trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln
==============================================================================
--- trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln (original)
+++ trunk/libs/filesystem/v3/test/msvc10/filesystem-v3.sln 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -132,7 +132,9 @@
                 {256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.ActiveCfg = Release|Win32
                 {256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.Build.0 = Release|Win32
                 {FC5C770F-3017-4021-8DAF-C5DCA3FDF005}.Debug|Win32.ActiveCfg = Debug|Win32
+ {FC5C770F-3017-4021-8DAF-C5DCA3FDF005}.Debug|Win32.Build.0 = Debug|Win32
                 {FC5C770F-3017-4021-8DAF-C5DCA3FDF005}.Release|Win32.ActiveCfg = Release|Win32
+ {FC5C770F-3017-4021-8DAF-C5DCA3FDF005}.Release|Win32.Build.0 = Release|Win32
                 {5C9B3380-3C6E-45CC-986A-16D245E27E58}.Debug|Win32.ActiveCfg = Debug|Win32
                 {5C9B3380-3C6E-45CC-986A-16D245E27E58}.Debug|Win32.Build.0 = Debug|Win32
                 {5C9B3380-3C6E-45CC-986A-16D245E27E58}.Release|Win32.ActiveCfg = Release|Win32

Modified: trunk/libs/timer/build/Jamfile.v2
==============================================================================
--- trunk/libs/timer/build/Jamfile.v2 (original)
+++ trunk/libs/timer/build/Jamfile.v2 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -14,7 +14,7 @@
       <link>static:<define>BOOST_TIMER_STATIC_LINK=1
     ;
 
-SOURCES = auto_timers auto_timers_construction cpu_timer ;
+SOURCES = auto_timers_construction cpu_timer ;
 
 lib boost_timer
    : $(SOURCES).cpp ../../chrono/build//boost_chrono

Deleted: trunk/libs/timer/src/auto_timers.cpp
==============================================================================
--- trunk/libs/timer/src/auto_timers.cpp 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
+++ (empty file)
@@ -1,130 +0,0 @@
-// boost auto_cpu_timer.cpp -----------------------------------------------------//
-
-// Copyright Beman Dawes 1994-2006, 2011
-
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt)
-
-//----------------------------------------------------------------------------//
-
-// define BOOST_TIMER_SOURCE so that <boost/timer/config.hpp> knows
-// the library is being built (possibly exporting rather than importing code)
-#define BOOST_TIMER_SOURCE
-
-#include <boost/timer/timer.hpp>
-#include <boost/io/ios_state.hpp>
-#include <string>
-#include <sstream>
-#include <cstring>
-
-using boost::timer::nanosecond_type;
-using boost::timer::cpu_times;
-using boost::system::error_code;
-
-# if defined(BOOST_WINDOWS_API)
-# include <windows.h>
-# elif defined(BOOST_POSIX_API)
-# include <sys/times.h>
-# else
-# error unknown API
-# endif
-
-namespace
-{
- // cpu_timer helpers ---------------------------------------------------------------//
-
- void show_time(const cpu_times& times,
- std::ostream& os, const std::string& fmt, short places)
- // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
- // be as low as 10, although will be 15 for many common platforms.
- {
- if (places > 9)
- places = 9;
- else if (places < 0)
- places = boost::timer::default_places;
-
- boost::io::ios_flags_saver ifs(os);
- boost::io::ios_precision_saver ips(os);
- os.setf(std::ios_base::fixed, std::ios_base::floatfield);
- os.precision(places);
-
- const long double sec = 1000000000.0L;
- nanosecond_type total = times.system + times.user;
- long double wall_sec = times.wall / sec;
- long double total_sec = total / sec;
-
- for (const char* format = fmt.c_str(); *format; ++format)
- {
- if (*format != '%' || !*(format+1) || !std::strchr("wustp", *(format+1)))
- os << *format; // anything except % followed by a valid format character
- // gets sent to the output stream
- else
- {
- ++format;
- switch (*format)
- {
- case 'w':
- os << times.wall / sec;
- break;
- case 'u':
- os << times.user / sec;
- break;
- case 's':
- os << times.system / sec;
- break;
- case 't':
- os << total / sec;
- break;
- case 'p':
- os.precision(1);
- if (wall_sec > 0.001L && total_sec > 0.001L)
- os << (total_sec/wall_sec) * 100.0;
- else
- os << "n/a";
- os.precision(places);
- break;
- }
- }
- }
- }
-
-} // unnamed namespace
-
-namespace boost
-{
- namespace timer
- {
- // format ------------------------------------------------------------------------//
-
- BOOST_TIMER_DECL
- std::string format(const cpu_times& times, short places, const std::string& fmt)
- {
- std::stringstream ss;
- show_time(times, ss, fmt, places);
- return ss.str();
- }
-
- // auto_cpu_timer ----------------------------------------------------------------//
-
- void auto_cpu_timer::report()
- {
- show_time(stop(), m_os, m_format, m_places);
- resume();
- }
-
- auto_cpu_timer::~auto_cpu_timer()
- {
- if (!is_stopped())
- {
- try
- {
- report();
- }
- catch (...) // eat any exceptions
- {
- }
- }
- }
-
- } // namespace timer
-} // namespace boost

Modified: trunk/libs/timer/src/auto_timers_construction.cpp
==============================================================================
--- trunk/libs/timer/src/auto_timers_construction.cpp (original)
+++ trunk/libs/timer/src/auto_timers_construction.cpp 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -23,14 +23,23 @@
 #include <boost/timer/timer.hpp>
 #include <iostream>
 
+namespace
+{
+ // CAUTION: must be identical to same constant in cpu_timer.cpp
+ const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
+}
+
 namespace boost
 {
   namespace timer
   {
- auto_cpu_timer::auto_cpu_timer(short places, const std::string& format)
+ auto_cpu_timer::auto_cpu_timer(short places) // #1
+ : m_places(places), m_os(std::cout), m_format(default_fmt) { start(); }
+
+ auto_cpu_timer::auto_cpu_timer(short places, const std::string& format) // #2
       : m_places(places), m_os(std::cout), m_format(format) { start(); }
 
- auto_cpu_timer::auto_cpu_timer(const std::string& format)
+ auto_cpu_timer::auto_cpu_timer(const std::string& format) // #3
       : m_places(default_places), m_os(std::cout), m_format(format) { start(); }
 
   } // namespace timer

Modified: trunk/libs/timer/src/cpu_timer.cpp
==============================================================================
--- trunk/libs/timer/src/cpu_timer.cpp (original)
+++ trunk/libs/timer/src/cpu_timer.cpp 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -19,6 +19,7 @@
 #include <boost/throw_exception.hpp>
 #include <boost/cerrno.hpp>
 #include <cstring>
+#include <sstream>
 #include <cassert>
 
 # if defined(BOOST_WINDOWS_API)
@@ -30,11 +31,68 @@
 # error unknown API
 # endif
 
+using boost::timer::nanosecond_type;
+using boost::timer::cpu_times;
 using boost::system::error_code;
 
 namespace
 {
 
+ void show_time(const cpu_times& times,
+ std::ostream& os, const std::string& fmt, short places)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ if (places > 9)
+ places = 9;
+ else if (places < 0)
+ places = boost::timer::default_places;
+
+ boost::io::ios_flags_saver ifs(os);
+ boost::io::ios_precision_saver ips(os);
+ os.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ os.precision(places);
+
+ const long double sec = 1000000000.0L;
+ nanosecond_type total = times.system + times.user;
+ long double wall_sec = times.wall / sec;
+ long double total_sec = total / sec;
+
+ for (const char* format = fmt.c_str(); *format; ++format)
+ {
+ if (*format != '%' || !*(format+1) || !std::strchr("wustp", *(format+1)))
+ os << *format; // anything except % followed by a valid format character
+ // gets sent to the output stream
+ else
+ {
+ ++format;
+ switch (*format)
+ {
+ case 'w':
+ os << times.wall / sec;
+ break;
+ case 'u':
+ os << times.user / sec;
+ break;
+ case 's':
+ os << times.system / sec;
+ break;
+ case 't':
+ os << total / sec;
+ break;
+ case 'p':
+ os.precision(1);
+ if (wall_sec > 0.001L && total_sec > 0.001L)
+ os << (total_sec/wall_sec) * 100.0;
+ else
+ os << "n/a";
+ os.precision(places);
+ break;
+ }
+ }
+ }
+ }
+
 # if defined(BOOST_POSIX_API)
   boost::int_least64_t tick_factor() // multiplier to convert ticks
                                      // to nanoseconds; -1 if unknown
@@ -100,18 +158,29 @@
 # endif
   }
 
+ // CAUTION: must be identical to same constant in auto_timers_construction.cpp
+ const std::string default_fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
+
 } // unnamed namespace
 
 namespace boost
 {
   namespace timer
   {
+ // format ------------------------------------------------------------------------//
 
     BOOST_TIMER_DECL
- const std::string& default_format()
+ std::string format(const cpu_times& times, short places, const std::string& fmt)
+ {
+ std::stringstream ss;
+ show_time(times, ss, fmt, places);
+ return ss.str();
+ }
+
+ BOOST_TIMER_DECL
+ std::string format(const cpu_times& times, short places)
     {
- static std::string fmt(" %ws wall, %us user + %ss system = %ts CPU (%p%)\n");
- return fmt;
+ return format(times, places, default_fmt);
     }
 
     // cpu_timer ---------------------------------------------------------------------//
@@ -159,5 +228,34 @@
         m_times.system -= current.system;
       }
     }
+
+ // auto_cpu_timer ----------------------------------------------------------------//
+
+ auto_cpu_timer::auto_cpu_timer(std::ostream& os, short places) // #5
+ : m_places(places), m_os(os), m_format(default_fmt)
+ {
+ start();
+ }
+
+ void auto_cpu_timer::report()
+ {
+ show_time(stop(), m_os, m_format, m_places);
+ resume();
+ }
+
+ auto_cpu_timer::~auto_cpu_timer()
+ {
+ if (!is_stopped())
+ {
+ try
+ {
+ report();
+ }
+ catch (...) // eat any exceptions
+ {
+ }
+ }
+ }
+
   } // namespace timer
 } // namespace boost

Modified: trunk/libs/timer/test/cpu_timer_test.cpp
==============================================================================
--- trunk/libs/timer/test/cpu_timer_test.cpp (original)
+++ trunk/libs/timer/test/cpu_timer_test.cpp 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -121,7 +121,7 @@
 
 //--------------------------------------------------------------------------------------//
 
-int cpp_main(int argc, char * argv[])
+int cpp_main(int, char *[])
 {
   cout << "---------- timer_test ----------\n";
 

Modified: trunk/libs/timer/test/msvc10/chrono_dll/chrono_dll.vcxproj
==============================================================================
--- trunk/libs/timer/test/msvc10/chrono_dll/chrono_dll.vcxproj (original)
+++ trunk/libs/timer/test/msvc10/chrono_dll/chrono_dll.vcxproj 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -57,6 +57,14 @@
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
@@ -74,6 +82,14 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\..\..\chrono\src\chrono.cpp" />

Modified: trunk/libs/timer/test/msvc10/common.props
==============================================================================
--- trunk/libs/timer/test/msvc10/common.props (original)
+++ trunk/libs/timer/test/msvc10/common.props 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -7,7 +7,7 @@
     <ClCompile>
       <AdditionalIncludeDirectories>../../../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <WarningLevel>EnableAllWarnings</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
     </ClCompile>
     <PostBuildEvent>
       <Command>"$(TargetDir)\$(TargetName).exe"</Command>

Modified: trunk/libs/timer/test/msvc10/cpu_timer_test/cpu_timer_test.vcxproj
==============================================================================
--- trunk/libs/timer/test/msvc10/cpu_timer_test/cpu_timer_test.vcxproj (original)
+++ trunk/libs/timer/test/msvc10/cpu_timer_test/cpu_timer_test.vcxproj 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -49,7 +49,6 @@
     <ClCompile>
       <PrecompiledHeader>
       </PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>

Modified: trunk/libs/timer/test/msvc10/system_dll/system_dll.vcxproj
==============================================================================
--- trunk/libs/timer/test/msvc10/system_dll/system_dll.vcxproj (original)
+++ trunk/libs/timer/test/msvc10/system_dll/system_dll.vcxproj 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -57,6 +57,14 @@
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
@@ -74,6 +82,14 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="..\..\..\..\system\src\error_code.cpp" />

Modified: trunk/libs/timer/test/msvc10/timer_dll/timer_dll.vcxproj
==============================================================================
--- trunk/libs/timer/test/msvc10/timer_dll/timer_dll.vcxproj (original)
+++ trunk/libs/timer/test/msvc10/timer_dll/timer_dll.vcxproj 2011-10-06 16:50:47 EDT (Thu, 06 Oct 2011)
@@ -57,6 +57,14 @@
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
@@ -74,9 +82,16 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
+ <PostBuildEvent>
+ <Command>
+ </Command>
+ </PostBuildEvent>
+ <PostBuildEvent>
+ <Message>
+ </Message>
+ </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
- <ClCompile Include="..\..\..\src\auto_timers.cpp" />
     <ClCompile Include="..\..\..\src\auto_timers_construction.cpp" />
     <ClCompile Include="..\..\..\src\cpu_timer.cpp" />
   </ItemGroup>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk