Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74381 - in sandbox/stopwatches/boost/chrono: . stopwatches/formatters
From: vicente.botet_at_[hidden]
Date: 2011-09-14 19:35:55


Author: viboes
Date: 2011-09-14 19:35:54 EDT (Wed, 14 Sep 2011)
New Revision: 74381
URL: http://svn.boost.org/trac/boost/changeset/74381

Log:
Stopwatches: Move duration_style.hpp tp chrono and extract base_formatter.hpp file
Added:
   sandbox/stopwatches/boost/chrono/duration_style.hpp (contents, props changed)
Removed:
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/duration_style.hpp
Text files modified:
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp | 46 +--------------------------------------
   sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp | 2
   2 files changed, 3 insertions(+), 45 deletions(-)

Added: sandbox/stopwatches/boost/chrono/duration_style.hpp
==============================================================================
--- (empty file)
+++ sandbox/stopwatches/boost/chrono/duration_style.hpp 2011-09-14 19:35:54 EDT (Wed, 14 Sep 2011)
@@ -0,0 +1,110 @@
+// boost/chrono/stopwatches/stopwatch_formatter.hpp ------------------------------------------------------------//
+// Copyright 2011 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org/libs/chrono/stopwatches for documentation.
+
+#ifndef BOOST_STOPWATCHES_FORMATTERS_DURATION_STYLE_HPP
+#define BOOST_STOPWATCHES_FORMATTERS_DURATION_STYLE_HPP
+
+#include <boost/chrono/chrono_io.hpp>
+#include <boost/chrono/config.hpp>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ struct duration_style
+ {
+ enum type {
+ prefix_text, symbol
+ };
+ };
+
+
+ class duration_fmt
+ {
+ duration_style::type style_;
+ public:
+ explicit duration_fmt(duration_style::type style) BOOST_CHRONO_NOEXCEPT
+ : style_(style)
+ {}
+
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+ explicit
+ operator duration_style::type() const BOOST_CHRONO_NOEXCEPT
+ { return style_;}
+#endif
+
+ duration_style::type get_duration_style() const BOOST_CHRONO_NOEXCEPT
+ { return style_;}
+ };
+
+ template<class charT, class traits>
+ std::basic_ostream<charT, traits>&
+ operator <<(std::basic_ostream<charT, traits>& os, duration_fmt d)
+ {
+ if (d.get_duration_style() == duration_style::symbol)
+ os << duration_short;
+ else if (d.get_duration_style() == duration_style::prefix_text)
+ os << duration_long;
+ return os;
+ }
+
+ template<class charT, class traits>
+ std::basic_istream<charT, traits>&
+ operator >>(std::basic_istream<charT, traits>& is, duration_fmt d)
+ {
+ if (d.get_duration_style() == duration_style::symbol)
+ is >> duration_short;
+ else if (d.get_duration_style() == duration_style::prefix_text)
+ is >> duration_long;
+ return is;
+ }
+
+ template<typename CharT = char, typename Traits = std::char_traits<CharT> >
+ struct duration_style_io_saver
+ {
+
+ typedef std::basic_ios<CharT, Traits> state_type;
+ typedef duration_style::type aspect_type;
+
+ explicit duration_style_io_saver(state_type &s) :
+ s_save_(s)
+ {
+ typedef duration_punct<CharT> Facet;
+ std::locale loc = s_save_.getloc();
+ if (!std::has_facet<Facet>(loc))
+ s_save_.imbue(std::locale(loc, new Facet()));
+
+ const Facet& f = std::use_facet<Facet>(loc);
+ if (f.is_long_name())
+ a_save_ = duration_style::prefix_text;
+ else
+ a_save_ = duration_style::symbol;
+ }
+
+ duration_style_io_saver(state_type &s, aspect_type new_value) :
+ s_save_(s), a_save_(new_value)
+ {
+ }
+
+ ~duration_style_io_saver()
+ {
+ this->restore();
+ }
+
+ void restore()
+ {
+ s_save_ << duration_fmt(a_save_);
+ }
+ private:
+ state_type& s_save_;
+ aspect_type a_save_;
+ };
+ } // namespace chrono
+} // namespace boost
+
+
+#endif

