Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85610 - in branches/release: boost/chrono/io libs/chrono/doc libs/chrono/test libs/chrono/test/io
From: vicente.botet_at_[hidden]
Date: 2013-09-08 14:44:28


Author: viboes
Date: 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013)
New Revision: 85610
URL: http://svn.boost.org/trac/boost/changeset/85610

Log:
Chrono: merge timepoint io improvements.

Added:
   branches/release/libs/chrono/test/test_7868.cpp
      - copied, changed from r84967, trunk/libs/chrono/test/test_7868.cpp
Properties modified:
   branches/release/libs/chrono/test/win32_test.cpp (props changed)
Text files modified:
   branches/release/boost/chrono/io/time_point_io.hpp | 259 +++++++++++++++++++++++++++------------
   branches/release/libs/chrono/doc/chrono.qbk | 4
   branches/release/libs/chrono/test/io/time_point_input.cpp | 28 ++++
   branches/release/libs/chrono/test/io/time_point_output.cpp | 23 +++
   branches/release/libs/chrono/test/test_7868.cpp | 5
   5 files changed, 235 insertions(+), 84 deletions(-)

Modified: branches/release/boost/chrono/io/time_point_io.hpp
==============================================================================
--- branches/release/boost/chrono/io/time_point_io.hpp Sun Sep 8 13:17:18 2013 (r85609)
+++ branches/release/boost/chrono/io/time_point_io.hpp 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013) (r85610)
@@ -158,8 +158,7 @@
                 err |= std::ios_base::failbit;
         }
 
- void
- get_second(int& s,
+ void get_second(int& s,
                                                        iter_type& b, iter_type e,
                                                        std::ios_base::iostate& err,
                                                        const std::ctype<char_type>& ct) const
@@ -171,7 +170,89 @@
                 err |= std::ios_base::failbit;
         }
 
+ void get_white_space(iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ for (; b != e && ct.is(std::ctype_base::space, *b); ++b)
+ ;
+ if (b == e)
+ err |= std::ios_base::eofbit;
+ }
 
