Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75562 - trunk/boost/chrono/io
From: vicente.botet_at_[hidden]
Date: 2011-11-19 19:37:34


Author: viboes
Date: 2011-11-19 19:37:33 EST (Sat, 19 Nov 2011)
New Revision: 75562
URL: http://svn.boost.org/trac/boost/changeset/75562

Log:
Chrono: minor refactoring from duration_get to duration_units
Text files modified:
   trunk/boost/chrono/io/duration_get.hpp | 157 +--------
   trunk/boost/chrono/io/duration_units.hpp | 599 +++++++++++++++++++++++----------------
   trunk/boost/chrono/io/time_point_get.hpp | 14
   3 files changed, 370 insertions(+), 400 deletions(-)

Modified: trunk/boost/chrono/io/duration_get.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_get.hpp (original)
+++ trunk/boost/chrono/io/duration_get.hpp 2011-11-19 19:37:33 EST (Sat, 19 Nov 2011)
@@ -189,7 +189,7 @@
 
         typedef typename detail::duration_io_intermediate<Rep>::type intermediate_type;
         intermediate_type r;
- detail::rt_ratio rt;
+ rt_ratio rt;
         bool value_found = false, unit_found = false;
         //bool loc_found=false;
 
@@ -242,20 +242,6 @@
               }
               break;
             }
- // case 'x':
- // {
- // if (unit_found || value_found || loc_found) {
- // err |= std::ios_base::failbit;
- // return s;
- // }
- // loc_found=true;
- // string_type pat = duration_units<CharT>::imbue_if_has_not(ios).get_pattern();
- // if (pattern+1 != pat_end)
- // pat.append(pattern+1, pat_end);
- // pattern = pat.data();
- // pat_end = pattern + pat.size();
- // break;
- // }
             default:
               BOOST_ASSERT(false && "Boost::Chrono internal error.");
               break;
@@ -396,7 +382,7 @@
        * @param rt a reference to the duration run-time ratio.
        * @Returns An iterator pointing just beyond the last character that can be determined to be part of a valid name
        */
- iter_type get_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err, detail::rt_ratio &rt) const
+ iter_type get_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err, rt_ratio &rt) const
       {
         if (std::has_facet<duration_units<CharT> >(is.getloc()))
         {
@@ -409,18 +395,18 @@
         }
       }
 
-// iter_type get_unit(duration_units<CharT> const &facet, iter_type i, iter_type e, std::ios_base& is,
-// std::ios_base::iostate& err, detail::rt_ratio &rt) const
-// {
-// }
+ // iter_type get_unit(duration_units<CharT> const &facet, iter_type i, iter_type e, std::ios_base& is,
+ // std::ios_base::iostate& err, rt_ratio &rt) const
+ // {
+ // }
 
       iter_type get_unit(duration_units<CharT> const &facet, iter_type i, iter_type e, std::ios_base& is,
- std::ios_base::iostate& err, detail::rt_ratio &rt) const
+ std::ios_base::iostate& err, rt_ratio &rt) const
       {
 
         if (*i == '[')
         {
- // parse [N/D]s or [N/D]seconds format
+ // parse [N/D]s or [N/D]second or [N/D]seconds format
           ++i;
           i = std::use_facet<std::num_get<CharT, iter_type> >(is.getloc()).get(i, e, is, err, rt.num);
           if ( (err & std::ios_base::failbit) != 0)
@@ -460,14 +446,13 @@
             err |= std::ios_base::failbit;
             return i;
           }
+ // parse s or second or seconds
           return do_get_n_d_prefix_unit(facet, i, e, is, err);
         }
         else
         {
           return do_get_prefix_unit(facet, i, e, is, err, rt);
         }
