Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75455 - trunk/boost/chrono/io
From: vicente.botet_at_[hidden]
Date: 2011-11-12 09:01:39


Author: viboes
Date: 2011-11-12 09:01:38 EST (Sat, 12 Nov 2011)
New Revision: 75455
URL: http://svn.boost.org/trac/boost/changeset/75455

Log:
Chrono: Don't imbue facets if not present on the ios. Use a default instead
Text files modified:
   trunk/boost/chrono/io/duration_get.hpp | 311 ++++++++++++++++++++++-----------------
   trunk/boost/chrono/io/duration_io.hpp | 83 +++++----
   trunk/boost/chrono/io/duration_put.hpp | 116 ++++++++++----
   trunk/boost/chrono/io/time_point_get.hpp | 243 +++++++++++++++++++------------
   trunk/boost/chrono/io/time_point_io.hpp | 194 +++++++++++-------------
   trunk/boost/chrono/io/time_point_put.hpp | 198 +++++++++++++++---------
   6 files changed, 666 insertions(+), 479 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-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -46,12 +46,12 @@
       };
 
       template <typename intermediate_type>
- typename enable_if<is_integral<intermediate_type>, bool>::type
- reduce(intermediate_type& r, unsigned long long& den, std::ios_base::iostate& err)
+ typename enable_if<is_integral<intermediate_type> , bool>::type reduce(intermediate_type& r,
+ unsigned long long& den, std::ios_base::iostate& err)
       {
         typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t;
 
- // Reduce r * num / den
+ // Reduce r * num / den
         common_type_t t = math::gcd<common_type_t>(common_type_t(r), common_type_t(den));
         r /= t;
         den /= t;
@@ -64,8 +64,8 @@
         return true;
       }
       template <typename intermediate_type>
- typename disable_if<is_integral<intermediate_type>, bool>::type
- reduce(intermediate_type& , unsigned long long& , std::ios_base::iostate& )
+ typename disable_if<is_integral<intermediate_type> , bool>::type reduce(intermediate_type&, unsigned long long&,
+ std::ios_base::iostate&)
       {
         return true;
       }
