Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75191 - in trunk: boost/chrono/io libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2011-10-31 09:34:35


Author: viboes
Date: 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
New Revision: 75191
URL: http://svn.boost.org/trac/boost/changeset/75191

Log:
Chrono: rename unit_strings.hpp to duration_units.hpp
Added:
   trunk/boost/chrono/io/duration_units.hpp
      - copied, changed from r75186, /trunk/boost/chrono/io/unit_strings.hpp
Removed:
   trunk/boost/chrono/io/unit_strings.hpp
Text files modified:
   trunk/boost/chrono/io/duration_io.hpp | 14 +++
   trunk/boost/chrono/io/duration_put.hpp | 137 ++++++++++++++++++++-------------------
   trunk/boost/chrono/io/duration_unit_string.hpp | 2
   trunk/boost/chrono/io/duration_units.hpp | 4
   trunk/libs/chrono/test/io/duration_input.cpp | 1
   5 files changed, 86 insertions(+), 72 deletions(-)

Modified: trunk/boost/chrono/io/duration_io.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_io.hpp (original)
+++ trunk/boost/chrono/io/duration_io.hpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
@@ -25,9 +25,7 @@
 #include <boost/chrono/io/ios_base_state.hpp>
 //#include <boost/format.hpp>
 #include <locale>
-#if defined BOOST_CHRONO_USES_DURATION_PUT
 #include <boost/chrono/io/duration_put.hpp>
-#endif
 namespace boost
 {
   namespace chrono
@@ -446,6 +444,12 @@
       aspect_type a_save_;
     };
 
+ /**
+ *
+ * @param os
+ * @param d
+ * @return @c os
+ */
     template <class CharT, class Traits, class Rep, class Period>
     std::basic_ostream<CharT, Traits>&
     operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d)
@@ -575,6 +579,12 @@
 
     }
 
+ /**
+ *
+ * @param is the input stream
+ * @param d the duration
+ * @return @c is
+ */
     template <class CharT, class Traits, class Rep, class Period>
     std::basic_istream<CharT, Traits>&
     operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)

Modified: trunk/boost/chrono/io/duration_put.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_put.hpp (original)
+++ trunk/boost/chrono/io/duration_put.hpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
@@ -5,11 +5,15 @@
 // http://www.boost.org/LICENSE_1_0.txt).
 //
 
+/**
+ * Duration formatting facet for output.
+ */
 #ifndef BOOST_CHRONO_IO_DURATION_PUT_HPP
 #define BOOST_CHRONO_IO_DURATION_PUT_HPP
 
 #include <boost/chrono/config.hpp>
-#include <boost/chrono/io/unit_strings.hpp>
+#include <boost/chrono/io/duration_units.hpp>
+#include <boost/assert.hpp>
 #include <locale>
 
 namespace boost