+ void get_12_hour(int& h,
+ iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ int t = get_up_to_n_digits(b, e, err, ct, 2);
+ if (!(err & std::ios_base::failbit) && 1 <= t && t <= 12)
+ h = t;
+ else
+ err |= std::ios_base::failbit;
+ }
+
+ void get_percent(iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ if (b == e)
+ {
+ err |= std::ios_base::eofbit | std::ios_base::failbit;
+ return;
+ }
+ if (ct.narrow(*b, 0) != '%')
+ err |= std::ios_base::failbit;
+ else if(++b == e)
+ err |= std::ios_base::eofbit;
+ }
+
+ void get_day_year_num(int& d,
+ iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ int t = get_up_to_n_digits(b, e, err, ct, 3);
+ if (!(err & std::ios_base::failbit) && t <= 365)
+ d = t;
+ else
+ err |= std::ios_base::failbit;
+ }
+
+ void
+ get_weekday(int& w,
+ iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ int t = get_up_to_n_digits(b, e, err, ct, 1);
+ if (!(err & std::ios_base::failbit) && t <= 6)
+ w = t;
+ else
+ err |= std::ios_base::failbit;
+ }
+#if 0
+
+ void
+ get_am_pm(int& h,
+ iter_type& b, iter_type e,
+ std::ios_base::iostate& err,
+ const std::ctype<char_type>& ct) const
+ {
+ const string_type* ap = am_pm();
+ if (ap[0].size() + ap[1].size() == 0)
+ {
+ err |= ios_base::failbit;
+ return;
+ }
+ ptrdiff_t i = detail::scan_keyword(b, e, ap, ap+2, ct, err, false) - ap;
+ if (i == 0 && h == 12)
+ h = 0;
+ else if (i == 1 && h < 12)
+ h += 12;
+ }
+
+#endif
 
         InputIterator get(
             iter_type b, iter_type e,
@@ -185,101 +266,111 @@
 
             switch (fmt)
             {
-// case 'a':
-// case 'A':
-// that_.get_weekdayname(tm->tm_wday, b, e, err, ct);
-// break;
-// case 'b':
-// case 'B':
-// case 'h':
-// that_.get_monthname(tm->tm_mon, b, e, err, ct);
-// break;
+ case 'a':
+ case 'A':
+ {
+ std::tm tm2;
+ that_.get_weekday(b, e, iob, err, &tm2);
+ //tm->tm_wday = tm2.tm_wday;
+ }
+ break;
+ case 'b':
+ case 'B':
+ case 'h':
+ {
+ std::tm tm2;
+ that_.get_monthname(b, e, iob, err, &tm2);
+ //tm->tm_mon = tm2.tm_mon;
+ }
+ break;
 // case 'c':
-// {
-// const string_type& fm = this->c();
-// b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
-// }
-// break;
+// {
+// const string_type& fm = c();
+// b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
+// }
+// break;
             case 'd':
             case 'e':
               get_day(tm->tm_mday, b, e, err, ct);
-
- break;
-// case 'D':
-// {
-// const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
-// b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
-// }
-// break;
-// case 'F':
-// {
-// const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
-// b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
-// }
-// break;
+ break;
+ case 'D':
+ {
+ const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
+ b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
+ }
+ break;
+ case 'F':
+ {
+ const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
+ b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
+ }
+ break;
             case 'H':
               get_hour(tm->tm_hour, b, e, err, ct);
- break;
-// case 'I':
-// that_.get_12_hour(tm->tm_hour, b, e, err, ct);
-// break;
-// case 'j':
-// that_.get_day_year_num(tm->tm_yday, b, e, err, ct);
-// break;
+ break;
+ case 'I':
+ get_12_hour(tm->tm_hour, b, e, err, ct);
+ break;
+ case 'j':
+ get_day_year_num(tm->tm_yday, b, e, err, ct);
+ break;
             case 'm':
               get_month(tm->tm_mon, b, e, err, ct);
- break;
+ break;
             case 'M':
               get_minute(tm->tm_min, b, e, err, ct);
- break;
-// case 'n':
-// case 't':
-// that_.get_white_space(b, e, err, ct);
-// break;
+ break;
+ case 'n':
+ case 't':
+ get_white_space(b, e, err, ct);
+ break;
 // case 'p':
-// that_.get_am_pm(tm->tm_hour, b, e, err, ct);
-// break;
-// case 'r':
-// {
-// const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
-// b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
-// }
-// break;
-// case 'R':
-// {
-// const char_type fm[] = {'%', 'H', ':', '%', 'M'};
-// b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
-// }
-// break;
-// case 'S':
-// that_.get_second(tm->tm_sec, b, e, err, ct);
-// break;
-// case 'T':
-// {
-// const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
-// b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
-// }
-// break;
-// case 'w':
-// that_.get_weekday(tm->tm_wday, b, e, err, ct);
-// break;
-// case 'x':
-// return that_.get_date(b, e, iob, err, tm);
+// get_am_pm(tm->tm_hour, b, e, err, ct);
+// break;
+ case 'r':
+ {
+ const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
+ b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
+ }
+ break;
+ case 'R':
+ {
+ const char_type fm[] = {'%', 'H', ':', '%', 'M'};
+ b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
+ }
+ break;
+ case 'S':
+ get_second(tm->tm_sec, b, e, err, ct);
+ break;
+ case 'T':
+ {
+ const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
+ b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
+ }
+ break;
+ case 'w':
+ {
+ get_weekday(tm->tm_wday, b, e, err, ct);
+ }
+ break;
+ case 'x':
+ return that_.get_date(b, e, iob, err, tm);
 // case 'X':
-// {
-// const string_type& fm = this->X();
+// return that_.get_time(b, e, iob, err, tm);
+// {
+// const string_type& fm = X();
 // b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
-// }
-// break;
+// }
+// break;
 // case 'y':
-// that_.get_year(tm->tm_year, b, e, err, ct);
+// get_year(tm->tm_year, b, e, err, ct);
                 break;
             case 'Y':
               get_year4(tm->tm_year, b, e, err, ct);
- break;
-// case '%':
-// that_.get_percent(b, e, err, ct);
-// break;
+ break;
+ case '%':
+ get_percent(b, e, err, ct);
+ break;
             default:
                 err |= std::ios_base::failbit;
             }
@@ -964,6 +1055,12 @@
           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}
+ tm.tm_year=0;
+ tm.tm_mon=0;
+ tm.tm_mday=0;
+ tm.tm_hour=0;
+ tm.tm_min=0;
+ tm.tm_sec=0;
           typedef std::istreambuf_iterator<CharT, Traits> It;
           if (pb == pe)
           {
@@ -971,7 +1068,7 @@
             { '%', 'Y', '-', '%', 'm', '-', '%', 'd', ' ', '%', 'H', ':', '%', 'M', ':' };
             pb = pattern;
             pe = pb + sizeof (pattern) / sizeof(CharT);
- tm.tm_sec=0;
+
 #if defined BOOST_CHRONO_USES_INTERNAL_TIME_GET
             const detail::time_get<CharT>& dtg(tg);
             dtg.get(is, 0, is, err, &tm, pb, pe);

Modified: branches/release/libs/chrono/doc/chrono.qbk
==============================================================================
--- branches/release/libs/chrono/doc/chrono.qbk Sun Sep 8 13:17:18 2013 (r85609)
+++ branches/release/libs/chrono/doc/chrono.qbk 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013) (r85610)
@@ -556,9 +556,7 @@
 __Boost_Chrono__ can be configured as a header-only library defining __BOOST_CHRONO_HEADER_ONLY.
 However Boost.Chrono depends on the non header-only library Boost.System, so that you will need to link with boost_system.
 