@@ -164,99 +164,120 @@
       iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
           duration<Rep, Period> &d, const char_type *pattern, const char_type *pat_end) const
       {
+ if (std::has_facet<duration_units<CharT> >(ios.getloc()))
+ {
+ duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(ios.getloc());
+ return get(facet, s, end, ios, err, d, pattern, pat_end);
+ }
+ else
+ {
+ duration_units_default<CharT> facet;
+ return get(facet, s, end, ios, err, d, pattern, pat_end);
+ }
+ }
+
+ template <typename Rep, typename Period>
+ iter_type get(duration_units<CharT> const&facet, iter_type s, iter_type end, std::ios_base& ios,
+ std::ios_base::iostate& err, duration<Rep, Period> &d, const char_type *pattern, const char_type *pat_end) const
+ {
 
         typedef typename detail::duration_io_intermediate<Rep>::type intermediate_type;
         intermediate_type r;
         detail::rt_ratio rt;
- bool value_found=false, unit_found=false, loc_found=false;
+ 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;
         while (pattern != pat_end && err == std::ios_base::goodbit)
         {
- if (s == end)
+ if (s == end)
+ {
+ err |= std::ios_base::eofbit;
+ break;
+ }
+ if (ct.narrow(*pattern, 0) == '%')
+ {
+ if (++pattern == pat_end)
             {
- err |= std::ios_base::eofbit;
- break;
+ err |= std::ios_base::failbit;
+ return s;
             }
- if (ct.narrow(*pattern, 0) == '%')
+ char cmd = ct.narrow(*pattern, 0);
+ switch (cmd)
             {
- if (++pattern == pat_end)
- {
- err |= std::ios_base::failbit;
- return s;
- }
- char cmd = ct.narrow(*pattern, 0);
- switch (cmd)
- {
- case 'v':
- {
- if (value_found) {
- err |= std::ios_base::failbit;
- return s;
- }
- if (value_found) {
- err |= std::ios_base::failbit;
- return s;
- }
- value_found=true;
- s=get_value(s, end, ios, err, r);
- if ( err & (std::ios_base::badbit |std::ios_base::failbit) )
- {
- return s;
- }
- break;
- }
- case 'u':
- {
- if (unit_found) {
- err |= std::ios_base::failbit;
- return s;
- }
- unit_found=true;
- s = get_unit(s, end, ios, err, rt);
- if ( err & (std::ios_base::badbit |std::ios_base::failbit) )
- {
- return s;
- }
- 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;
- }
-
- ++pattern;
- }
- else if (ct.is(std::ctype_base::space, *pattern))
+ case 'v':
             {
- for (++pattern; pattern != pat_end && ct.is(std::ctype_base::space, *pattern); ++pattern)
- ;
- for ( ; s != end && ct.is(std::ctype_base::space, *s); ++s)
- ;
+ if (value_found)
+ {
+ err |= std::ios_base::failbit;
+ return s;
+ }
+ if (value_found)
+ {
+ err |= std::ios_base::failbit;
+ return s;
+ }
+ value_found = true;
+ s = get_value(s, end, ios, err, r);
+ if (err & (std::ios_base::badbit | std::ios_base::failbit))
+ {
+ return s;
+ }
+ break;
             }
- else if (ct.toupper(*s) == ct.toupper(*pattern))
+ case 'u':
             {
- ++s;
- ++pattern;
- }
- else {
+ if (unit_found)
+ {
                 err |= std::ios_base::failbit;
+ return s;
+ }
+ unit_found = true;
+ s = get_unit(facet, s, end, ios, err, rt);
+ if (err & (std::ios_base::badbit | std::ios_base::failbit))
+ {
+ return s;
+ }
+ 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;
+ }
+
+ ++pattern;
+ }
+ else if (ct.is(std::ctype_base::space, *pattern))
+ {
+ for (++pattern; pattern != pat_end && ct.is(std::ctype_base::space, *pattern); ++pattern)
+ ;
+ for (; s != end && ct.is(std::ctype_base::space, *s); ++s)
+ ;
+ }
+ else if (ct.toupper(*s) == ct.toupper(*pattern))
+ {
+ ++s;
+ ++pattern;
+ }
+ else
+ {
+ err |= std::ios_base::failbit;
+ }
 
         }
 
@@ -271,8 +292,8 @@
         den /= gcd_d1_d2;
         unsigned long long n2 = Period::num / gcd_n1_n2;
         unsigned long long d2 = Period::den / gcd_d1_d2;
- if (num > (std::numeric_limits<unsigned long long>::max)() / d2 || den > (std::numeric_limits<
- unsigned long long>::max)() / n2)
+ if (num > (std::numeric_limits<unsigned long long>::max)() / d2 || den
+ > (std::numeric_limits<unsigned long long>::max)() / n2)
         {
           // (num/den) / Period overflows
           err |= std::ios_base::failbit;
@@ -284,11 +305,10 @@
         typedef typename common_type<intermediate_type, unsigned long long>::type common_type_t;
 
         // num / den is now factor to multiply by r
- if (!detail::reduce(r, den, err))
- return s;
+ if (!detail::reduce(r, den, err)) return s;
 
         //if (r > ( (duration_values<common_type_t>::max)() / num))
- if (chrono::detail::gt(r,((duration_values<common_type_t>::max)() / num)))
+ if (chrono::detail::gt(r, ( (duration_values<common_type_t>::max)() / num)))
         //if (common_type_t(r) > ( (duration_values<common_type_t>::max)() / num))
         {
           // Conversion to Period overflowed
@@ -321,8 +341,7 @@
        * @param ios a reference to a ios_base
        * @param err the ios_base state
        * @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
+ * Stores the duration pattern from the @c duration_unit facet in let say @c str. Last as if
        * @code
        * return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
        * @codeend
@@ -332,8 +351,19 @@
       iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
           duration<Rep, Period> & d) const
       {
- std::basic_string < CharT > str = duration_units<CharT>::imbue_if_has_not(ios).get_pattern();
- return get(s, end, ios, err, d, str.data(), str.data() + str.size());
+ if (std::has_facet<duration_units<CharT> >(ios.getloc()))
+ {
+ duration_units<CharT> const&facet = std::use_facet<duration_units<CharT> >(ios.getloc());
+ std::basic_string<CharT> str = facet.get_pattern();
+ return get(facet, s, end, ios, err, d, str.data(), str.data() + str.size());
+ }
+ else
+ {
+ duration_units_default<CharT> facet;
+ std::basic_string<CharT> str = facet.get_pattern();
+ return get(facet, s, end, ios, err, d, str.data(), str.data() + str.size());
+ }
+
       }
 
       /**
@@ -351,8 +381,6 @@
         return std::use_facet<std::num_get<CharT, iter_type> >(ios.getloc()).get(s, end, ios, err, r);
       }
 
-
-
       /**
        *
        * @param s start input stream iterator
@@ -362,22 +390,34 @@
        * @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, detail::rt_ratio &rt) const
+ {
+ if (std::has_facet<duration_units<CharT> >(is.getloc()))
+ {
+ return get_unit(std::use_facet<duration_units<CharT> >(is.getloc()), i, e, is, err, rt);
+ }
+ else
+ {
+ duration_units_default<CharT> facet;
+ return get_unit(facet, i, e, is, err, rt);
+ }
+ }
+
+ 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
       {
- duration_units<CharT> const &facet = duration_units<CharT>::imbue_if_has_not(is);
 
         if (*i == '[')
         {
           // parse [N/D]s 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)
+ 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)
           {
             return i;
           }
 
- if (i==e)
+ if (i == e)
           {
             err |= std::ios_base::failbit;
             return i;
@@ -388,12 +428,12 @@
             err |= std::ios_base::failbit;
             return i;
           }
- i=std::use_facet<std::num_get<CharT, iter_type> >(is.getloc()).get(i, e, is, err, rt.den);
- if ((err & std::ios_base::failbit) != 0)
+ i = std::use_facet<std::num_get<CharT, iter_type> >(is.getloc()).get(i, e, is, err, rt.den);
+ if ( (err & std::ios_base::failbit) != 0)
           {
             return i;
           }
- if (i==e)
+ if (i == e)
           {
             err |= std::ios_base::failbit;
             return i;
@@ -404,22 +444,19 @@
             return i;
           }
           ++i;
- if (i==e)
+ if (i == e)
           {
             err |= std::ios_base::failbit;
             return i;
           }
           const string_type units[] =
- {
- facet.template get_plural_form<ratio<1> >(duration_style::prefix, 1),
- facet.template get_plural_form<ratio<1> >(duration_style::prefix, 0),
- facet.template get_plural_form<ratio<1> >(duration_style::symbol, 0)
- };
+ { facet.template get_plural_form<ratio<1> > (duration_style::prefix, 1), facet.template get_plural_form<
+ ratio<1> > (duration_style::prefix, 0), facet.template get_plural_form<ratio<1> > (
+ duration_style::symbol, 0) };
           // FIXME is this necessary?????
           err = std::ios_base::goodbit;
- const string_type* k = chrono_detail::scan_keyword(i, e, units,
- units + sizeof (units) / sizeof (units[0]),
- //~ std::use_facet<std::ctype<CharT> >(loc),
+ const string_type* k = chrono_detail::scan_keyword(i, e, units, units + sizeof (units) / sizeof (units[0]),
+ //~ std::use_facet<std::ctype<CharT> >(loc),
               err);
           switch ( (k - units) / 3)
           {
@@ -432,7 +469,7 @@
         }
         else
         {
- return do_get_prefix_unit(i, e, is, err, rt);
+ return do_get_prefix_unit(facet, i, e, is, err, rt);
         }
 
         return i;
@@ -452,6 +489,20 @@
 
     protected:
 
+ virtual iter_type do_get_prefix_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
+ detail::rt_ratio &rt) const
+ {
+ if (std::has_facet<duration_units<CharT> >(is.getloc()))
+ {
+ return do_get_prefix_unit(std::use_facet<duration_units<CharT> >(is.getloc()), i, e, is, err, rt);
+ }
+ else
+ {
+ duration_units_default<CharT> facet;
+ return do_get_prefix_unit(facet, i, e, is, err, rt);
+ }
+ }
+
       /**
        * Extracts the run-time ratio associated to the duration when it is given in prefix form.
        *
@@ -464,18 +515,14 @@
        * @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.
        */
- virtual iter_type do_get_prefix_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
- detail::rt_ratio &rt) const
+ 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::cerr << __FILE__ << ":" << __LINE__ << " " << std::endl;
- duration_units<CharT> const &facet = duration_units<CharT>::imbue_if_has_not(is);
-
-
         // parse SI name, short or long
- std::size_t pfs = facet.get_plural_forms()+1;
+ std::size_t pfs = facet.get_plural_forms() + 1;
 
         // scoped_ptr ???
- string_type* units= new string_type[19*pfs]();
+ string_type* units = new string_type[19 * pfs]();
         string_type* it = units;
         it = facet.fill_units(it, atto());
         it = facet.fill_units(it, femto());
@@ -493,23 +540,22 @@
         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>());
+ 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;
+ string_type* units_end = units + 19 * pfs;
 
         err = std::ios_base::goodbit;
         std::cerr << __FILE__ << ":" << __LINE__ << " " << std::endl;
- const string_type* k = chrono_detail::scan_keyword(i, e, units,
- units_end,
- //~ std::use_facet<std::ctype<CharT> >(loc),
+ const string_type* k = chrono_detail::scan_keyword(i, e, units, units_end,
+ //~ std::use_facet<std::ctype<CharT> >(loc),
             err);
         std::cerr << __FILE__ << ":" << __LINE__ << " err" << err << std::endl;
 
- std::size_t index = (k - units) / pfs;
- delete []units;
- switch ( index )
+ std::size_t index = (k - units) / pfs;
+ delete[] units;
+ switch (index)
         {
         case 0:
           rt = detail::rt_ratio(atto());
@@ -560,13 +606,13 @@
           rt = detail::rt_ratio(exa());
           break;
         case 16:
- rt = detail::rt_ratio(ratio<1>());
+ rt = detail::rt_ratio(ratio<1> ());
           break;
         case 17:
- rt = detail::rt_ratio(ratio<60>());
+ rt = detail::rt_ratio(ratio<60> ());
           break;
         case 18:
- rt = detail::rt_ratio(ratio<3600>());
+ rt = detail::rt_ratio(ratio<3600> ());
           break;
         default:
           err = std::ios_base::failbit;
@@ -586,7 +632,6 @@
     template <class CharT, class InputIterator>
     std::locale::id duration_get<CharT, InputIterator>::id;
 
-
   } // chrono
 }
 // boost

Modified: trunk/boost/chrono/io/duration_io.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_io.hpp (original)
+++ trunk/boost/chrono/io/duration_io.hpp 2011-11-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -31,7 +31,7 @@
      * duration parameterized manipulator.
      */
 
- class duration_fmt : public manip<duration_fmt>
+ class duration_fmt: public manip<duration_fmt>
     {
       duration_style::type style_;
     public:
@@ -39,7 +39,7 @@
       /**
        * explicit manipulator constructor from a @c duration_style
        */
- explicit duration_fmt(duration_style::type style) BOOST_NOEXCEPT
+ explicit duration_fmt(duration_style::type style)BOOST_NOEXCEPT
       : style_(style)
       {}
 
@@ -49,6 +49,7 @@
       template <typename out_stream>
       void operator()(out_stream &ios) const
       //void operator()(std::ios_base &ios) const
+
       {
         set_duration_style(ios, style_);
       }
@@ -122,48 +123,51 @@
     std::basic_ostream<CharT, Traits>&
     operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d)
     {
- typedef std::basic_string<CharT, Traits> string_type;
- bool failed = false;
+ typedef std::basic_string<CharT, Traits> string_type;
+ bool failed = false;
+ try
+ {
+ std::ios_base::iostate err = std::ios_base::goodbit;
         try
         {
- std::ios_base::iostate err = std::ios_base::goodbit;
- try
+ typename std::basic_ostream<CharT, Traits>::sentry opfx(os);
+ if (opfx)
           {
- typename std::basic_ostream<CharT, Traits>::sentry opfx(os);
- if (opfx)
+ if (!std::has_facet<duration_put<CharT> >(os.getloc()))
             {
- if (!std::has_facet<duration_put<CharT> >(os.getloc()))
- {
- os.imbue(std::locale(os.getloc(), new duration_put<CharT> ()));
- }
- if (std::use_facet<duration_put<CharT> >(os.getloc()) .put(os, os, d) .failed())
+ if (duration_put<CharT> ().put(os, os, d) .failed())
               {
                 err = std::ios_base::badbit;
               }
- os.width(0);
- }
- }
- catch (...)
- {
- bool flag = false;
- try
- {
- os.setstate(std::ios_base::failbit);
             }
- catch (std::ios_base::failure )
+ else if (std::use_facet<duration_put<CharT> >(os.getloc()) .put(os, os, d) .failed())
             {
- flag = true;
+ err = std::ios_base::badbit;
             }
- if (flag) throw;
+ os.width(0);
           }
- if (err) os.setstate(err);
- return os;
         }
         catch (...)
         {
- failed = true;
+ bool flag = false;
+ try
+ {
+ os.setstate(std::ios_base::failbit);
+ }
+ catch (std::ios_base::failure )
+ {
+ flag = true;
+ }
+ if (flag) throw;
         }
- if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
+ if (err) os.setstate(err);
+ return os;
+ }
+ catch (...)
+ {
+ failed = true;
+ }
+ if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
       return os;
     }
 
@@ -182,30 +186,33 @@
       try
       {
         typename std::basic_istream<CharT, Traits>::sentry ipfx(is);
- if(ipfx)
+ if (ipfx)
         {
           if (!std::has_facet<duration_get<CharT> >(is.getloc()))
           {
- is.imbue(std::locale(is.getloc(), new duration_get<CharT>()));
+ duration_get<CharT> ().get(is, std::istreambuf_iterator<CharT, Traits>(), is, err, d);
+ }
+ else
+ {
+ std::use_facet<duration_get<CharT> >(is.getloc()) .get(is, std::istreambuf_iterator<CharT, Traits>(), is,
+ err, d);
           }
- std::use_facet<duration_get<CharT> >(is.getloc())
- .get(is, std::istreambuf_iterator<CharT,Traits>() ,is, err, d);
         }
       }
- catch(...)
+ catch (...)
       {
         bool flag = false;
         try
         {
           is.setstate(std::ios_base::failbit);
         }
- catch( std::ios_base::failure )
+ catch (std::ios_base::failure )
         {
- flag= true;
+ flag = true;
         }
- if ( flag ) throw;
+ if (flag) throw;
       }
- if ( err ) is.setstate(err);
+ if (err) is.setstate(err);
       return is;
     }
 