@@ -17,16 +21,40 @@
   namespace chrono
   {
 
+ /**
+ * @tparam ChatT a character type
+ * @tparam OutputIterator a model of @c OutputIterator
+ *
+ * The @c duration_put facet provides facilities for formatted output of duration values.
+ * The member function of @c duration_put take a duration and translate this into character string representation.
+ *
+ * FIXME As the facet doesn't have any data, I'm wondering if this should functions
+ * shouldn't be at the namespace level or static member functions.
+ * This will leverage the user to need to ensure that the facet is imbued on the ios_base.
+ */
     template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
     class duration_put: public std::locale::facet
     {
     public:
+ /**
+ * Type of character the facet is instantiated on.
+ */
       typedef CharT char_type;
+ /**
+ * Type of iterator used to write in the character buffer.
+ */
       typedef OutputIterator iter_type;
 
       /**
- * Facet constructor.
+ * Construct a duration_put facet.
        * @param refs
+ * @Effects Construct a duration_put facet.
+ * If the @c refs argument is @c 0 then destruction of the object is
+ * delegated to the @c locale, or locales, containing it. This allows
+ * the user to ignore lifetime management issues. On the other had,
+ * if @c refs is @c 1 then the object must be explicitly deleted;
+ * the @c locale will not do so. In this case, the object can be
+ * maintained across the lifetime of multiple locales.
        */
       explicit duration_put(size_t refs = 0) :
         std::locale::facet(refs)
@@ -35,17 +63,17 @@
 
       /**
        *
- * @param s
- * @param ios
- * @param d
- * @param pattern
- * @param pat_end
+ * @param s an output stream iterator
+ * @param ios a reference to a ios_base
+ * @param d the duration
+ * @param pattern begin of the formatting patter
+ * @param pat_end end of the formatting pattern
        *
        * @Effects Steps through the sequence from @c pattern to @c pat_end,
        * identifying characters that are part of a pattern sequence. Each character
        * that is not part of a pattern sequence is written to @c s immediately, and
        * each pattern sequence, as it is identified, results in a call to
- * @c do_put_value or @c do_put_unit;
+ * @c put_value or @c put_unit;
        * thus, pattern elements and other characters are interleaved in the output
        * in the order in which they appear in the pattern. Pattern sequences are
        * identified by converting each character @c c to a @c char value as if by
@@ -54,9 +82,9 @@
        * followed by a pattern specifier character @c spec, which can be @c 'v' for
        * the duration value or @c 'u' for the duration unit. .
        * For each valid pattern sequence identified, calls
- * <c>do_put_value(s, ios, d)</c> or <c>do_put_unit(s, ios, d)</c>.
+ * <c>put_value(s, ios, d)</c> or <c>put_unit(s, ios, d)</c>.
        *
- * @Returns: An iterator pointing immediately after the last character produced.
+ * @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, duration<Rep, Period> const& d, const CharT* pattern,
@@ -67,7 +95,8 @@
 
         for (; pattern != pat_end; ++pattern)
         {
- if ( (*pattern != '%') || ( (pattern + 1) == pat_end) || (!std::strchr("uvx", * (pattern + 1))))
+ // FIXME: Shouldn't "uvx" be a basic_string<CharT> ?????
+ if ( (*pattern != CharT('%')) || ( (pattern + 1) == pat_end) || (!std::strchr("uvx", * (pattern + 1))))
           {
             *s++ = *pattern;
           }
@@ -77,12 +106,13 @@
             switch (*pattern)
             {
             case 'v':
- std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ',
- static_cast<long int> (d.count()));
+ {
+ put_value(s, ios, d);
               break;
+ }
             case 'u':
             {
- std::use_facet<duration_units<CharT> >(ios.getloc()).put(s, ios, d);
+ put_unit(s, ios, d);
               break;
             }
             case 'x':
@@ -93,12 +123,26 @@
               break;
             }
             default:
+ BOOST_ASSERT(false && "Boost::Chrono internal error.");
               break;
             }
           }
         }
         return s;
       }
+
+ /**
+ *
+ * @param s an output stream iterator
+ * @param ios a reference to a ios_base
+ * @param d the duration
+ * @Effects imbue in @c ios the @c duration_units_default facet if not already present.
+ * Retrieves Stores the duration pattern from the @c duration_unit facet in let say @c str. Last as if
+ * @code
+ * return put(s, ios, d, str.data(), str.data() + str.size());
+ * @codeend
+ * @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, duration<Rep, Period> const& d) const
       {
@@ -111,85 +155,46 @@
 
       /**
        *
- * @param s
- * @param ios
- * @param d
- * @param pattern
+ * @param s an output stream iterator
+ * @param ios a reference to a ios_base
+ * @param d the duration
        * @Effects Calls do_put_value(s, f, d).
- * @Returns: An iterator pointing immediately after the last character produced.
+ * @Returns An iterator pointing immediately after the last character produced.
        */
       template <typename Rep, typename Period>
       iter_type put_value(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d) const
       {
- do_put_value(s, ios, d);
+ return std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ',
+ static_cast<long int> (d.count()));
       }
 
       /**
        *
- * @param s
- * @param ios
- * @param d
+ * @param s an output stream iterator
+ * @param ios a reference to a ios_base
+ * @param d the duration
        * @param pattern
        * @Effects Calls do_put_unit(s, f, d).
- * @Returns: An iterator pointing immediately after the last character produced.
+ * @Returns An iterator pointing immediately after the last character produced.
        */
       template <typename Rep, typename Period>
       iter_type put_unit(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d) const
       {
- do_put_unit(s, ios, d);
+ return std::use_facet<duration_units<CharT> >(ios.getloc()).put(s, ios, d);
       }
 
       /**
        * Unique identifier for this type of facet.
        */
       static std::locale::id id;
- protected:
+
       /**
- *
+ * @Effects Destroy the facet
        */
       ~duration_put()
       {
       }
 
- // /**
- // *
- // * @param s
- // * @param ios
- // * @param d
- // * @param pattern
- // * @Effects: Formats the count() the parameter d into characters
- // * placed on the output sequence s.
- // * @Returns: An iterator pointing immediately after the last character produced.
- // */
- // virtual iter_type do_put_value(iter_type s, std::ios_base& ios, Rep d) const
- // {
- // stringstream str(ios.getloc());
- // str << d.days_.count();
- // const CharT* b = str.str().data();
- // const CharT* e = b + str.str().size();
- // std::copy(b, e, s);
- // return s;
- // }
- // /**
- // *
- // * @param s
- // * @param ios
- // * @param d
- // * @param pattern
- // * @Effects: Formats the unit of the parameter d into characters
- // * placed on the output sequence s. The unit is obtained calling to the duration_unit<CharT> facet to_string()
- // * @Returns: An iterator pointing immediately after the last character produced.
- // */
- // virtual iter_type do_put_unit(iter_type s, std::ios_base& ios, duration<Rep,
- // Period> const& d) const
- // {
- // // retrieve duration_units facet
- // // get string
- // std::basic_string<CharT> str;
- // const CharT* b = str.data();
- // const CharT* e = b + str.size();
- // std::copy(b, e, s);
- // }
     };
 
     template <class CharT, class OutputIterator>

