Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75598 - in trunk: boost/chrono/io boost/chrono/io/utility libs/chrono/example
From: vicente.botet_at_[hidden]
Date: 2011-11-21 17:24:42


Author: viboes
Date: 2011-11-21 17:24:41 EST (Mon, 21 Nov 2011)
New Revision: 75598
URL: http://svn.boost.org/trac/boost/changeset/75598

Log:
Chrono: Yet another renaming in duration_units
Text files modified:
   trunk/boost/chrono/io/duration_get.hpp | 5
   trunk/boost/chrono/io/duration_units.hpp | 219 +++++++++++++++++----------------------
   trunk/boost/chrono/io/time_point_get.hpp | 6
   trunk/boost/chrono/io/time_point_io.hpp | 4
   trunk/boost/chrono/io/utility/to_string.hpp | 4
   trunk/libs/chrono/example/french.cpp | 2
   6 files changed, 107 insertions(+), 133 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-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -191,10 +191,9 @@
         intermediate_type r;
         rt_ratio rt;
         bool value_found = false, unit_found = false;
- //bool loc_found=false;
 
         const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
- err = std::ios_base::goodbit;
+ //err = std::ios_base::goodbit;
         while (pattern != pat_end && err == std::ios_base::goodbit)
         {
           if (s == end)
@@ -264,6 +263,7 @@
           else
           {
             err |= std::ios_base::failbit;
+ return s;
           }
 
         }
@@ -348,7 +348,6 @@
           std::basic_string<CharT> str = facet.get_pattern();
           return get(facet, s, end, ios, err, d, str.data(), str.data() + str.size());
         }
-
       }
 
       /**

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-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -13,11 +13,7 @@
 #include <boost/ratio/ratio_io.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 <boost/utility/enable_if.hpp>
-#include <boost/scoped_array.hpp>
-#include <boost/chrono/detail/scan_keyword.hpp>
 #include <string>
 #include <ios>
 #include <locale>
@@ -27,91 +23,6 @@
 {
   namespace chrono
   {
- 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
- {
- };
-
- }
     class rt_ratio
     {
     public:
@@ -326,6 +237,7 @@
     template <typename CharT = char>
     class duration_units_default: public duration_units<CharT>
     {
+ protected:
       static const std::size_t pfs_ = 2;
 
     public:
@@ -354,7 +266,28 @@
       {
         string_type* it = n_d_valid_units_;
         it = fill_units(it, ratio<1> ());
- it = valid_units_;
+ it = init_valid_units(valid_units_);
+ }
+
+ /**
+ * Destroys the facet.
+ */
+ ~duration_units_default()
+ {
+ }
+
+ protected:
+
+ explicit duration_units_default(string_type*, size_t refs = 0) :
+ duration_units<CharT> (refs)
+ {
+ string_type* it = n_d_valid_units_;
+ it = fill_units(it, ratio<1> ());
+ //it = init_valid_units(valid_units);
+ }
+
+ string_type* init_valid_units(string_type* it)
+ {
         it = fill_units(it, atto());
         it = fill_units(it, femto());
         it = fill_units(it, pico());
@@ -374,16 +307,9 @@
         it = fill_units(it, ratio<1> ());
         it = fill_units(it, ratio<60> ());
         it = fill_units(it, ratio<3600> ());
- }
- /**
- * Destroys the facet.
- */
- ~duration_units_default()
- {
+ return it;
       }
 
- protected:
-
       /**
        * @param k the found pointer to the [N/D] unit.
        * @return true if @c k matches a valid unit.
@@ -468,7 +394,6 @@
           rt = rt_ratio(ratio<3600> ());
           break;
         default:
- std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
           return false;
         }
         return true;
@@ -554,9 +479,9 @@
        * In English the suffix used after [N/D] is the one associated to the period ratio<1>.
        * @return the [N/D] suffix unit associated to this duration.
        */
- std::string do_get_n_d_unit(duration_style::type style, rt_ratio, intmax_t ) const
+ std::string do_get_n_d_unit(duration_style::type style, rt_ratio, intmax_t v) const
       {
- return do_get_unit(style, ratio<1>(), 1);
+ return do_get_unit(style, ratio<1>(), do_get_plural_form(v));
       }
 
       /**
@@ -631,17 +556,31 @@
 
     protected:
       /**
- *
- * @param value
- * @return
+ * @return the number of associated plural forms this facet manages.
+ */
+ virtual std::size_t do_get_plural_forms() const
+ {
+ return pfs_;
+ }
+ /**
+ * Gets the associated plural form.
+ * @param value the duration representation
+ * @return the plural form associated to the @c value parameter. In English there are 2 plural forms
+ * 0 singular (-1 or 1)
+ * 1 plural for all others
        */
       virtual std::size_t do_get_plural_form(int_least64_t value) const
       {
         return (value == -1 || value == 1) ? 0 : 1;
       }
 
-
- string_type do_get_unit(duration_style_type style, ratio<1> , std::size_t pf) const
+ /**
+ * @param style the duration style.
+ * @param period the period associated to the duration seconds.
+ * @param pf the requested plural form.
+ * @return if style is symbol returns "s", otherwise if pf is 0 return "second", if pf is 1 "seconds"
+ */
+ virtual string_type do_get_unit(duration_style_type style, ratio<1> , std::size_t pf) const
       {
         static const CharT t[] =
         { 's' };
@@ -669,6 +608,12 @@
         throw "exception";
       }
 