Modified: trunk/boost/chrono/io/duration_put.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_put.hpp (original)
+++ trunk/boost/chrono/io/duration_put.hpp 2011-11-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -91,45 +91,61 @@
       iter_type put(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d, const CharT* pattern,
           const CharT* pat_end) const
       {
- duration_units<CharT,OutputIterator> const& units_facet = duration_units<CharT,OutputIterator>::imbue_if_has_not(ios);
+ if (std::has_facet<duration_units<CharT, OutputIterator> >(ios.getloc()))
+ {
+ duration_units<CharT, OutputIterator> const&facet = std::use_facet<duration_units<CharT, OutputIterator> >(
+ ios.getloc());
+ return put(facet, s, ios, d, pattern, pat_end);
+ }
+ else
+ {
+ duration_units_default<CharT, OutputIterator> facet;
+ return put(facet, s, ios, d, pattern, pat_end);
+ }
+ }
+
+ template <typename Rep, typename Period>
+ iter_type put(duration_units<CharT, OutputIterator> const& units_facet, iter_type s, std::ios_base& ios,
+ duration<Rep, Period> const& d, const CharT* pattern, const CharT* pat_end) const
+ {
 
         const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
         for (; pattern != pat_end; ++pattern)
         {
- if (ct.narrow(*pattern, 0) == '%')
+ if (ct.narrow(*pattern, 0) == '%')
+ {
+ if (++pattern == pat_end)
+ {
+ *s++ = pattern[-1];
+ break;
+ }
+ char fmt = ct.narrow(*pattern, 0);
+ switch (fmt)
+ {
+ case 'v':
+ {
+ s = put_value(s, ios, d);
+ break;
+ }
+ case 'u':
             {
- if (++pattern == pat_end)
- {
- *s++ = pattern[-1];
- break;
- }
- char fmt = ct.narrow(*pattern, 0);
- switch (fmt)
- {
- case 'v':
- {
- s = put_value(s, ios, d);
- break;
- }
- case 'u':
- {
- s = put_unit(s, ios, d);
- break;
- }
- case 'x':
- {
- std::basic_string<CharT> pat = units_facet.get_pattern();
- pattern = pat.data();
- pat_end = pattern + pat.size();
- break;
- }
- default:
- BOOST_ASSERT(false && "Boost::Chrono internal error.");
- break;
- }
+ s = put_unit(units_facet, s, ios, d);
+ break;
             }
- else
- *s++ = *pattern;
+ // case 'x':
+ // {
+ // std::basic_string<CharT> pat = units_facet.get_pattern();
+ // pattern = pat.data();
+ // pat_end = pattern + pat.size();
+ // break;
+ // }
+ default:
+ BOOST_ASSERT(false && "Boost::Chrono internal error.");
+ break;
+ }
+ }
+ else
+ *s++ = *pattern;
         }
         return s;
       }