-Boost.System has un undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only, but it is buggy
-(see [@http://svn.boost.org/trac/boost/ticket/7347 #7347] duplicate symbol while BOOST_ERROR_CODE_HEADER_ONLY is defined)
-
+Boost.System has un undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only.
  
 If __BOOST_CHRONO_HEADER_ONLY is not defined you need to compile it and build the library before use, for example using:
 

Modified: branches/release/libs/chrono/test/io/time_point_input.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/time_point_input.cpp Sun Sep 8 13:17:18 2013 (r85609)
+++ branches/release/libs/chrono/test/io/time_point_input.cpp 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013) (r85610)
@@ -38,6 +38,25 @@
   std::cout << "Obtained= " << boost::chrono::duration_cast<boost::chrono::nanoseconds>(tp.time_since_epoch()).count() << std::endl;
   BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res)));
 }
+
+template <typename D>
+void test_good_utc_fmt_system_clock(std::string str, std::string fmt, D res)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::istringstream in(str);
+ boost::chrono::time_point<Clock, D> tp;
+ in >> time_fmt(boost::chrono::timezone::utc, fmt);
+ in >> tp;
+ BOOST_TEST(in.eof());
+ BOOST_TEST(!in.fail());
+ std::cout << "Input= " << str << std::endl;
+ std::cout << "Expected= " << boost::chrono::time_point<Clock, D>(res) << std::endl;
+ std::cout << "Obtained= " << tp << std::endl;
+ std::cout << "Expected= " << boost::chrono::duration_cast<boost::chrono::nanoseconds>(boost::chrono::time_point<Clock, D>(res).time_since_epoch()).count() << std::endl;
+ std::cout << "Obtained= " << boost::chrono::duration_cast<boost::chrono::nanoseconds>(tp.time_since_epoch()).count() << std::endl;
+ BOOST_TEST_EQ( tp , (boost::chrono::time_point<Clock, D>(res)));
+}
 #endif
 template <typename Clock, typename D>
 void test_fail(const char* str, D)
@@ -131,6 +150,15 @@
   test_good_system_clock ("1970-01-01 00:08:20.000000 +0000", duration<boost::int_least64_t, deci> (5000));
   test_good_system_clock ("1970-01-01 00:02:46.666667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (5000));
 
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%F %H:%M:%S", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02", "%Y-%m-%d %H", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02", "%F %H", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2));
+ test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2));
+ //test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2));
+
 
 // test_fail<Clock> ("3001 ms", seconds(3));
 // test_fail_epoch<Clock> ("3001 ms", seconds(3));

Modified: branches/release/libs/chrono/test/io/time_point_output.cpp
==============================================================================
--- branches/release/libs/chrono/test/io/time_point_output.cpp Sun Sep 8 13:17:18 2013 (r85609)
+++ branches/release/libs/chrono/test/io/time_point_output.cpp 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013) (r85610)
@@ -67,6 +67,20 @@
   BOOST_TEST( (out.str() == std::string(str) ));
 }
 
+template <typename D>
+void test_good_utc_fmt_system_clock(const char* str, const char* fmt, D d)
+{
+ typedef boost::chrono::system_clock Clock;
+
+ std::ostringstream out;
+ boost::chrono::time_point<Clock, D> tp(d);
+ out << time_fmt(boost::chrono::timezone::utc, fmt) << tp;
+ BOOST_TEST(out.good());
+ std::cout << "Expected= " << str << std::endl;
+ std::cout << "Obtained= " << out.str() << std::endl;
+ BOOST_TEST_EQ( out.str() , std::string(str) );
+}
+
 template<typename Clock, typename D>
 void test_good(const char* str, D d, boost::chrono::duration_style style)
 {
@@ -156,6 +170,15 @@
   test_good_symbol_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2));
   test_good_symbol_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2));
   test_good_symbol_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2));
+
+ test_good_utc_fmt_system_clock("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2));
+ test_good_utc_fmt_system_clock("1970-01-01 02", "%Y-%m-%d %H", hours(2));
+
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2));
+ test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2));
+ test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2));
+
 }
 
 void test_gmtime(std::time_t t)

Copied and modified: branches/release/libs/chrono/test/test_7868.cpp (from r84967, trunk/libs/chrono/test/test_7868.cpp)
==============================================================================
--- trunk/libs/chrono/test/test_7868.cpp Sun Jul 7 07:37:27 2013 (r84967, copy source)
+++ branches/release/libs/chrono/test/test_7868.cpp 2013-09-08 14:44:28 EDT (Sun, 08 Sep 2013) (r85610)
@@ -1,3 +1,8 @@
+// Copyright 2013 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org/libs/chrono for documentation.
+
 #define BOOST_CHRONO_VERSION 2
 //#define BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT 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