+ /**
+ * @param style the duration style.
+ * @param period the period associated to the duration minutes.
+ * @param pf the requested plural form.
+ * @return if style is symbol returns "min", otherwise if pf is 0 return "minute", if pf is 1 "minutes"
+ */
       virtual string_type do_get_unit(duration_style_type style, ratio<60> , std::size_t pf) const
       {
         static const CharT t[] =
@@ -689,6 +634,12 @@
         throw "exception";
       }
 
+ /**
+ * @param style the duration style.
+ * @param period the period associated to the duration hours.
+ * @param pf the requested plural form.
+ * @return if style is symbol returns "h", otherwise if pf is 0 return "hour", if pf is 1 "hours"
+ */
       virtual string_type do_get_unit(duration_style_type style, ratio<3600> , std::size_t pf) const
       {
         static const CharT t[] =
@@ -707,14 +658,32 @@
         // assert
         throw "exception";
       }
+ /**
+ * @param style the duration style.
+ * @param u the period tag atto.
+ * @param pf the requested plural form.
+ * @return the concatenation of the prefix associated to @c period + the one associated to seconds.
+ */
       virtual string_type do_get_unit(duration_style_type style, atto u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_unit(style, ratio<1> (), pf);
       }
+ /**
+ * @param style the duration style.
+ * @param u the period tag femto.
+ * @param pf the requested plural form.
+ * @return the concatenation of the prefix associated to period @c u + the one associated to seconds.
+ */
       virtual string_type do_get_unit(duration_style_type style, femto u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_unit(style, ratio<1> (), pf);
       }
+ /**
+ * @param style the duration style.
+ * @param u the period tag femto.
+ * @param pf the requested plural form.
+ * @return the concatenation of the prefix associated to period @c u + the one associated to seconds.
+ */
       virtual string_type do_get_unit(duration_style_type style, pico u, std::size_t pf) const
       {
         return do_get_ratio_prefix(style, u) + do_get_unit(style, ratio<1> (), pf);
@@ -774,6 +743,11 @@
 
     protected:
 
+ /**
+ * @param style the duration style.
+ * @param u the period tag atto.
+ * @return depending on the value of @c style return the ratio_string symbol or prefix.
+ */
       virtual string_type do_get_ratio_prefix(duration_style_type style, atto) const
       {
         if (style == duration_style::symbol) return ratio_string<atto, CharT>::symbol();
@@ -855,28 +829,29 @@
         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_unit(duration_style_type style,
- std::size_t pf) const
- {
- return do_get_unit(style, Period(), pf);
- }
+// /**
+// *
+// * @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_unit(duration_style_type style,
+// std::size_t pf) const
+// {
+// return do_get_unit(style, Period(), pf);
+// }
 
- private:
+ protected:
       template <typename Period>
       string_type* fill_units(string_type* it, Period) const
       {
- for (std::size_t pf = 0; pf < pfs_; ++pf)
+ std::size_t pfs = do_get_plural_forms();
+ for (std::size_t pf = 0; pf < pfs; ++pf)
         {
- *it++ = get_unit<Period> (duration_style::prefix, pf);
+ *it++ = do_get_unit(duration_style::prefix, Period(), pf);
         }
- *it++ = get_unit<Period> (duration_style::symbol, 0);
+ *it++ = do_get_unit(duration_style::symbol, Period(), 0);
         return it;
       }
 

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-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -136,7 +136,7 @@
       {
 
         Duration d;
- bool duration_found = false, epoch_found = false, loc_found = false;
+ bool duration_found = false, epoch_found = false;
 
         const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
         err = std::ios_base::goodbit;
@@ -160,7 +160,7 @@
             {
             case 'd':
             {
- if (duration_found || loc_found)
+ if (duration_found)
               {
                 err |= std::ios_base::failbit;
                 return s;
@@ -176,7 +176,7 @@
             }
             case 'e':
             {
- if (epoch_found || loc_found)
+ if (epoch_found)
               {
                 err |= std::ios_base::failbit;
                 return s;

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp (original)
+++ trunk/boost/chrono/io/time_point_io.hpp 2011-11-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -438,9 +438,9 @@
                 std::ios::fmtflags flgs = os.flags();
                 std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
                 os.setf(std::ios::fixed, std::ios::floatfield);
- std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< " " << d.count() << std::endl;
                 os << d.count();
- std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
+ std::cerr << __FILE__ << "[" << __LINE__ << "]"<< " " << d.count() << std::endl;
                 os.flags(flgs);
                 std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl;
                 if (tz == timezone::local)

Modified: trunk/boost/chrono/io/utility/to_string.hpp
==============================================================================
--- trunk/boost/chrono/io/utility/to_string.hpp (original)
+++ trunk/boost/chrono/io/utility/to_string.hpp 2011-11-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -33,11 +33,11 @@
     }
 #if BOOST_CHRONO_HAS_UNICODE_SUPPORT
     template <typename T>
- std::wstring to_u16string(T const&v) {
+ std::basic_string<char16_t> to_u16string(T const&v) {
       return to_basic_string<char16_t>(v);
     }
     template <typename T>
- std::wstring to_u32string(T const&v) {
+ std::basic_string<char32_t> to_u32string(T const&v) {
       return to_basic_string<char32_t>(v);
     }
 #endif

Modified: trunk/libs/chrono/example/french.cpp
==============================================================================
--- trunk/libs/chrono/example/french.cpp (original)
+++ trunk/libs/chrono/example/french.cpp 2011-11-21 17:24:41 EST (Mon, 21 Nov 2011)
@@ -34,7 +34,7 @@
       }
     protected:
 
- using duration_units_default<CharT>::do_get_plural_form;
+ using duration_units_default<CharT>::do_get_unit;
       std::size_t do_get_plural_form(boost::int_least64_t value) const
       {
         return (value == -1 || value == 0 || value == 1) ? 0 : 1;


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