@@ -149,8 +165,19 @@
       template <typename Rep, typename Period>
       iter_type put(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d) const
       {
- std::basic_string<CharT> str = duration_units<CharT,OutputIterator>::imbue_if_has_not(ios).get_pattern();
- return put(s, ios, d, str.data(), str.data() + str.size());
+ if (std::has_facet<duration_units<CharT, OutputIterator> >(ios.getloc()))
+ {
+ duration_units<CharT, OutputIterator> const&facet = std::use_facet<duration_units<CharT, OutputIterator> >(
+ ios.getloc());
+ std::basic_string<CharT> str = facet.get_pattern();
+ return put(facet, s, ios, d, str.data(), str.data() + str.size());
+ }
+ else
+ {
+ duration_units_default<CharT, OutputIterator> facet;
+ std::basic_string<CharT> str = facet.get_pattern();
+ return put(facet, s, ios, d, str.data(), str.data() + str.size());
+ }
       }
 
       /**
@@ -181,7 +208,24 @@
       template <typename Rep, typename Period>
       iter_type put_unit(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d) const
       {
- return duration_units<CharT,OutputIterator>::imbue_if_has_not(ios).put(s, ios, d);
+ if (std::has_facet<duration_units<CharT, OutputIterator> >(ios.getloc()))
+ {
+ duration_units<CharT, OutputIterator> const&facet = std::use_facet<duration_units<CharT, OutputIterator> >(
+ ios.getloc());
+ return put_unit(facet, s, ios, d);
+ }
+ else
+ {
+ duration_units_default<CharT, OutputIterator> facet;
+ return put_unit(facet, s, ios, d);
+ }
+ }
+
+ template <typename Rep, typename Period>
+ iter_type put_unit(duration_units<CharT, OutputIterator> const& facet, iter_type s, std::ios_base& ios,
+ duration<Rep, Period> const& d) const
+ {
+ return facet.put(s, ios, d);
       }
 
       /**

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-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -112,106 +112,126 @@
        *
        * Returns: s
        */
+
       template <class Clock, class Duration>
- iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
+ iter_type get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
           time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const
       {
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
+ if (std::has_facet<time_point_units<CharT> >(is.getloc()))
+ {
+ time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
+ return get(facet, i, e, is, err, tp, pattern, pat_end);
+ }
+ else
+ {
+ time_point_units_default<CharT> facet;
+ return get(facet, i, e, is, err, tp, pattern, pat_end);
+ }
+ }
+
+ template <class Clock, class Duration>
+ iter_type get(time_point_units<CharT> const &facet, iter_type s, iter_type end, std::ios_base& ios,
+ std::ios_base::iostate& err, time_point<Clock, Duration> &tp, const char_type *pattern,
+ const char_type *pat_end) const
+ {
 
         Duration d;
- bool duration_found=false, epoch_found=false, loc_found=false;
+ bool duration_found = false, epoch_found = false, loc_found = false;
 
         const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
         err = std::ios_base::goodbit;
         while (pattern != pat_end && err == std::ios_base::goodbit)
         {
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
- if (s == end)
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
+ if (s == end)
+ {
+ err |= std::ios_base::eofbit;
+ break;
+ }
+ if (ct.narrow(*pattern, 0) == '%')
+ {
+ if (++pattern == pat_end)
             {
- err |= std::ios_base::eofbit;
- break;
+ err |= std::ios_base::failbit;
+ return s;
             }
- if (ct.narrow(*pattern, 0) == '%')
+ char cmd = ct.narrow(*pattern, 0);
+ switch (cmd)
             {
- if (++pattern == pat_end)
- {
- err |= std::ios_base::failbit;
- return s;
- }
- char cmd = ct.narrow(*pattern, 0);
- switch (cmd)
- {
- case 'd':
- {
- if (duration_found || loc_found) {
- err |= std::ios_base::failbit;
- return s;
- }
- duration_found=true;
- s = get_duration(s, end, ios, err, d);
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
- if ( err & (std::ios_base::badbit |std::ios_base::failbit) )
- {
- return s;
- }
- break;
- }
- case 'e':
- {
- if (epoch_found || loc_found) {
- err |= std::ios_base::failbit;
- return s;
- }
- epoch_found=true;
- s = get_epoch<Clock>(s, end, ios, err);
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
- if ( err & (std::ios_base::badbit |std::ios_base::failbit) )
- {
- return s;
- }
- 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;
- }
-
- ++pattern;
- }
- else if (ct.is(std::ctype_base::space, *pattern))
+ case 'd':
             {
- for (++pattern; pattern != pat_end && ct.is(std::ctype_base::space, *pattern); ++pattern)
- ;
- for ( ; s != end && ct.is(std::ctype_base::space, *s); ++s)
- ;
+ if (duration_found || loc_found)
+ {
+ err |= std::ios_base::failbit;
+ return s;
+ }
+ duration_found = true;
+ s = get_duration(s, end, ios, err, d);
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
+ if (err & (std::ios_base::badbit | std::ios_base::failbit))
+ {
+ return s;
+ }
+ break;
             }
- else if (ct.toupper(*s) == ct.toupper(*pattern))
+ case 'e':
             {
- ++s;
- ++pattern;
- }
- else {
+ if (epoch_found || loc_found)
+ {
                 err |= std::ios_base::failbit;
+ return s;
+ }
+ epoch_found = true;
+ s = get_epoch<Clock> (facet, s, end, ios, err);
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
+ if (err & (std::ios_base::badbit | std::ios_base::failbit))
+ {
+ return s;
+ }
+ 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;
             }
+
+ ++pattern;
+ }
+ else if (ct.is(std::ctype_base::space, *pattern))
+ {
+ for (++pattern; pattern != pat_end && ct.is(std::ctype_base::space, *pattern); ++pattern)
+ ;
+ for (; s != end && ct.is(std::ctype_base::space, *s); ++s)
+ ;
+ }
+ else if (ct.toupper(*s) == ct.toupper(*pattern))
+ {
+ ++s;
+ ++pattern;
+ }
+ else
+ {
+ err |= std::ios_base::failbit;
+ }
         }
 
         // Success! Store it.
- tp = time_point<Clock, Duration>(d);
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
+ tp = time_point<Clock, Duration> (d);
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
 
         return s;
       }
@@ -229,11 +249,21 @@
        * @Returns An iterator pointing just beyond the last character that can be determined to be part of a valid name
        */
       template <class Clock, class Duration>
- iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
+ iter_type get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
           time_point<Clock, Duration> &tp) const
       {
- std::basic_string < CharT > str = time_point_units<CharT>::imbue_if_has_not(ios).get_pattern();
- return get(s, end, ios, err, tp, str.data(), str.data() + str.size());
+ if (std::has_facet<time_point_units<CharT> >(is.getloc()))
+ {
+ time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
+ std::basic_string<CharT> str = facet.get_pattern();
+ return get(facet, i, e, is, err, tp, str.data(), str.data() + str.size());
+ }
+ else
+ {
+ time_point_units_default<CharT> facet;
+ std::basic_string<CharT> str = facet.get_pattern();
+ return get(facet, i, e, is, err, tp, str.data(), str.data() + str.size());
+ }
       }
 
       /**
@@ -244,14 +274,26 @@
        * @Returns An iterator pointing just beyond the last character that can be determined to be part of a valid name
        */
       template <typename Rep, typename Period>