Modified: trunk/boost/chrono/io/duration_unit_string.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_unit_string.hpp (original)
+++ trunk/boost/chrono/io/duration_unit_string.hpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
@@ -13,7 +13,7 @@
 #include <boost/ratio/ratio_io.hpp>
 #include <boost/chrono/io/duration_style.hpp>
 #include <boost/chrono/io/translate.hpp>
-#include <boost/chrono/io/unit_strings.hpp>
+#include <boost/chrono/io/duration_units.hpp>
 
 #include <string>
 #include <locale>

Copied: trunk/boost/chrono/io/duration_units.hpp (from r75186, /trunk/boost/chrono/io/unit_strings.hpp)
==============================================================================
--- /trunk/boost/chrono/io/unit_strings.hpp (original)
+++ trunk/boost/chrono/io/duration_units.hpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
@@ -5,8 +5,8 @@
 // http://www.boost.org/LICENSE_1_0.txt).
 //
 
-#ifndef BOOST_CHRONO_IO_UNIT_STRINGS_HPP
-#define BOOST_CHRONO_IO_UNIT_STRINGS_HPP
+#ifndef BOOST_CHRONO_IO_DURATION_UNITS_HPP
+#define BOOST_CHRONO_IO_DURATION_UNITS_HPP
 
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/duration.hpp>