Deleted: sandbox/stopwatches/boost/chrono/stopwatches/formatters/duration_style.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/formatters/duration_style.hpp 2011-09-14 19:35:54 EDT (Wed, 14 Sep 2011)
+++ (empty file)
@@ -1,110 +0,0 @@
-// boost/chrono/stopwatches/stopwatch_formatter.hpp ------------------------------------------------------------//
-// Copyright 2011 Vicente J. Botet Escriba
-// Distributed under the Boost Software License, Version 1.0.
-// See http://www.boost.org/LICENSE_1_0.txt
-// See http://www.boost.org/libs/chrono/stopwatches for documentation.
-
-#ifndef BOOST_STOPWATCHES_FORMATTERS_DURATION_STYLE_HPP
-#define BOOST_STOPWATCHES_FORMATTERS_DURATION_STYLE_HPP
-
-#include <boost/chrono/chrono_io.hpp>
-#include <boost/chrono/config.hpp>
-
-namespace boost
-{
- namespace chrono
- {
-
- struct duration_style
- {
- enum type {
- prefix_text, symbol
- };
- };
-
-
- class duration_fmt
- {
- duration_style::type style_;
- public:
- explicit duration_fmt(duration_style::type style) BOOST_CHRONO_NOEXCEPT
- : style_(style)
- {}
-
-#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
- explicit
- operator duration_style::type() const BOOST_CHRONO_NOEXCEPT
- { return style_;}
-#endif
-
- duration_style::type get_duration_style() const BOOST_CHRONO_NOEXCEPT
- { return style_;}
- };
-
- template<class charT, class traits>
- std::basic_ostream<charT, traits>&
- operator <<(std::basic_ostream<charT, traits>& os, duration_fmt d)
- {
- if (d.get_duration_style() == duration_style::symbol)
- os << duration_short;
- else if (d.get_duration_style() == duration_style::prefix_text)
- os << duration_long;
- return os;
- }
-
- template<class charT, class traits>
- std::basic_istream<charT, traits>&
- operator >>(std::basic_istream<charT, traits>& is, duration_fmt d)
- {
- if (d.get_duration_style() == duration_style::symbol)
- is >> duration_short;
- else if (d.get_duration_style() == duration_style::prefix_text)
- is >> duration_long;
- return is;
- }
-
- template<typename CharT = char, typename Traits = std::char_traits<CharT> >
- struct duration_style_io_saver
- {
-
- typedef std::basic_ios<CharT, Traits> state_type;
- typedef duration_style::type aspect_type;
-
- explicit duration_style_io_saver(state_type &s) :
- s_save_(s)
- {
- typedef duration_punct<CharT> Facet;
- std::locale loc = s_save_.getloc();
- if (!std::has_facet<Facet>(loc))
- s_save_.imbue(std::locale(loc, new Facet()));
-
- const Facet& f = std::use_facet<Facet>(loc);
- if (f.is_long_name())
- a_save_ = duration_style::prefix_text;
- else
- a_save_ = duration_style::symbol;
- }
-
- duration_style_io_saver(state_type &s, aspect_type new_value) :
- s_save_(s), a_save_(new_value)
- {
- }
-
- ~duration_style_io_saver()
- {
- this->restore();
- }
-
- void restore()
- {
- s_save_ << duration_fmt(a_save_);
- }
- private:
- state_type& s_save_;
- aspect_type a_save_;
- };
- } // namespace chrono
-} // namespace boost
-
-
-#endif

Modified: sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/formatters/elapsed_formatter.hpp 2011-09-14 19:35:54 EDT (Wed, 14 Sep 2011)
@@ -7,12 +7,10 @@
 #ifndef BOOST_STOPWATCHES_FORMATTERS_ELAPSED_HPP
 #define BOOST_STOPWATCHES_FORMATTERS_ELAPSED_HPP
 
-#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/stopwatches/formatters/base_formatter.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/stopwatches/detail/adaptive_string.hpp>
-#include <boost/chrono/stopwatches/formatters/duration_style.hpp>
-#include <boost/chrono/chrono_io.hpp>
 #include <boost/format.hpp>
 #include <boost/format/group.hpp>
 #include <boost/cstdint.hpp>
@@ -21,6 +19,7 @@
 #include <iostream>
 #include <cassert>
 #include <iomanip>
+
 #define BOOST_CHRONO_STOPWATCHES_ELAPSED_FORMAT_DEFAULT "%1%"
 
 namespace boost
@@ -28,48 +27,7 @@
   namespace chrono
   {
 
- template<typename CharT = char, typename Traits = std::char_traits<CharT> >
- class base_formatter
- {
-
- public:
- typedef basic_format<CharT, Traits> format_type;
- typedef CharT char_type;
- typedef std::basic_ostream<CharT, Traits> ostream_type;
-
- base_formatter() :
- precision_(3), os_(std::cout),
- style_(duration_style::symbol)
- {
- }
- base_formatter(ostream_type& os) :
- precision_(3), os_(os),
- style_(duration_style::symbol)
- {
- }
-
- void set_precision(std::size_t precision)
- {
- precision_=precision;
- if (precision_ > 9)
- precision_ = 9; // sanity check
- }
- void set_os(ostream_type& os)
- {
- os_=os;
- }
- void set_duration_style(duration_style::type style)
- {
- style_==style;
- }
-
- protected:
- std::size_t precision_;
- ostream_type & os_;
- duration_style::type style_;
 
-
- };
     template<typename Ratio=micro, typename CharT = char, typename Traits = std::char_traits<CharT>,
         class Alloc = std::allocator<CharT> >
     class basic_elapsed_formatter : public base_formatter<CharT, Traits>

Modified: sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp
==============================================================================
--- sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp (original)
+++ sandbox/stopwatches/boost/chrono/stopwatches/formatters/oneshot_formatter.hpp 2011-09-14 19:35:54 EDT (Wed, 14 Sep 2011)
@@ -18,7 +18,7 @@
 #include <cstring>
 #include <cassert>
 #include <boost/assert.hpp>
-#include <boost/chrono/stopwatches/formatters/duration_style.hpp>
+#include <boost/chrono/duration_style.hpp>
 #include <boost/chrono/chrono_io.hpp>
 
 #define BOOST_CHRONO_STOPWATCHES_ONESHOOT_FORMAT_DEFAULT "%d\n"


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