diff options
Diffstat (limited to 'boost/chrono')
-rw-r--r-- | boost/chrono/duration.hpp | 13 | ||||
-rw-r--r-- | boost/chrono/io/duration_get.hpp | 8 | ||||
-rw-r--r-- | boost/chrono/io/duration_io.hpp | 80 | ||||
-rw-r--r-- | boost/chrono/io/duration_put.hpp | 42 | ||||
-rw-r--r-- | boost/chrono/io/time_point_io.hpp | 14 | ||||
-rw-r--r-- | boost/chrono/io_v1/chrono_io.hpp | 8 |
6 files changed, 132 insertions, 33 deletions
diff --git a/boost/chrono/duration.hpp b/boost/chrono/duration.hpp index 814adb0e91..a2110bf411 100644 --- a/boost/chrono/duration.hpp +++ b/boost/chrono/duration.hpp @@ -433,8 +433,12 @@ namespace chrono { rep rep_; public: +#if defined BOOST_NO_CXX11_DEFAULTED_FUNCTIONS BOOST_FORCEINLINE BOOST_CONSTEXPR duration() : rep_(duration_values<rep>::zero()) { } +#else + BOOST_CONSTEXPR duration() BOOST_NOEXCEPT {}; +#endif template <class Rep2> BOOST_SYMBOL_VISIBLE BOOST_FORCEINLINE BOOST_CONSTEXPR explicit duration(const Rep2& r @@ -451,14 +455,15 @@ namespace chrono { > >::type* = 0 ) : rep_(r) { } - //~duration() {} //= default; -// BOOST_CONSTEXPR duration(const duration& rhs) : rep_(rhs.rep_) {} // = default; - duration& operator=(const duration& rhs) // = default; +#if defined BOOST_NO_CXX11_DEFAULTED_FUNCTIONS + duration& operator=(const duration& rhs) { if (&rhs != this) rep_= rhs.rep_; return *this; } - +#else + duration& operator=(const duration& rhs) = default; +#endif // conversions template <class Rep2, class Period2> BOOST_FORCEINLINE BOOST_CONSTEXPR diff --git a/boost/chrono/io/duration_get.hpp b/boost/chrono/io/duration_get.hpp index ce3075b7b3..5a0a875037 100644 --- a/boost/chrono/io/duration_get.hpp +++ b/boost/chrono/io/duration_get.hpp @@ -14,7 +14,7 @@ #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_signed.hpp> #include <boost/mpl/if.hpp> -#include <boost/math/common_factor_rt.hpp> +#include <boost/integer/common_factor_rt.hpp> #include <boost/chrono/detail/scan_keyword.hpp> #include <boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp> #include <boost/chrono/process_cpu_clocks.hpp> @@ -58,7 +58,7 @@ namespace boost typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t; // Reduce r * num / den - common_type_t t = math::gcd<common_type_t>(common_type_t(r), common_type_t(den)); + common_type_t t = integer::gcd<common_type_t>(common_type_t(r), common_type_t(den)); r /= t; den /= t; if (den != 1) @@ -278,8 +278,8 @@ namespace boost // r should be multiplied by (num/den) / Period // Reduce (num/den) / Period to lowest terms - unsigned long long gcd_n1_n2 = math::gcd<unsigned long long>(num, Period::num); - unsigned long long gcd_d1_d2 = math::gcd<unsigned long long>(den, Period::den); + unsigned long long gcd_n1_n2 = integer::gcd<unsigned long long>(num, Period::num); + unsigned long long gcd_d1_d2 = integer::gcd<unsigned long long>(den, Period::den); num /= gcd_n1_n2; den /= gcd_d1_d2; unsigned long long n2 = Period::num / gcd_n1_n2; diff --git a/boost/chrono/io/duration_io.hpp b/boost/chrono/io/duration_io.hpp index 438f7696db..34004484f3 100644 --- a/boost/chrono/io/duration_io.hpp +++ b/boost/chrono/io/duration_io.hpp @@ -18,8 +18,11 @@ #include <boost/chrono/io/duration_get.hpp> #include <boost/chrono/io/utility/manip_base.hpp> #include <boost/detail/no_exceptions_support.hpp> +#include <boost/type_traits/is_integral.hpp> +#include <boost/type_traits/is_floating_point.hpp> #include <locale> #include <iostream> +#include <sstream> namespace boost { @@ -71,19 +74,19 @@ namespace boost * Store a reference to the i/o stream and the value of the associated @c duration_style. */ explicit duration_style_io_saver(state_type &s) : - s_save_(s) + s_save_(s), a_save_(get_duration_style(s)) { - a_save_ = get_duration_style(s_save_); } /** * Construction from an i/o stream and a @c duration_style to restore. * - * Stores a reference to the i/o stream and the value @c duration_style to restore given as parameter. + * Stores a reference to the i/o stream and the value @c new_value @c duration_style to set. */ duration_style_io_saver(state_type &s, aspect_type new_value) : - s_save_(s), a_save_(new_value) + s_save_(s), a_save_(get_duration_style(s)) { + set_duration_style(s, new_value); } /** @@ -111,14 +114,81 @@ namespace boost aspect_type a_save_; }; + template <class Rep> + struct duration_put_enabled + : integral_constant<bool, + is_integral<Rep>::value || is_floating_point<Rep>::value + > + {}; + + /** * duration stream inserter * @param os the output stream * @param d to value to insert * @return @c os */ + + template <class CharT, class Traits, class Rep, class Period> + typename boost::enable_if_c< ! duration_put_enabled<Rep>::value, std::basic_ostream<CharT, Traits>& >::type + operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d) + { + std::basic_ostringstream<CharT, Traits> ostr; + ostr << d.count(); + duration<int, Period> dd(0); + bool failed = false; + BOOST_TRY + { + std::ios_base::iostate err = std::ios_base::goodbit; + BOOST_TRY + { + typename std::basic_ostream<CharT, Traits>::sentry opfx(os); + if (bool(opfx)) + { + if (!std::has_facet<duration_put<CharT> >(os.getloc())) + { + if (duration_put<CharT> ().put(os, os, os.fill(), dd, ostr.str().c_str()) .failed()) + { + err = std::ios_base::badbit; + } + } + else if (std::use_facet<duration_put<CharT> >(os.getloc()) .put(os, os, os.fill(), dd, ostr.str().c_str()) .failed()) + { + err = std::ios_base::badbit; + } + os.width(0); + } + } + BOOST_CATCH(...) + { + bool flag = false; + BOOST_TRY + { + os.setstate(std::ios_base::failbit); + } + BOOST_CATCH (std::ios_base::failure ) + { + flag = true; + } + BOOST_CATCH_END + if (flag) throw; + } + BOOST_CATCH_END + if (err) os.setstate(err); + return os; + } + BOOST_CATCH(...) + { + failed = true; + } + BOOST_CATCH_END + if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit); + return os; + + } + template <class CharT, class Traits, class Rep, class Period> - std::basic_ostream<CharT, Traits>& + typename boost::enable_if_c< duration_put_enabled<Rep>::value, std::basic_ostream<CharT, Traits>& >::type operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d) { bool failed = false; diff --git a/boost/chrono/io/duration_put.hpp b/boost/chrono/io/duration_put.hpp index 81c13cf40e..623eae1bf6 100644 --- a/boost/chrono/io/duration_put.hpp +++ b/boost/chrono/io/duration_put.hpp @@ -22,6 +22,17 @@ namespace boost namespace chrono { + namespace detail + { + template <class T> + struct propagate { + typedef T type; + }; + template <> + struct propagate<boost::int_least32_t> { + typedef boost::int_least64_t type; + }; + } /** * @tparam ChatT a character type * @tparam OutputIterator a model of @c OutputIterator @@ -91,24 +102,24 @@ namespace boost */ template <typename Rep, typename Period> iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern, - const CharT* pat_end) const + const CharT* pat_end, const char_type* val = 0) const { if (std::has_facet<duration_units<CharT> >(ios.getloc())) { duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( ios.getloc()); - return put(facet, s, ios, fill, d, pattern, pat_end); + return put(facet, s, ios, fill, d, pattern, pat_end, val); } else { duration_units_default<CharT> facet; - return put(facet, s, ios, fill, d, pattern, pat_end); + return put(facet, s, ios, fill, d, pattern, pat_end, val); } } template <typename Rep, typename Period> iter_type put(duration_units<CharT> const& units_facet, iter_type s, std::ios_base& ios, char_type fill, - duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end) const + duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end, const char_type* val = 0) const { const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc()); @@ -126,7 +137,7 @@ namespace boost { case 'v': { - s = put_value(s, ios, fill, d); + s = put_value(s, ios, fill, d, val); break; } case 'u': @@ -159,20 +170,21 @@ namespace boost * @Returns An iterator pointing immediately after the last character produced. */ template <typename Rep, typename Period> - iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const + iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const char_type* val = 0) const { if (std::has_facet<duration_units<CharT> >(ios.getloc())) { duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >( ios.getloc()); std::basic_string<CharT> str = facet.get_pattern(); - return put(facet, s, ios, fill, d, str.data(), str.data() + str.size()); + return put(facet, s, ios, fill, d, str.data(), str.data() + str.size(), val); } else { duration_units_default<CharT> facet; std::basic_string<CharT> str = facet.get_pattern(); - return put(facet, s, ios, fill, d, str.data(), str.data() + str.size()); + + return put(facet, s, ios, fill, d, str.data(), str.data() + str.size(), val); } } @@ -186,14 +198,22 @@ namespace boost * @Returns s, iterator pointing immediately after the last character produced. */ template <typename Rep, typename Period> - iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const + iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const char_type* val = 0) const { + if (val) + { + while (*val) { + *s = *val; + s++; val++; + } + return s; + } return std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, - static_cast<long int> (d.count())); + static_cast<typename detail::propagate<Rep>::type> (d.count())); } template <typename Rep, typename Period> - iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<process_times<Rep>, Period> const& d) const + iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<process_times<Rep>, Period> const& d, const char_type* = 0) const { *s++ = CharT('{'); s = put_value(s, ios, fill, process_real_cpu_clock::duration(d.count().real)); diff --git a/boost/chrono/io/time_point_io.hpp b/boost/chrono/io/time_point_io.hpp index 629479cde9..ec4ba13aeb 100644 --- a/boost/chrono/io/time_point_io.hpp +++ b/boost/chrono/io/time_point_io.hpp @@ -527,7 +527,9 @@ namespace boost { //! the type of the state to restore - typedef std::basic_ostream<CharT, Traits> state_type; + //typedef std::basic_ostream<CharT, Traits> state_type; + typedef std::ios_base state_type; + //! the type of aspect to save typedef std::basic_string<CharT, Traits> aspect_type; @@ -537,7 +539,7 @@ namespace boost * Store a reference to the i/o stream and the value of the associated @c time format . */ explicit time_fmt_io_saver(state_type &s) : - s_save_(s), a_save_(get_time_fmt(s_save_)) + s_save_(s), a_save_(get_time_fmt<CharT>(s_save_)) { } @@ -547,8 +549,9 @@ namespace boost * Stores a reference to the i/o stream and the value @c new_value to restore given as parameter. */ time_fmt_io_saver(state_type &s, aspect_type new_value) : - s_save_(s), a_save_(new_value) + s_save_(s), a_save_(get_time_fmt<CharT>(s_save_)) { + set_time_fmt(s_save_, new_value); } /** @@ -566,7 +569,7 @@ namespace boost */ void restore() { - set_time_fmt(a_save_, a_save_); + set_time_fmt(s_save_, a_save_); } private: state_type& s_save_; @@ -602,8 +605,9 @@ namespace boost * Stores a reference to the i/o stream and the value @c new_value to restore given as parameter. */ timezone_io_saver(state_type &s, aspect_type new_value) : - s_save_(s), a_save_(new_value) + s_save_(s), a_save_(get_timezone(s_save_)) { + set_timezone(s_save_, new_value); } /** diff --git a/boost/chrono/io_v1/chrono_io.hpp b/boost/chrono/io_v1/chrono_io.hpp index 1a7e832b5b..12d9f5436f 100644 --- a/boost/chrono/io_v1/chrono_io.hpp +++ b/boost/chrono/io_v1/chrono_io.hpp @@ -22,7 +22,7 @@ #include <boost/type_traits/is_scalar.hpp> #include <boost/type_traits/is_signed.hpp> #include <boost/mpl/if.hpp> -#include <boost/math/common_factor_rt.hpp> +#include <boost/integer/common_factor_rt.hpp> #include <boost/chrono/detail/scan_keyword.hpp> #include <boost/utility/enable_if.hpp> #include <boost/chrono/detail/no_warning/signed_unsigned_cmp.hpp> @@ -241,7 +241,7 @@ reduce(intermediate_type& r, unsigned long long& den, std::ios_base::iostate& er typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t; // Reduce r * num / den - common_type_t t = math::gcd<common_type_t>(common_type_t(r), common_type_t(den)); + common_type_t t = integer::gcd<common_type_t>(common_type_t(r), common_type_t(den)); r /= t; den /= t; if (den != 1) @@ -504,8 +504,8 @@ operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d) // unit is num/den // r should be multiplied by (num/den) / Period // Reduce (num/den) / Period to lowest terms - unsigned long long gcd_n1_n2 = math::gcd<unsigned long long>(num, Period::num); - unsigned long long gcd_d1_d2 = math::gcd<unsigned long long>(den, Period::den); + unsigned long long gcd_n1_n2 = integer::gcd<unsigned long long>(num, Period::num); + unsigned long long gcd_d1_d2 = integer::gcd<unsigned long long>(den, Period::den); num /= gcd_n1_n2; den /= gcd_d1_d2; unsigned long long n2 = Period::num / gcd_n1_n2; |