-
- //return i;
       }
 
       /**
@@ -491,37 +476,28 @@
        * translation in other contexts, as e.g. days and weeks.
        *
        * @param facet the duration_units facet
- * @param i
- * @param e
- * @param
- * @param err
- * @return
+ * @param s start input stream iterator.
+ * @param e end input stream iterator.
+ * @param ios a reference to a ios_base.
+ * @param err the ios_base state.
+ * @return @c s
        */
       virtual iter_type do_get_n_d_prefix_unit(duration_units<CharT> const &facet, iter_type i, iter_type e,
           std::ios_base&, std::ios_base::iostate& err) const
       {
         // parse SI name, short or long
- std::size_t pfs = facet.get_plural_forms() + 1;
 
- // scoped_ptr ???
- string_type* units = new string_type[pfs]();
- string_type* it = units;
- it = facet.fill_units(it, ratio<1>());
- string_type* units_end = units + pfs;
+ const string_type* units = facet.get_n_d_prefix_units_start();
+ const string_type* units_end = facet.get_n_d_prefix_units_end();
 
- //err = std::ios_base::goodbit;
         const string_type* k = chrono_detail::scan_keyword(i, e, units, units_end,
         //~ std::use_facet<std::ctype<CharT> >(loc),
             err);
- switch ( (k - units) / 3)
+ if (!facet.match_n_d_prefix_unit(k))
         {
- case 0:
- break;
- default:
           err |= std::ios_base::failbit;
- std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
- return i;
         }
+
         return i;
       }
 