- iter_type get_duration(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err, duration<Rep, Period>& d) const
+ iter_type get_duration(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
+ duration<Rep, Period>& d) const
       {
- if (!std::has_facet<duration_get<CharT> >(ios.getloc()))
+ if (std::has_facet<duration_get<CharT> >(is.getloc()))
+ {
+ duration_get<CharT> const &facet = std::use_facet<duration_get<CharT> >(is.getloc());
+ return get_duration(facet, i, e, is, err, d);
+ }
+ else
         {
- ios.imbue(std::locale(ios.getloc(), new duration_get<CharT>()));
+ duration_get<CharT> facet;
+ return get_duration(facet, i, e, is, err, d);
         }
- return std::use_facet<duration_get<CharT> >(ios.getloc())
- .get(s, end, ios, err, d);
+ }
+
+ template <typename Rep, typename Period>
+ iter_type get_duration(duration_get<CharT> const& facet, iter_type s, iter_type end, std::ios_base& ios,
+ std::ios_base::iostate& err, duration<Rep, Period>& d) const
+ {
+ return facet.get(s, end, ios, err, d);
       }
 
       /**
@@ -266,21 +308,34 @@
       template <class Clock>
       iter_type get_epoch(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err) const
       {
- time_point_units<CharT> const &facet = time_point_units<CharT>::imbue_if_has_not(is);
+ if (std::has_facet<time_point_units<CharT> >(is.getloc()))
+ {
+ time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
+ return get_epoch(facet, i, e, is, err);
+ }
+ else
+ {
+ time_point_units_default<CharT> facet;
+ return get_epoch(facet, i, e, is, err);
+ }
+ }
 
- const std::basic_string<CharT> units = facet.get_epoch<Clock>();
+ template <class Clock>
+ iter_type get_epoch(time_point_units<CharT> const &facet, iter_type i, iter_type e, std::ios_base&,
+ std::ios_base::iostate& err) const
+ {
+ const std::basic_string<CharT> units = facet.get_epoch<Clock> ();
         err = std::ios_base::goodbit;
- std::ptrdiff_t k =
- chrono_detail::scan_keyword(i, e, &units, &units + 1,
- //~ std::use_facet<std::ctype<CharT> >(ios.getloc()),
+ std::ptrdiff_t k = chrono_detail::scan_keyword(i, e, &units, &units + 1,
+ //~ std::use_facet<std::ctype<CharT> >(ios.getloc()),
             err) - &units;
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
         if (k == 1)
         {
           err |= std::ios_base::failbit;
           return i;
         }
- std::cerr << __FILE__ <<":"<< __LINE__ << " err "<< err << std::endl;
+ std::cerr << __FILE__ << ":" << __LINE__ << " err " << err << std::endl;
         return i;
       }
 

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-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -32,8 +32,8 @@
     namespace detail
     {
 
- template<class CharT>
- class time_manip : public manip<time_manip<CharT> >
+ template <class CharT>
+ class time_manip: public manip<time_manip<CharT> >
       {
         std::basic_string<CharT> fmt_;
         timezone_type tz_;
@@ -41,7 +41,8 @@
 
         time_manip(timezone_type tz, std::basic_string<CharT> fmt)
         // todo move semantics
- : fmt_(fmt), tz_(tz)
+ :
+ fmt_(fmt), tz_(tz)
         {
         }
 
@@ -51,19 +52,20 @@
         //template <typename out_stream>
         void operator()(std::ios_base &ios) const
         {
- set_time_fmt<CharT>(ios, fmt_);
+ set_time_fmt<CharT> (ios, fmt_);
           set_timezone(ios, tz_);
         }
       };
 
- class time_man : public manip<time_man>
+ class time_man: public manip<time_man>
       {
         timezone_type tz_;
       public:
 
         time_man(timezone_type tz)
         // todo move semantics
- : tz_(tz)
+ :
+ tz_(tz)
         {
         }
 
@@ -81,15 +83,14 @@
 
     }
 
- template<class CharT>
+ template <class CharT>
     inline detail::time_manip<CharT> time_fmt(timezone_type tz, const CharT* fmt)
     {
       return detail::time_manip<CharT>(tz, fmt);
     }
 
- template<class CharT>
- inline detail::time_manip<CharT> time_fmt(timezone_type tz, std::basic_string<
- CharT> fmt)
+ template <class CharT>
+ inline detail::time_manip<CharT> time_fmt(timezone_type tz, std::basic_string<CharT> fmt)
     {
       // todo move semantics
       return detail::time_manip<CharT>(tz, fmt);
@@ -105,7 +106,7 @@
      *
      * See Boost.IO i/o state savers for a motivating compression.
      */