Deleted: trunk/boost/chrono/io/unit_strings.hpp
==============================================================================
--- trunk/boost/chrono/io/unit_strings.hpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
+++ (empty file)
@@ -1,871 +0,0 @@
-//
-// (C) Copyright 2011 Vicente J. Botet Escriba
-// Use, modification and distribution are subject to the Boost Software License,
-// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt).
-//
-
-#ifndef BOOST_CHRONO_IO_UNIT_STRINGS_HPP
-#define BOOST_CHRONO_IO_UNIT_STRINGS_HPP
-
-#include <boost/chrono/config.hpp>
-#include <boost/chrono/duration.hpp>
-#include <boost/chrono/io/duration_style.hpp>
-#include <boost/chrono/process_cpu_clocks.hpp>
-#include <boost/chrono/io/ios_base_state.hpp>
-#include <string>
-#include <iostream>
-//#include <locale>
-#include <boost/utility/enable_if.hpp>
-
-namespace boost
-{
- namespace chrono
- {
- template <typename Period>
- struct is_localizable: false_type
- {
- };
-
- template <>
- struct is_localizable<atto> : true_type
- {
- };
- template <>
- struct is_localizable<femto> : true_type
- {
- };
- template <>
- struct is_localizable<pico> : true_type
- {
- };
- template <>
- struct is_localizable<nano> : true_type
- {
- };
- template <>
- struct is_localizable<micro> : true_type
- {
- };
- template <>
- struct is_localizable<milli> : true_type
- {
- };
- template <>
- struct is_localizable<centi> : true_type
- {
- };
- template <>
- struct is_localizable<deci> : true_type
- {
- };
- template <>
- struct is_localizable<ratio<1> > : true_type
- {
- };
- template <>
- struct is_localizable<deca> : true_type
- {
- };
- template <>
- struct is_localizable<hecto> : true_type
- {
- };
- template <>
- struct is_localizable<kilo> : true_type
- {
- };
- template <>
- struct is_localizable<mega> : true_type
- {
- };
- template <>
- struct is_localizable<tera> : true_type
- {
- };
- template <>
- struct is_localizable<peta> : true_type
- {
- };
- template <>
- struct is_localizable<exa> : true_type
- {
- };
- template <>
- struct is_localizable<ratio<60> > : true_type
- {
- };
- template <>
- struct is_localizable<ratio<3600> > : true_type
- {
- };
-
- namespace detail
- {
-
- class rt_ratio
- {
- public:
- template <typename Period>
- rt_ratio(Period const&) :
- num(Period::type::num), den(Period::type::den)
- {
- }
-
- intmax_t num;
- intmax_t den;
- };
- }
-
- /**
- * @c duration_units facet gives useful information about the duration units,
- * as the number of plural forms, the plural form associated to a duration,
- * the text associated to a plural form and a duration's period,
- */
- template <typename CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
- class duration_units: public std::locale::facet
- {
- public:
- typedef CharT char_type;
- typedef OutputIterator iter_type;
-
- static std::locale::id id;
-
- explicit duration_units(size_t refs = 0) :
- std::locale::facet(refs)
- {
- }
-
- /* TBR */
- virtual bool swaps_value_unit_order() const = 0;
-
- /**
- *
- * @tparam Rep
- * @tparam Period
- * @Requires Rep must be explicitly convertible to int_least64_t.
- * @Requires Period is named.
- *
- * @param s
- * @param ios
- * @param d
- * @Effects puts the unit associated to the duration @c d in @c s taken in account the @c ios state flags.
- * The implementation uses the non template virtual function do_put as if
- * @code
- * return do_put(s, ios, get_duration_style(ios), Period(), int_least64_t(d.count()));
- * @codeend
- *
- * where @get_duration_style gives the duration style associated to @ios.
- * @return s
- */
- template <typename Rep, typename Period>
- typename enable_if<is_localizable<Period> , iter_type>::type put(iter_type s, std::ios_base& ios,
- duration<Rep, Period> const& d) const
- {
- return do_put(s, ios, get_duration_style(ios), Period(), int_least64_t(d.count()));
- }
-
- /**
- *
- * @tparam Rep
- * @tparam Period
- * @Requires Rep must be explicitly convertible to int_least64_t.
- * @Requires Period is not named, that is its textual representation is in the form [N/D].
- *
- * @param s
- * @param ios
- * @param d
- * @Effects puts the unit associated to the duration @c d in @c s taken in account the @c ios state flags.
- * The implementation uses the non template virtual function do_put as if
- * @code
- * return do_put(s, ios, get_duration_style(ios), detail::rt_ratio(Period()), int_least64_t(d.count()));
- * @codeend
- *
- * where @get_duration_style gives the duration style associated to @ios and
- * detail::rt_ratio is a class that flats the template ration on a run-time ration so we can use it in virtual functions.
- * @return s
- */
- template <typename Rep, typename Period>
- typename disable_if<is_localizable<Period> , iter_type>::type put(iter_type s, std::ios_base& ios,
- duration<Rep, Period> const& d) const
- {
- return do_put(s, ios, get_duration_style(ios), detail::rt_ratio(Period()), int_least64_t(d.count()));
- }
-
- /**
- *
- * @return the number of plural forms.
- */
- std::size_t get_plural_forms() const
- {
- return do_get_plural_forms();
- }
-
- /**
- *
- * @param value
- * @return the associated plural form index.
- */
- std::size_t plural_form(int_least64_t value) const
- {
- return do_get_plural_form(value);
- }
-
- /**
- *
- * @param style
- * @param pf
- * @return the translation associated to the plural form given as parameter.
- */
- template <typename Period>
- typename enable_if<is_localizable<Period> , std::basic_string<CharT> >::type get_plural_form(
- duration_style::type style, std::size_t pf) const
- {
- return do_get_plural_form(style, Period(), pf);
- }
-
- /**
- *
- * @return the pattern to be used by default.
- */
- std::basic_string<CharT> get_pattern() const
- {
- return do_get_pattern();
- }
-
- protected:
- virtual std::basic_string<CharT> do_get_pattern() const=0;
- virtual std::size_t do_get_plural_forms() const = 0;
- virtual std::size_t do_get_plural_form(int_least64_t value) const = 0;
-
- // used for ouput
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, atto, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, pico, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, nano, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, micro, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, milli, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, centi, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, deci, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, ratio<1> , int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, deca, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, hecto, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, kilo, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, mega, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, tera, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, peta, int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, exa, int_least64_t) const = 0;
- virtual iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, detail::rt_ratio,
- int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, ratio<60> , int_least64_t) const = 0;
- virtual iter_type
- do_put(iter_type s, std::ios_base& ios, duration_style::type style, ratio<3600> , int_least64_t) const = 0;
-
- // used for input
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, atto, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, pico, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, nano, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, micro, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, milli, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, centi, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, deci, std::size_t pf) const = 0;
- virtual std::basic_string<CharT>
- do_get_plural_form(duration_style::type style, ratio<1> , std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, deca, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, hecto, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, kilo, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, mega, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, giga, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, tera, std::size_t pf) const = 0;
- // virtual std::basic_string<CharT> do_get_plural_form(duration_style::type style, exa, std::size_t pf) const = 0;
- virtual std::basic_string<CharT>
- do_get_plural_form(duration_style::type style, ratio<60> , std::size_t pf) const = 0;
- virtual std::basic_string<CharT>
- do_get_plural_form(duration_style::type style, ratio<3600> , std::size_t pf) const = 0;
-
- };
-
- template <typename CharT, class OutputIterator>
- std::locale::id duration_units<CharT, OutputIterator>::id;
-
- ///////////////////////////
- // This class is used to define the strings for the default English
- template <typename CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
- class duration_units_default: public duration_units<CharT, OutputIterator>
- {
- public:
- typedef CharT char_type;
- typedef OutputIterator iter_type;
-
- explicit duration_units_default(size_t refs = 0) :
- duration_units<CharT> (refs)
- {
- }
- bool swaps_value_unit_order() const
- {
- return false;
- }
-
- protected:
- std::size_t do_get_plural_forms() const
- {
- return 2;
- }
-
- std::size_t do_get_plural_form(int_least64_t value) const
- {
- return (value == -1 || value == 1) ? 0 : 1;
- }
-
- std::basic_string<CharT> do_get_pattern() const
- {
- static const CharT t[] =
- { '%', 'v', ' ', '%', 'u' };
- static const std::basic_string<CharT> pattern(t, t + sizeof (t) / sizeof (t[0]));
-
- return pattern;
- }
-
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, atto u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, pico u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
-
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, nano u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, micro u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, milli u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, centi u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, deci u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base&, duration_style::type style, ratio<1> u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_plural_form(style, u, do_get_plural_form(value));
- return std::copy(str.begin(), str.end(), s);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, deca u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, hecto u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
-
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, kilo u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, mega u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, giga u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, tera u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, peta u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, exa u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_ratio_prefix(style, u);
- std::copy(str.begin(), str.end(), s);
- return do_put(s, ios, style, ratio<1> (), value);
- }
-
- iter_type do_put(iter_type s, std::ios_base&, duration_style::type style, ratio<60> u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_plural_form(style, u, do_get_plural_form(value));
- return std::copy(str.begin(), str.end(), s);
- }
-
- iter_type do_put(iter_type s, std::ios_base&, duration_style::type style, ratio<3600> u, int_least64_t value) const
- {
- std::basic_string<CharT> str = do_get_plural_form(style, u, do_get_plural_form(value));
- return std::copy(str.begin(), str.end(), s);
- }
-
- iter_type do_put(iter_type s, std::ios_base& ios, duration_style::type style, detail::rt_ratio rtr,
- int_least64_t value) const
- {
- *s++ = CharT('[');
- std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ', rtr.num);
- *s++ = CharT('/');
- std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ', rtr.den);
- *s++ = CharT(']');
-
- return do_put(s, ios, style, ratio<1> (), value);
- }
-
- std::basic_string<CharT> do_get_plural_form(duration_style::type style, ratio<1> , std::size_t pf) const
- {
- static const CharT t[] =
- { 's' };
- static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
- static const CharT u[] =
- { 's', 'e', 'c', 'o', 'n', 'd' };
- static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 's', 'e', 'c', 'o', 'n', 'd', 's' };
- static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- if (pf == 0) return singular;
- if (pf == 1) return plural;
- // assert
- throw "exception";
- }
-
- std::basic_string<CharT> do_get_plural_form(duration_style::type style, ratio<60> , std::size_t pf) const
- {
- static const CharT t[] =
- { 'm', 'i', 'n' };
- static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
-
- static const CharT u[] =
- { 'm', 'i', 'n', 'u', 't', 'e' };
- static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'm', 'i', 'n', 'u', 't', 'e', 's' };
- static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- if (pf == 0) return singular;
- if (pf == 1) return plural;
- // assert
- throw "exception";
- }
-
- std::basic_string<CharT> do_get_plural_form(duration_style::type style, ratio<3600> , std::size_t pf) const
- {
- static const CharT t[] =
- { 'h' };
- static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
- static const CharT u[] =
- { 'h', 'o', 'u', 'r' };
- static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'h', 'o', 'u', 'r', 's' };
- static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- if (pf == 0) return singular;
- if (pf == 1) return plural;
- // assert
- throw "exception";
- }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, atto>, std::size_t pf) const
- // {
- // return to_string(style, atto())+do_get_plural_form(style, ratio<1>(), pf);
- // }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, pico>, std::size_t pf) const
- // {
- // return to_string(style, pico())+do_get_plural_form(style, ratio<1>(), pf);
- // }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, nano>, std::size_t pf) const
- // {
- // return to_string(style, nano())+do_get_plural_form(style, ratio<1>(), pf);
- // }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, micro>, std::size_t pf) const
- // {
- // return to_string(style, micro())+do_get_plural_form(style, ratio<1>(), pf);
- // }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, milli>, std::size_t pf) const
- // {
- // return to_string(style, milli())+do_get_plural_form(style, ratio<1>(), pf);
- // }
- // std::basic_string<CharT> do_get_plural_form(duration_style::type style, duration<boost::int_least64_t, centi>, std::size_t pf) const
- // {
- // return to_string(style, centi())+do_get_plural_form(style, ratio<1>(), pf);
- // }
-
- protected:
-
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, atto) const
- {
- static const CharT u[] =
- { 'a', 't', 't', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'a' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, pico) const
- {
- static const CharT u[] =
- { 'p', 'i', 'c', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'p' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, nano) const
- {
- static const CharT u[] =
- { 'n', 'a', 'n', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'n' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, micro) const
- {
- static const CharT u[] =
- { 'm', 'i', 'c', 'r', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'u' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
-
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, milli) const
- {
- static const CharT u[] =
- { 'm', 'i', 'l', 'l', 'i' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'm' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, centi) const
- {
- static const CharT u[] =
- { 'c', 'e', 'n', 't', 'i' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'c' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, deci) const
- {
- static const CharT u[] =
- { 'd', 'e', 'c', 'i' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'd' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, deca) const
- {
- static const CharT u[] =
- { 'd', 'e', 'c', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'd', 'a' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, hecto) const
- {
- static const CharT u[] =
- { 'h', 'e', 'c', 't', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'h' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, kilo) const
- {
- static const CharT u[] =
- { 'k', 'i', 'l', 'o' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'k' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, mega) const
- {
- static const CharT u[] =
- { 'm', 'e', 'g', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'M' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, giga) const
- {
- static const CharT u[] =
- { 'g', 'i', 'g', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'G' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, tera) const
- {
- static const CharT u[] =
- { 't', 'e', 'r', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'T' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, peta) const
- {
- static const CharT u[] =
- { 'p', 'e', 't', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'P' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
- virtual std::basic_string<CharT> do_get_ratio_prefix(duration_style::type style, exa) const
- {
- static const CharT u[] =
- { 'e', 'x', 'a' };
- static const std::basic_string<CharT> prefix(u, u + sizeof (u) / sizeof (u[0]));
- static const CharT v[] =
- { 'E' };
- static const std::basic_string<CharT> symbol(v, v + sizeof (v) / sizeof (v[0]));
-
- if (style == duration_style::symbol) return symbol;
- return prefix;
- }
-
- };
-
-#if defined BOOST_CHRONO_IS_LOCALIZABLE_VIRTUAL
-
- template <typename CharT, typename T>
- std::basic_string<CharT> to_basic_string(T const&v, std::locale const &loc)
- {
- std::basic_ostringstream<CharT> os;
- os.imbue(loc);
- os << v;
- return os.str();
- }
-
- template <typename CharT, typename Rep, typename Period>
- typename enable_if<is_localizable<Period>, std::basic_string<CharT> >::type
- to_basic_string(
- duration_style::type style,
- duration<Rep,Period> value,
- std::locale const &loc
- )
- {
- std::locale nloc;
- if (!std::has_facet<duration_units<CharT> >(loc))
- {
- nloc =std::locale(loc, new duration_units_default<CharT>());
- }
- else
- {
- nloc=loc;
- }
- duration_units<CharT> const & f = std::use_facet<duration_units<CharT> >(nloc);
-
- if (f.swaps_value_unit_order())
- {
- return f.to_string(style, Period(), int_least64_t(value.count())) + " " + to_basic_string<CharT>(value.count(), nloc);
- }
- else
- {
- return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, Period(), int_least64_t(value.count()));
- }
- }
-
- template <typename CharT, typename Rep, typename Period>
- typename disable_if<is_localizable<Period> , std::basic_string<CharT> >::type
- to_basic_string(
- duration_style::type style,
- duration<Rep,Period> value,
- std::locale const& loc
- )
- {
- std::locale nloc;
- if (!std::has_facet<duration_units<CharT> >(loc))
- {
- nloc =std::locale(loc, new duration_units_default<CharT>());
- }
- else
- {
- nloc=loc;
- }
- duration_units<CharT> const & f = std::use_facet<duration_units<CharT> >(nloc);
- if (f.swaps_value_unit_order())
- {
- return f.to_string(style, detail::rt_ratio(Period()), int_least64_t(value.count())) + " " + to_basic_string<CharT>(value.count(), nloc);
- }
- else
- {
- return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, detail::rt_ratio(Period()), int_least64_t(value.count()));
- }
- }
-
- template <typename CharT, typename Rep, typename Period>
- typename enable_if<is_localizable<Period>, std::basic_string<CharT> >::type
- to_basic_string(
- duration_style::type style,
- duration<process_times<Rep>,Period> value,
- std::locale const &loc
- )
- {
- std::locale nloc;
- if (!std::has_facet<duration_units<CharT> >(loc))
- {
- nloc =std::locale(loc, new duration_units_default<CharT>());
- }
- else
- {
- nloc=loc;
- }
- duration_units<CharT> const & f = std::use_facet<duration_units<CharT> >(nloc);
-
- if (f.swaps_value_unit_order())
- {
- return f.to_string(style, nano(), int_least64_t(value.count())) + " " + to_basic_string<CharT>(value.count(), nloc);
- }
- else
- {
- return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, nano(), int_least64_t(value.count()));
- }
- }
-
- template <typename CharT, typename Rep, typename Period>
- typename disable_if<is_localizable<Period> , std::basic_string<CharT> >::type
- to_basic_string(
- duration_style::type style,
- duration<process_times<Rep>,Period> value,
- std::locale const& loc
- )
- {
- std::locale nloc;
- if (!std::has_facet<duration_units<CharT> >(loc))
- {
- nloc =std::locale(loc, new duration_units_default<CharT>());
- }
- else
- {
- nloc=loc;
- }
- duration_units<CharT> const & f = std::use_facet<duration_units<CharT> >(nloc);
- if (f.swaps_value_unit_order())
- {
- return f.to_string(style, detail::rt_ratio(nano()), int_least64_t(value.count())) + " " + to_basic_string<CharT>(value.count(), nloc);
- }
- else
- {
- return to_basic_string<CharT>(value.count(), nloc) + " " + f.to_string(style, detail::rt_ratio(nano()), int_least64_t(value.count()));
- }
- }
-
- template <typename CharT, typename Rep, typename Period>
- std::basic_string<CharT>
- to_basic_string(duration_style::type style, duration<Rep,Period> value)
- {
- return to_basic_string<CharT>(style, value, std::locale());
- }
-#endif
-
- } // chrono
-
-} // boost
-
-#endif // header

Modified: trunk/libs/chrono/test/io/duration_input.cpp
==============================================================================
--- trunk/libs/chrono/test/io/duration_input.cpp (original)
+++ trunk/libs/chrono/test/io/duration_input.cpp 2011-10-31 09:34:34 EDT (Mon, 31 Oct 2011)
@@ -3,7 +3,6 @@
 // See http://www.boost.org/LICENSE_1_0.txt
 
 #include <boost/chrono/chrono_io.hpp>
-#include <boost/chrono/io/unit_strings.hpp>
 #include <sstream>
 #include <boost/detail/lightweight_test.hpp>
 


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