@@ -541,106 +517,21 @@
        * @Returns An iterator pointing just beyond the last character that can be determined to be part of a valid name.
        */
       virtual iter_type do_get_prefix_unit(duration_units<CharT> const &facet, iter_type i, iter_type e,
- std::ios_base&, std::ios_base::iostate& err, detail::rt_ratio &rt) const
+ std::ios_base&, std::ios_base::iostate& err, rt_ratio &rt) const
       {
         // parse SI name, short or long
- std::size_t pfs = facet.get_plural_forms() + 1;
-
- // scoped_ptr ???
- string_type* units = new string_type[19 * pfs]();
- string_type* it = units;
- it = facet.fill_units(it, atto());
- it = facet.fill_units(it, femto());
- it = facet.fill_units(it, pico());
- it = facet.fill_units(it, nano());
- it = facet.fill_units(it, micro());
- it = facet.fill_units(it, milli());
- it = facet.fill_units(it, centi());
- it = facet.fill_units(it, deci());
- it = facet.fill_units(it, deca());
- it = facet.fill_units(it, hecto());
- it = facet.fill_units(it, kilo());
- it = facet.fill_units(it, mega());
- it = facet.fill_units(it, giga());
- it = facet.fill_units(it, tera());
- it = facet.fill_units(it, peta());
- it = facet.fill_units(it, exa());
- it = facet.fill_units(it, ratio<1> ());
- it = facet.fill_units(it, ratio<60> ());
- it = facet.fill_units(it, ratio<3600> ());
 
- string_type* units_end = units + 19 * pfs;
+ const string_type* units = facet.get_prefix_units_start();
+ const string_type* units_end = facet.get_prefix_units_end();
 
         err = std::ios_base::goodbit;
         const string_type* k = chrono_detail::scan_keyword(i, e, units, units_end,
         //~ std::use_facet<std::ctype<CharT> >(loc),
             err);
 
- std::size_t index = (k - units) / pfs;
- delete[] units;
- switch (index)
- {
- case 0:
- rt = detail::rt_ratio(atto());
- break;
- case 1:
- rt = detail::rt_ratio(femto());
- break;
- case 2:
- rt = detail::rt_ratio(pico());
- break;
- case 3:
- rt = detail::rt_ratio(nano());
- break;
- case 4:
- rt = detail::rt_ratio(micro());
- break;
- case 5:
- rt = detail::rt_ratio(milli());
- break;
- case 6:
- rt = detail::rt_ratio(centi());
- break;
- case 7:
- rt = detail::rt_ratio(deci());
- break;
- case 8:
- rt = detail::rt_ratio(deca());
- break;
- case 9:
- rt = detail::rt_ratio(hecto());
- break;
- case 10:
- rt = detail::rt_ratio(kilo());
- break;
- case 11:
- rt = detail::rt_ratio(mega());
- break;
- case 12:
- rt = detail::rt_ratio(giga());
- break;
- case 13:
- rt = detail::rt_ratio(tera());
- break;
- case 14:
- rt = detail::rt_ratio(peta());
- break;
- case 15:
- rt = detail::rt_ratio(exa());
- break;
- case 16:
- rt = detail::rt_ratio(ratio<1> ());
- break;
- case 17:
- rt = detail::rt_ratio(ratio<60> ());
- break;
- case 18:
- rt = detail::rt_ratio(ratio<3600> ());
- break;
- default:
- err = std::ios_base::failbit;
- std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
- return i;
+ if (!facet.match_prefix_unit(k, rt))
+ {
+ err |= std::ios_base::failbit;
         }
         return i;
 

Modified: trunk/boost/chrono/io/duration_units.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_units.hpp (original)
+++ trunk/boost/chrono/io/duration_units.hpp 2011-11-19 19:37:33 EST (Sat, 19 Nov 2011)
@@ -16,6 +16,8 @@
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/chrono/io/ios_base_state.hpp>
 #include <boost/utility/enable_if.hpp>
+#include <boost/scoped_array.hpp>
+#include <boost/chrono/detail/scan_keyword.hpp>
 #include <string>
 #include <ios>
 #include <locale>
@@ -25,116 +27,115 @@
 {
   namespace chrono
   {
- template <typename Period>
- struct is_localizable: false_type
+ namespace detail
     {
- };
+ 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<giga> : 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
- {
- };
+ 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<giga> : 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
     {
-
- class rt_ratio
+ public:
+ template <typename Period>
+ rt_ratio(Period const&) :
+ num(Period::type::num), den(Period::type::den)
       {
- public:
- template <typename Period>
- rt_ratio(Period const&) :
- num(Period::type::num), den(Period::type::den)
- {
- }
+ }
 
- rt_ratio(intmax_t n = 0, intmax_t d = 0) :
- num(n), den(d)
- {
- }
+ rt_ratio(intmax_t n = 0, intmax_t d = 0) :
+ num(n), den(d)
+ {
+ }
 
- intmax_t num;
- intmax_t 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=char, class OutputIterator = std::ostreambuf_iterator<CharT> >
+ template <typename CharT = char, class OutputIterator = std::ostreambuf_iterator<CharT> >
     class duration_units: public std::locale::facet
     {
     public:
@@ -178,7 +179,7 @@
        * @return s
        */
       template <typename Rep, typename Period>
- typename enable_if<is_localizable<Period> , iter_type>::type put_unit(iter_type s, std::ios_base& ios,
+ typename enable_if<detail::is_localizable<Period>, iter_type>::type put_unit(iter_type s, std::ios_base& ios,
           duration<Rep, Period> const& d) const
       {
         return do_put_unit(s, ios, get_duration_style(ios), Period(), int_least64_t(d.count()));
@@ -197,50 +198,45 @@
        * @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_unit as if
        * @code
- * return do_put_unit(s, ios, get_duration_style(ios), detail::rt_ratio(Period()), int_least64_t(d.count()));
+ * return do_put_unit(s, ios, get_duration_style(ios), 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.
+ * 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_unit(iter_type s, std::ios_base& ios,
+ typename disable_if<detail::is_localizable<Period>, iter_type>::type put_unit(iter_type s, std::ios_base& ios,
           duration<Rep, Period> const& d) const
       {
- return do_put_unit(s, ios, get_duration_style(ios), detail::rt_ratio(Period()), int_least64_t(d.count()));
+ return do_put_unit(s, ios, get_duration_style(ios), rt_ratio(Period()), int_least64_t(d.count()));
       }
 
- /**
- *
- * @return the number of plural forms.
- */
- std::size_t get_plural_forms() const
+ const string_type* get_n_d_prefix_units_start() const
+ {
+ return do_get_n_d_prefix_units_start();
+ }
+ const string_type* get_n_d_prefix_units_end() const
       {
- return do_get_plural_forms();
+ return do_get_n_d_prefix_units_end();
       }
 
- /**
- *
- * @param value
- * @return the associated plural form index.
- */
- std::size_t plural_form(int_least64_t value) const
+ const string_type* get_prefix_units_start() const
       {
- return do_get_plural_form(value);
+ return do_get_prefix_units_start();
+ }
+ const string_type* get_prefix_units_end() const
+ {
+ return do_get_prefix_units_end();
       }
 
- /**
- *
- * @param style
- * @param pf
- * @return the translation associated to the plural form given as parameter.
- */
- template <typename Period>
- typename enable_if<is_localizable<Period> , string_type >::type get_plural_form(
- duration_style_type style, std::size_t pf) const
+ bool match_n_d_prefix_unit(const string_type* k) const
       {
- return do_get_plural_form(style, Period(), pf);
+ return do_match_n_d_prefix_unit(k);
+ }
+ bool match_prefix_unit(const string_type* k, rt_ratio& rt) const
+ {
+ return do_match_prefix_unit(k, rt);
       }
 
       /**
@@ -252,55 +248,18 @@
         return do_get_pattern();
       }
 
- template<typename Period>
- inline string_type* fill_units(string_type* it, Period ) const
- {
- for (std::size_t pf=0; pf < get_plural_forms(); ++pf)
- {
- *it++ = get_plural_form<Period>(duration_style::prefix, pf);
- }
- *it++ = get_plural_form<Period>(duration_style::symbol, 0);
- return it;
- }
-
- const string_type* get_units() const
- {
- string_type* units= new string_type[19*get_plural_forms()]();
- string_type* it = units;
- it = fill_units(it, atto());
- it = fill_units(it, femto());
- it = fill_units(it, pico());
- it = fill_units(it, nano());
- it = fill_units(it, micro());
- it = fill_units(it, milli());
- it = fill_units(it, centi());
- it = fill_units(it, deci());
- it = fill_units(it, deca());
- it = fill_units(it, hecto());
- it = fill_units(it, kilo());
- it = fill_units(it, mega());
- it = fill_units(it, giga());
- it = fill_units(it, tera());
- it = fill_units(it, peta());
- it = fill_units(it, exa());
- it = fill_units(it, ratio<1>());
- it = fill_units(it, ratio<60>());
- it = fill_units(it, ratio<3600>());
+ protected:
 
- return units;
- }
- const string_type* get_units_end(const string_type* units) const
+ virtual ~duration_units()
       {
- return units +19*get_plural_forms();
       }
-
-
- protected:
-
- virtual ~duration_units() {}
       virtual string_type 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;
+ virtual const string_type* do_get_n_d_prefix_units_start() const = 0;
+ virtual const string_type* do_get_n_d_prefix_units_end() const = 0;
+ virtual const string_type* do_get_prefix_units_start() const = 0;
+ virtual const string_type* do_get_prefix_units_end() const = 0;
+ virtual bool do_match_n_d_prefix_unit(const string_type* k) const = 0;
+ virtual bool do_match_prefix_unit(const string_type* k, rt_ratio& rt) const = 0;
 
       // used for ouput
       virtual iter_type
@@ -335,44 +294,24 @@
       do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, peta, int_least64_t) const = 0;
       virtual iter_type
       do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, exa, int_least64_t) const = 0;
- virtual iter_type do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, detail::rt_ratio,
- int_least64_t) const = 0;
+ virtual iter_type
+ do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, rt_ratio, int_least64_t) const = 0;
       virtual iter_type
       do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, ratio<60> , int_least64_t) const = 0;
       virtual iter_type
       do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, ratio<3600> , int_least64_t) const = 0;
 
- // used for input
- virtual string_type do_get_plural_form(duration_style_type style, atto, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, femto, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, pico, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, nano, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, micro, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, milli, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, centi, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, deci, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, ratio<1> , std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, deca, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, hecto, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, kilo, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, mega, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, giga, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, tera, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, peta, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, exa, std::size_t pf) const = 0;
- virtual string_type do_get_plural_form(duration_style_type style, ratio<60> , std::size_t pf) const = 0;
- virtual string_type 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=char, class OutputIterator = std::ostreambuf_iterator<CharT> >
+ template <typename CharT = char, class OutputIterator = std::ostreambuf_iterator<CharT> >
     class duration_units_default: public duration_units<CharT, OutputIterator>
     {
+ static const std::size_t pfs_ = 2;
+
     public:
       typedef CharT char_type;
       typedef std::basic_string<CharT> string_type;
@@ -381,16 +320,139 @@
       explicit duration_units_default(size_t refs = 0) :
         duration_units<CharT, OutputIterator> (refs)
       {
+ string_type* it = n_d_prefix_units_;
+ it = fill_units(it, ratio<1> ());
+ it = prefix_units_;
+ it = fill_units(it, atto());
+ it = fill_units(it, femto());
+ it = fill_units(it, pico());
+ it = fill_units(it, nano());
+ it = fill_units(it, micro());
+ it = fill_units(it, milli());
+ it = fill_units(it, centi());
+ it = fill_units(it, deci());
+ it = fill_units(it, deca());
+ it = fill_units(it, hecto());
+ it = fill_units(it, kilo());
+ it = fill_units(it, mega());
+ it = fill_units(it, giga());
+ it = fill_units(it, tera());
+ it = fill_units(it, peta());
+ it = fill_units(it, exa());
+ it = fill_units(it, ratio<1> ());
+ it = fill_units(it, ratio<60> ());
+ it = fill_units(it, ratio<3600> ());
+ }
+ ~duration_units_default()
+ {
       }
- ~duration_units_default() {}
 
     protected:
- std::size_t do_get_plural_forms() const
+
+ bool do_match_n_d_prefix_unit(const string_type* k) const
+ {
+ std::size_t index = (k - n_d_prefix_units_) / (pfs_ + 1);
+ switch (index)
+ {
+ case 0:
+ break;
+ default:
+ return false;
+ }
+ return true;
+ }
+ bool do_match_prefix_unit(const string_type* k, rt_ratio& rt) const
+ {
+ std::size_t index = (k - prefix_units_) / (pfs_ + 1);
+ switch (index)
+ {
+ case 0:
+ rt = rt_ratio(atto());
+ break;
+ case 1:
+ rt = rt_ratio(femto());
+ break;
+ case 2:
+ rt = rt_ratio(pico());
+ break;
+ case 3:
+ rt = rt_ratio(nano());
+ break;
+ case 4:
+ rt = rt_ratio(micro());
+ break;
+ case 5:
+ rt = rt_ratio(milli());
+ break;
+ case 6:
+ rt = rt_ratio(centi());
+ break;
+ case 7:
+ rt = rt_ratio(deci());
+ break;
+ case 8:
+ rt = rt_ratio(deca());
+ break;
+ case 9:
+ rt = rt_ratio(hecto());
+ break;
+ case 10:
+ rt = rt_ratio(kilo());
+ break;
+ case 11:
+ rt = rt_ratio(mega());
+ break;
+ case 12:
+ rt = rt_ratio(giga());
+ break;
+ case 13:
+ rt = rt_ratio(tera());
+ break;
+ case 14:
+ rt = rt_ratio(peta());
+ break;
+ case 15:
+ rt = rt_ratio(exa());
+ break;
+ case 16:
+ rt = rt_ratio(ratio<1> ());
+ break;
+ case 17:
+ rt = rt_ratio(ratio<60> ());
+ break;
+ case 18:
+ rt = rt_ratio(ratio<3600> ());
+ break;
+ default:
+ std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
+ return false;
+ }
+ return true;
+ }
+ const string_type* do_get_n_d_prefix_units_start() const
+ {
+ return n_d_prefix_units_;
+ }
+ const string_type* do_get_n_d_prefix_units_end() const
+ {
+ return n_d_prefix_units_ + (pfs_ + 1);
+ }
+
+ virtual const string_type* do_get_prefix_units_start() const
+ {
+ return prefix_units_;
+ }
+ virtual const string_type* do_get_prefix_units_end() const
+ {
+ return prefix_units_ + 19 * (pfs_ + 1);
+ }
+
+ virtual std::size_t do_get_plural_forms() const
       {
- return 2;
+ return pfs_;
       }
 
- std::size_t do_get_plural_form(int_least64_t value) const
+ virtual std::size_t do_get_plural_form(int_least64_t value) const
       {
         return (value == -1 || value == 1) ? 0 : 1;
       }
@@ -520,7 +582,7 @@
         return std::copy(str.begin(), str.end(), s);
       }
 
- iter_type do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, detail::rt_ratio rtr,
+ iter_type do_put_unit(iter_type s, std::ios_base& ios, duration_style_type style, rt_ratio rtr,
           int_least64_t value) const
       {
         *s++ = CharT('[');
@@ -544,20 +606,23 @@
         { 's', 'e', 'c', 'o', 'n', 'd', 's' };
         static const string_type plural(v, v + sizeof (v) / sizeof (v[0]));
 
- if (style == duration_style::symbol) {
+ if (style == duration_style::symbol)
+ {
           return symbol;
         }
- if (pf == 0) {
+ if (pf == 0)
+ {
           return singular;
         }
- if (pf == 1) {
+ if (pf == 1)
+ {
           return plural;
         }
         // assert
         throw "exception";
       }
 
- string_type do_get_plural_form(duration_style_type style, ratio<60> , std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, ratio<60> , std::size_t pf) const
       {
         static const CharT t[] =
         { 'm', 'i', 'n' };
@@ -577,7 +642,7 @@
         throw "exception";
       }
 
- string_type do_get_plural_form(duration_style_type style, ratio<3600> , std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, ratio<3600> , std::size_t pf) const
       {
         static const CharT t[] =
         { 'h' };
@@ -595,67 +660,67 @@
         // assert
         throw "exception";
       }
- string_type do_get_plural_form(duration_style_type style, atto u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, atto u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, femto u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, femto u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, pico u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, pico u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, nano u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, nano u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, micro u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, micro u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, milli u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, milli u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, centi u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, centi u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, deci u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, deci u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, deca u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, deca u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, hecto u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, hecto u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, kilo u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, kilo u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, mega u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, mega u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, giga u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, giga u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, tera u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, tera u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, peta u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, peta u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
- string_type do_get_plural_form(duration_style_type style, exa u, std::size_t pf) const
+ virtual string_type do_get_plural_form(duration_style_type style, exa u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_plural_form(style, ratio<1> (), pf);
       }
@@ -664,85 +729,113 @@
 
       virtual string_type do_get_ratio_prefix(duration_style_type style, atto) const
       {
- if (style == duration_style::symbol) return ratio_string<atto,CharT>::symbol();
- return ratio_string<atto,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<atto, CharT>::symbol();
+ return ratio_string<atto, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, femto) const
       {
- if (style == duration_style::symbol) return ratio_string<femto,CharT>::symbol();
- return ratio_string<femto,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<femto, CharT>::symbol();
+ return ratio_string<femto, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, pico) const
       {
- if (style == duration_style::symbol) return ratio_string<pico,CharT>::symbol();
- return ratio_string<pico,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<pico, CharT>::symbol();
+ return ratio_string<pico, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, nano) const
       {
- if (style == duration_style::symbol) return ratio_string<nano,CharT>::symbol();
- return ratio_string<nano,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<nano, CharT>::symbol();
+ return ratio_string<nano, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, micro) const
       {
- if (style == duration_style::symbol) return ratio_string<micro,CharT>::symbol();
- return ratio_string<micro,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<micro, CharT>::symbol();
+ return ratio_string<micro, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, milli) const
       {
- if (style == duration_style::symbol) return ratio_string<milli,CharT>::symbol();
- return ratio_string<milli,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<milli, CharT>::symbol();
+ return ratio_string<milli, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, centi) const
       {
- if (style == duration_style::symbol) return ratio_string<centi,CharT>::symbol();
- return ratio_string<centi,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<centi, CharT>::symbol();
+ return ratio_string<centi, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, deci) const
       {
- if (style == duration_style::symbol) return ratio_string<deci,CharT>::symbol();
- return ratio_string<deci,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<deci, CharT>::symbol();
+ return ratio_string<deci, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, deca) const
       {
- if (style == duration_style::symbol) return ratio_string<deca,CharT>::symbol();
- return ratio_string<deca,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<deca, CharT>::symbol();
+ return ratio_string<deca, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, hecto) const
       {
- if (style == duration_style::symbol) return ratio_string<hecto,CharT>::symbol();
- return ratio_string<hecto,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<hecto, CharT>::symbol();
+ return ratio_string<hecto, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, kilo) const
       {
- if (style == duration_style::symbol) return ratio_string<kilo,CharT>::symbol();
- return ratio_string<kilo,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<kilo, CharT>::symbol();
+ return ratio_string<kilo, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, mega) const
       {
- if (style == duration_style::symbol) return ratio_string<mega,CharT>::symbol();
- return ratio_string<mega,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<mega, CharT>::symbol();
+ return ratio_string<mega, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, giga) const
       {
- if (style == duration_style::symbol) return ratio_string<giga,CharT>::symbol();
- return ratio_string<giga,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<giga, CharT>::symbol();
+ return ratio_string<giga, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, tera) const
       {
- if (style == duration_style::symbol) return ratio_string<tera,CharT>::symbol();
- return ratio_string<tera,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<tera, CharT>::symbol();
+ return ratio_string<tera, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, peta) const
       {
- if (style == duration_style::symbol) return ratio_string<peta,CharT>::symbol();
- return ratio_string<peta,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<peta, CharT>::symbol();
+ return ratio_string<peta, CharT>::prefix();
       }
       virtual string_type do_get_ratio_prefix(duration_style_type style, exa) const
       {
- if (style == duration_style::symbol) return ratio_string<exa,CharT>::symbol();
- return ratio_string<exa,CharT>::prefix();
+ if (style == duration_style::symbol) return ratio_string<exa, CharT>::symbol();
+ return ratio_string<exa, CharT>::prefix();
+ }
+
+ /**
+ *
+ * @param style
+ * @param pf
+ * @return the translation associated to the plural form given as parameter.
+ */
+ template <typename Period>
+ typename enable_if<detail::is_localizable<Period>, string_type>::type get_plural_form(duration_style_type style,
+ std::size_t pf) const
+ {
+ return do_get_plural_form(style, Period(), pf);
       }
 
+ private:
+ template <typename Period>
+ string_type* fill_units(string_type* it, Period) const
+ {
+ for (std::size_t pf = 0; pf < pfs_; ++pf)
+ {
+ *it++ = get_plural_form<Period> (duration_style::prefix, pf);
+ }
+ *it++ = get_plural_form<Period> (duration_style::symbol, 0);
+ return it;
+ }
+
+ string_type n_d_prefix_units_[3];
+ string_type prefix_units_[19 * 3];
+
     };
 
   } // chrono

Modified: trunk/boost/chrono/io/time_point_get.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_get.hpp (original)
+++ trunk/boost/chrono/io/time_point_get.hpp 2011-11-19 19:37:33 EST (Sat, 19 Nov 2011)
@@ -190,20 +190,6 @@
               }
               break;
             }
- // case 'x':
- // {
- // if (duration_found || epoch_found || loc_found) {
- // err |= std::ios_base::failbit;
- // return s;
- // }
- // loc_found=true;
- // std::basic_string<CharT> pat = time_point_units<CharT>::imbue_if_has_not(ios).get_pattern();
- // if (pattern+1 != pat_end)
- // pat.append(pattern+1, pat_end);
- // pattern = pat.data();
- // pat_end = pattern + pat.size();
- // break;
- // }
             default:
               BOOST_ASSERT(false && "Boost::Chrono internal error.");
               break;


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