- template<typename CharT = char, typename Traits = std::char_traits<CharT> >
+ template <typename CharT = char, typename Traits = std::char_traits<CharT> >
     struct time_fmt_io_saver
     {
 
@@ -161,7 +162,7 @@
      *
      * See Boost.IO i/o state savers for a motivating compression.
      */
- template<typename CharT = char, typename Traits = std::char_traits<CharT> >
+ template <typename CharT = char, typename Traits = std::char_traits<CharT> >
     struct timezone_io_saver
     {
 
@@ -212,91 +213,98 @@
       aspect_type a_save_;
     };
 
- template<class CharT, class Traits, class Clock, class Duration>
+ template <class CharT, class Traits, class Clock, class Duration>
     std::basic_ostream<CharT, Traits>&
- operator<<(std::basic_ostream<CharT, Traits>& os, const time_point<Clock,
- Duration>& tp)
+ operator<<(std::basic_ostream<CharT, Traits>& os, const time_point<Clock, Duration>& tp)
     {
 
- typedef std::basic_string<CharT, Traits> string_type;
- bool failed = false;
+ typedef std::basic_string<CharT, Traits> string_type;
+ bool failed = false;
+ try
+ {
+ std::ios_base::iostate err = std::ios_base::goodbit;
         try
         {
- std::ios_base::iostate err = std::ios_base::goodbit;
- try
+ typename std::basic_ostream<CharT, Traits>::sentry opfx(os);
+ if (opfx)
           {
- typename std::basic_ostream<CharT, Traits>::sentry opfx(os);
- if (opfx)
+ if (!std::has_facet<time_point_put<CharT> >(os.getloc()))
             {
- if (!std::has_facet<time_point_put<CharT> >(os.getloc()))
+ if (time_point_put<CharT> ().put(os, os, tp) .failed())
               {
- os.imbue(std::locale(os.getloc(), new time_point_put<CharT> ()));
+ err = std::ios_base::badbit;
               }
+ }
+ else
+ {
               if (std::use_facet<time_point_put<CharT> >(os.getloc()) .put(os, os, tp) .failed())
               {
                 err = std::ios_base::badbit;
               }
- os.width(0);
             }
+ os.width(0);
           }
- catch (...)
- {
- bool flag = false;
- try
- {
- os.setstate(std::ios_base::failbit);
- }
- catch (std::ios_base::failure )
- {
- flag = true;
- }
- if (flag) throw;
- }
- if (err) os.setstate(err);
- return os;
         }
         catch (...)
         {
- failed = true;
+ bool flag = false;
+ try
+ {
+ os.setstate(std::ios_base::failbit);
+ }
+ catch (std::ios_base::failure )
+ {
+ flag = true;
+ }
+ if (flag) throw;
         }
- if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
+ if (err) os.setstate(err);
         return os;
+ }
+ catch (...)
+ {
+ failed = true;
+ }
+ if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
+ return os;
     }
 
- template<class CharT, class Traits, class Clock, class Duration>
+ template <class CharT, class Traits, class Clock, class Duration>
     std::basic_istream<CharT, Traits>&
- operator>>(std::basic_istream<CharT, Traits>& is, time_point<Clock,
- Duration>& tp)
+ operator>>(std::basic_istream<CharT, Traits>& is, time_point<Clock, Duration>& tp)
     {
       std::ios_base::iostate err = std::ios_base::goodbit;
 
       try
       {
         typename std::basic_istream<CharT, Traits>::sentry ipfx(is);
- if(ipfx)
+ if (ipfx)
         {
           if (!std::has_facet<time_point_get<CharT> >(is.getloc()))
           {
- is.imbue(std::locale(is.getloc(), new time_point_get<CharT>()));
+ time_point_get<CharT> () .get(is, std::istreambuf_iterator<CharT, Traits>(), is, err, tp);
+ }
+ else
+ {
+ std::use_facet<time_point_get<CharT> >(is.getloc()) .get(is, std::istreambuf_iterator<CharT, Traits>(), is,
+ err, tp);
           }
- std::use_facet<time_point_get<CharT> >(is.getloc())
- .get(is, std::istreambuf_iterator<CharT,Traits>() ,is, err, tp);
         }
       }
- catch(...)
+ catch (...)
       {
         bool flag = false;
         try
         {
           is.setstate(std::ios_base::failbit);
         }
- catch( std::ios_base::failure )
+ catch (std::ios_base::failure )
         {
- flag= true;
+ flag = true;
         }
- if ( flag ) throw;
+ if (flag) throw;
       }
- if ( err ) is.setstate(err);
+ if (err) is.setstate(err);
       return is;
     }
 
@@ -363,10 +371,9 @@
 #endif
     } // detail
 
- template<class CharT, class Traits, class Duration>
+ template <class CharT, class Traits, class Duration>
     std::basic_ostream<CharT, Traits>&
- operator<<(std::basic_ostream<CharT, Traits>& os, const time_point<
- system_clock, Duration>& tp)
+ operator<<(std::basic_ostream<CharT, Traits>& os, const time_point<system_clock, Duration>& tp)
     {
       typename std::basic_ostream<CharT, Traits>::sentry ok(os);
       if (ok)
@@ -376,8 +383,7 @@
         {
           const CharT* pb = 0; //nullptr;
           const CharT* pe = pb;
- std::basic_string<CharT> fmt =
- get_time_fmt<CharT>(os);
+ std::basic_string<CharT> fmt = get_time_fmt<CharT> (os);
           pb = fmt.data();
           pe = pb + fmt.size();
 
@@ -393,8 +399,7 @@
             failed = true;
             tm =*tmp;
 #else
- if (localtime_r(&t, &tm) == 0)
- failed = true;
+ if (localtime_r(&t, &tm) == 0) failed = true;
 #endif
           }
           else
@@ -405,29 +410,24 @@
             failed = true;
             tm = *tmp;
 #else
- if (gmtime_r(&t, &tm) == 0)
- failed = true;
+ if (gmtime_r(&t, &tm) == 0) failed = true;
 #endif
 
           }
           if (!failed)
           {
- const std::time_put<CharT>& tpf = std::use_facet<std::time_put<
- CharT> >(loc);
+ const std::time_put<CharT>& tpf = std::use_facet<std::time_put<CharT> >(loc);
             if (pb == pe)
             {
- CharT
- pattern[] =
- { '%', 'Y', '-', '%', 'm', '-', '%', 'd', ' ', '%', 'H', ':', '%', 'M', ':' };
+ CharT pattern[] =
+ { '%', 'Y', '-', '%', 'm', '-', '%', 'd', ' ', '%', 'H', ':', '%', 'M', ':' };
               pb = pattern;
- pe = pb + sizeof(pattern) / sizeof(CharT);
+ pe = pb + sizeof (pattern) / sizeof(CharT);
               failed = tpf.put(os, os, os.fill(), &tm, pb, pe).failed();
               if (!failed)
               {
- duration<double> d = tp - system_clock::from_time_t(t)
- + seconds(tm.tm_sec);
- if (d.count() < 10)
- os << CharT('0');
+ duration<double> d = tp - system_clock::from_time_t(t) + seconds(tm.tm_sec);
+ if (d.count() < 10) os << CharT('0');
                 std::ios::fmtflags flgs = os.flags();
                 os.setf(std::ios::fixed, std::ios::floatfield);
                 os << d.count();
@@ -437,7 +437,7 @@
                   CharT sub_pattern[] =
                   { ' ', '%', 'z' };
                   pb = sub_pattern;
- pe = pb + +sizeof(sub_pattern) / sizeof(CharT);
+ pe = pb + +sizeof (sub_pattern) / sizeof(CharT);
                   failed = tpf.put(os, os, os.fill(), &tm, pb, pe).failed();
                 }
                 else
@@ -456,8 +456,7 @@
         {
           failed = true;
         }
- if (failed)
- os.setstate(std::ios_base::failbit | std::ios_base::badbit);
+ if (failed) os.setstate(std::ios_base::failbit | std::ios_base::badbit);
       }
       return os;
     }
@@ -465,9 +464,8 @@
     namespace detail
     {
 
- template<class CharT, class InputIterator>
- minutes extract_z(InputIterator& b, InputIterator e, std::ios_base::iostate& err, const std::ctype<
- CharT>& ct)
+ template <class CharT, class InputIterator>
+ minutes extract_z(InputIterator& b, InputIterator e, std::ios_base::iostate& err, const std::ctype<CharT>& ct)
       {
         int min = 0;
         if (b != e)
@@ -488,7 +486,7 @@
               return minutes(0);
             }
             cn = ct.narrow(*b, 0);
- if (!('0' <= cn && cn <= '9'))
+ if (! ('0' <= cn && cn <= '9'))
             {
               err |= std::ios_base::failbit;
               return minutes(0);
@@ -503,15 +501,14 @@
               return minutes(0);
             }
             cn = ct.narrow(*b, 0);
- if (!('0' <= cn && cn <= '9'))
+ if (! ('0' <= cn && cn <= '9'))
             {
               err |= std::ios_base::failbit;
               return minutes(0);
             }
             min = min * 10 + cn - '0';
           }
- if (++b == e)
- err |= std::ios_base::eofbit;
+ if (++b == e) err |= std::ios_base::eofbit;
           min += hr * 60;
           min *= sn;
         }
@@ -522,10 +519,9 @@
 
     } // detail
 
- template<class CharT, class Traits, class Duration>
+ template <class CharT, class Traits, class Duration>
     std::basic_istream<CharT, Traits>&
- operator>>(std::basic_istream<CharT, Traits>& is, time_point<system_clock,
- Duration>& tp)
+ operator>>(std::basic_istream<CharT, Traits>& is, time_point<system_clock, Duration>& tp)
     {
       typename std::basic_istream<CharT, Traits>::sentry ok(is);
       if (ok)
@@ -535,28 +531,24 @@
         {
           const CharT* pb = 0; //nullptr;
           const CharT* pe = pb;
- std::basic_string<CharT> fmt =
- get_time_fmt<CharT>(is);
+ std::basic_string<CharT> fmt = get_time_fmt<CharT> (is);
           pb = fmt.data();
           pe = pb + fmt.size();
 
           timezone_type tz = get_timezone(is);
           std::locale loc = is.getloc();
- const std::time_get<CharT>& tg =
- std::use_facet<std::time_get<CharT> >(loc);
+ const std::time_get<CharT>& tg = std::use_facet<std::time_get<CharT> >(loc);
           const std::ctype<CharT>& ct = std::use_facet<std::ctype<CharT> >(loc);
           tm tm; // {0}
           typedef std::istreambuf_iterator<CharT, Traits> It;
           if (pb == pe)
           {
- CharT
- pattern[] =
- { '%', 'Y', '-', '%', 'm', '-', '%', 'd', ' ', '%', 'H', ':', '%', 'M', ':' };
+ CharT pattern[] =
+ { '%', 'Y', '-', '%', 'm', '-', '%', 'd', ' ', '%', 'H', ':', '%', 'M', ':' };
             pb = pattern;
- pe = pb + sizeof(pattern) / sizeof(CharT);
+ pe = pb + sizeof (pattern) / sizeof(CharT);
             tg.get(is, 0, is, err, &tm, pb, pe);
- if (err & std::ios_base::failbit)
- goto exit;
+ if (err & std::ios_base::failbit) goto exit;
             double sec;
             CharT c = CharT();
             is >> sec;
@@ -574,16 +566,14 @@
               goto exit;
             }
             minutes min = detail::extract_z(i, eof, err, ct);
- if (err & std::ios_base::failbit)
- goto exit;
+ if (err & std::ios_base::failbit) goto exit;
             time_t t;
 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
             t = detail::internal_timegm(&tm);
 #else
             t = timegm(&tm);
 #endif
- tp = system_clock::from_time_t(t) - min
- + round<microseconds> (duration<double> (sec));
+ tp = system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec));
           }
           else
           {
@@ -602,8 +592,7 @@
               It i(is);
               It eof;
               minu = extract_z(i, eof, err, ct);
- if (err & std::ios_base::failbit)
- goto exit;
+ if (err & std::ios_base::failbit) goto exit;
               if (fz + 2 != pe)
               {
                 if (err != std::ios_base::goodbit)
@@ -612,8 +601,7 @@
                   goto exit;
                 }
                 tg.get(is, 0, is, err, &tm, fz + 2, pe);
- if (err & std::ios_base::failbit)
- goto exit;
+ if (err & std::ios_base::failbit) goto exit;
               }
             }
             tm.tm_isdst = -1;

Modified: trunk/boost/chrono/io/time_point_put.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_put.hpp (original)
+++ trunk/boost/chrono/io/time_point_put.hpp 2011-11-12 09:01:38 EST (Sat, 12 Nov 2011)
@@ -88,49 +88,66 @@
        *
        * @Returns An iterator pointing immediately after the last character produced.
        */
+
       template <class Clock, class Duration>
- iter_type put(iter_type s, std::ios_base& ios, time_point<Clock, Duration> const& tp, const CharT* pattern,
+ iter_type put(iter_type i, std::ios_base& ios, time_point<Clock, Duration> const& tp, const CharT* pattern,
           const CharT* pat_end) const
       {
- time_point_units<CharT,OutputIterator> const& units_facet = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios);
+ if (std::has_facet<time_point_units<CharT, OutputIterator> >(ios.getloc()))
+ {
+ time_point_units<CharT, OutputIterator> const &facet =
+ std::use_facet<time_point_units<CharT, OutputIterator> >(ios.getloc());
+ return put(facet, i, ios, tp, pattern, pat_end);
+ }
+ else
+ {
+ time_point_units_default<CharT, OutputIterator> facet;
+ return put(facet, i, ios, tp, pattern, pat_end);
+ }
+ }
+
+ template <class Clock, class Duration>
+ iter_type put(time_point_units<CharT, OutputIterator> const& units_facet, iter_type s, std::ios_base& ios,
+ time_point<Clock, Duration> const& tp, const CharT* pattern, const CharT* pat_end) const
+ {
 
         const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(ios.getloc());
         for (; pattern != pat_end; ++pattern)
         {
- if (ct.narrow(*pattern, 0) == '%')
+ if (ct.narrow(*pattern, 0) == '%')
+ {
+ if (++pattern == pat_end)
+ {
+ *s++ = pattern[-1];
+ break;
+ }
+ char fmt = ct.narrow(*pattern, 0);
+ switch (fmt)
+ {
+ case 'd':
             {
- if (++pattern == pat_end)
- {
- *s++ = pattern[-1];
- break;
- }
- char fmt = ct.narrow(*pattern, 0);
- switch (fmt)
- {
- case 'd':
- {
- s = put_duration(s, ios, tp.time_since_epoch());
- break;
- }
- case 'e':
- {
- s = put_epoch<Clock>(s, ios);
- break;
- }
- case 'x':
- {
- std::basic_string<CharT> pat = units_facet.get_pattern();
- pattern = pat.data();
- pat_end = pattern + pat.size();
- break;
- }
- default:
- BOOST_ASSERT(false && "Boost::Chrono internal error.");
- break;
- }
+ s = put_duration(s, ios, tp.time_since_epoch());
+ break;
+ }
+ case 'e':
+ {
+ s = put_epoch<Clock> (units_facet, s, ios);
+ break;
+ }
+ // case 'x':
+ // {
+ // std::basic_string<CharT> pat = units_facet.get_pattern();
+ // pattern = pat.data();
+ // pat_end = pattern + pat.size();
+ // break;
+ // }
+ default:
+ BOOST_ASSERT(false && "Boost::Chrono internal error.");
+ break;
             }
- else
- *s++ = *pattern;
+ }
+ else
+ *s++ = *pattern;
         }
         return s;
       }
@@ -148,43 +165,54 @@
        * @Returns An iterator pointing immediately after the last character produced.
        */
       template <class Clock, class Duration>
- iter_type put(iter_type s, std::ios_base& ios, time_point<Clock, Duration> const& tp) const
+ iter_type put(iter_type i, std::ios_base& ios, time_point<Clock, Duration> const& tp) const
       {
- std::basic_string<CharT> str = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios).get_pattern();
- return put(s, ios, tp, str.data(), str.data() + str.size());
+ if (std::has_facet<time_point_units<CharT, OutputIterator> >(ios.getloc()))
+ {
+ time_point_units<CharT, OutputIterator> const &facet =
+ std::use_facet<time_point_units<CharT, OutputIterator> >(ios.getloc());
+ std::basic_string<CharT> str = facet.get_pattern();
+ return put(facet, i, ios, tp, str.data(), str.data() + str.size());
+ }
+ else
+ {
+ time_point_units_default<CharT, OutputIterator> facet;
+ std::basic_string<CharT> str = facet.get_pattern();
+ return put(facet, i, ios, tp, str.data(), str.data() + str.size());
+ }
       }
 
-// /*
-// *
-// */
-//
-// template <class Clock, class Duration>
-// iter_type put(iter_type s, std::ios_base& ios, time_point<Clock, Duration> const& tp, const CharT* pattern,
-// const CharT* pat_end) const
-// {
-// time_point_units<CharT,OutputIterator> const& units_facet = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios);
-//
-// 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 time_point_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 <class Duration>
-// iter_type put(iter_type s, std::ios_base& ios, time_point<system_clock, Duration> const& tp) const
-// {
-// std::basic_string<CharT> str = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios).get_date_time_pattern();
-// return put(s, ios, tp, str.data(), str.data() + str.size());
-// }
+ // /*
+ // *
+ // */
+ //
+ // template <class Clock, class Duration>
+ // iter_type put(iter_type s, std::ios_base& ios, time_point<Clock, Duration> const& tp, const CharT* pattern,
+ // const CharT* pat_end) const
+ // {
+ // time_point_units<CharT,OutputIterator> const& units_facet = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios);
+ //
+ // 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 time_point_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 <class Duration>
+ // iter_type put(iter_type s, std::ios_base& ios, time_point<system_clock, Duration> const& tp) const
+ // {
+ // std::basic_string<CharT> str = time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios).get_date_time_pattern();
+ // return put(s, ios, tp, str.data(), str.data() + str.size());
+ // }
 
       /**
        *
@@ -195,14 +223,18 @@
        * @Returns An iterator pointing immediately after the last character produced.
        */
       template <typename Rep, typename Period>
- iter_type put_duration(iter_type s, std::ios_base& ios, duration<Rep, Period> const& d) const
+ iter_type put_duration(iter_type i, std::ios_base& ios, duration<Rep, Period> const& d) const
       {
- if (!std::has_facet<duration_put<CharT> >(ios.getloc()))
+ if (std::has_facet<duration_put<CharT> >(ios.getloc()))
         {
- ios.imbue(std::locale(ios.getloc(), new duration_put<CharT>()));
+ duration_put<CharT> const &facet = std::use_facet<duration_put<CharT> >(ios.getloc());
+ return facet.put(i, ios, d);
+ }
+ else
+ {
+ duration_put<CharT> facet;
+ return facet.put(i, ios, d);
         }
- return std::use_facet<duration_put<CharT> >(ios.getloc())
- .put(s, ios, d);
       }
 
       /**
@@ -215,10 +247,26 @@
        * @Effects Calls std::use_facet<time_point_units<CharT,OutputIterator> >(ios.getloc()).put(s, ios, d).
        * @Returns An iterator pointing immediately after the last character produced.
        */
+
+ template <typename Clock>
+ iter_type put_epoch(iter_type i, std::ios_base& is) const
+ {
+ if (std::has_facet<time_point_units<CharT> >(is.getloc()))
+ {
+ time_point_units<CharT> const &facet = std::use_facet<time_point_units<CharT> >(is.getloc());
+ return put_epoch<Clock> (facet, i, is);
+ }
+ else
+ {
+ time_point_units_default<CharT> facet;
+ return put_epoch<Clock> (facet, i, is);
+ }
+ }
+
       template <typename Clock>
- iter_type put_epoch(iter_type s, std::ios_base& ios) const
+ iter_type put_epoch(time_point_units<CharT, OutputIterator> const& facet, iter_type s, std::ios_base& ios) const
       {
- return time_point_units<CharT,OutputIterator>::imbue_if_has_not(ios).template put<Clock>(s, ios);
+ return facet.template put<Clock> (s, ios);
       }
 
       /**


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