|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74738 - trunk/boost/chrono/io
From: vicente.botet_at_[hidden]
Date: 2011-10-05 09:56:28
Author: viboes
Date: 2011-10-05 09:56:27 EDT (Wed, 05 Oct 2011)
New Revision: 74738
URL: http://svn.boost.org/trac/boost/changeset/74738
Log:
Chrono: Move translation to a separated file and make use for epoch also.
Added:
trunk/boost/chrono/io/translate.hpp (contents, props changed)
Text files modified:
trunk/boost/chrono/io/duration_io.hpp | 122 ++++++++++++++++++++--------------------
trunk/boost/chrono/io/duration_unit_string.hpp | 111 ++++++++++++++---------------------
trunk/boost/chrono/io/time_point_io.hpp | 5
3 files changed, 109 insertions(+), 129 deletions(-)
Modified: trunk/boost/chrono/io/duration_io.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_io.hpp (original)
+++ trunk/boost/chrono/io/duration_io.hpp 2011-10-05 09:56:27 EDT (Wed, 05 Oct 2011)
@@ -127,7 +127,7 @@
std::locale::facet(refs), style_(style)
{
}
- explicit duration_punct(duration_style::type style, const duration_punct&, size_t refs = 0) :
+ duration_punct(duration_style::type style, const duration_punct&, size_t refs = 0) :
std::locale::facet(refs), style_(style)
{
}
@@ -418,7 +418,7 @@
#if !defined BOOST_CHRONO_IO_V1_DONT_PROVIDE_DEPRECATED
return os << d.count() << ' ' << f.template name<Rep,Period>(d);
#else
- return os << d.count() << ' ' << duration_unit_string<CharT>(f.is_prefix(), d);
+ return os << d.count() << ' ' << duration_unit<CharT>(f.is_prefix(), d);
#endif
}
catch (...)
@@ -511,8 +511,8 @@
f.template long_name<ratio<1> >(),
f.template short_name<ratio<1> >()
#else
- duration_unit_string<CharT>(true, seconds(2)),
- duration_unit_string<CharT>(false, seconds(1))
+ duration_unit<CharT>(true, seconds(2)),
+ duration_unit<CharT>(false, seconds(1))
#endif
};
std::ios_base::iostate err = std::ios_base::goodbit;
@@ -575,63 +575,63 @@
f.template long_name<ratio<3600> >(),
f.template short_name<ratio<3600> >()
#else
- duration_unit_string<CharT>(true, duration<Rep, atto>(2)),
- duration_unit_string<CharT>(true, duration<Rep, atto>(1)),
- duration_unit_string<CharT>(false, duration<Rep, atto>(1)),
- duration_unit_string<CharT>(true, duration<Rep, femto>(2)),
- duration_unit_string<CharT>(true, duration<Rep, femto>(1)),
- duration_unit_string<CharT>(false, duration<Rep, femto>(1)),
- duration_unit_string<CharT>(true, duration<Rep, pico>(2)),
- duration_unit_string<CharT>(true, duration<Rep, pico>(1)),
- duration_unit_string<CharT>(false, duration<Rep, pico>(1)),
- duration_unit_string<CharT>(true, duration<Rep, nano>(2)),
- duration_unit_string<CharT>(true, duration<Rep, nano>(1)),
- duration_unit_string<CharT>(false, duration<Rep, nano>(1)),
- duration_unit_string<CharT>(true, duration<Rep, micro>(2)),
- duration_unit_string<CharT>(true, duration<Rep, micro>(1)),
- duration_unit_string<CharT>(false, duration<Rep, micro>(1)),
- duration_unit_string<CharT>(true, duration<Rep, milli>(2)),
- duration_unit_string<CharT>(true, duration<Rep, milli>(1)),
- duration_unit_string<CharT>(false, duration<Rep, milli>(1)),
- duration_unit_string<CharT>(true, duration<Rep, centi>(2)),
- duration_unit_string<CharT>(true, duration<Rep, centi>(1)),
- duration_unit_string<CharT>(false, duration<Rep, centi>(1)),
- duration_unit_string<CharT>(true, duration<Rep, deci>(2)),
- duration_unit_string<CharT>(true, duration<Rep, deci>(1)),
- duration_unit_string<CharT>(false, duration<Rep, deci>(1)),
- duration_unit_string<CharT>(true, duration<Rep, deca>(2)),
- duration_unit_string<CharT>(true, duration<Rep, deca>(1)),
- duration_unit_string<CharT>(false, duration<Rep, deca>(1)),
- duration_unit_string<CharT>(true, duration<Rep, hecto>(2)),
- duration_unit_string<CharT>(true, duration<Rep, hecto>(1)),
- duration_unit_string<CharT>(false, duration<Rep, hecto>(1)),
- duration_unit_string<CharT>(true, duration<Rep, kilo>(2)),
- duration_unit_string<CharT>(true, duration<Rep, kilo>(1)),
- duration_unit_string<CharT>(false, duration<Rep, kilo>(1)),
- duration_unit_string<CharT>(true, duration<Rep, mega>(2)),
- duration_unit_string<CharT>(true, duration<Rep, mega>(1)),
- duration_unit_string<CharT>(false, duration<Rep, mega>(1)),
- duration_unit_string<CharT>(true, duration<Rep, giga>(2)),
- duration_unit_string<CharT>(true, duration<Rep, giga>(1)),
- duration_unit_string<CharT>(false, duration<Rep, giga>(1)),
- duration_unit_string<CharT>(true, duration<Rep, giga>(2)),
- duration_unit_string<CharT>(true, duration<Rep, tera>(1)),
- duration_unit_string<CharT>(false, duration<Rep, giga>(1)),
- duration_unit_string<CharT>(true, duration<Rep, peta>(2)),
- duration_unit_string<CharT>(true, duration<Rep, peta>(1)),
- duration_unit_string<CharT>(false, duration<Rep, peta>(1)),
- duration_unit_string<CharT>(true, duration<Rep, exa>(2)),
- duration_unit_string<CharT>(true, duration<Rep, exa>(1)),
- duration_unit_string<CharT>(false, duration<Rep, exa>(1)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<1> >(2)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<1> >(1)),
- duration_unit_string<CharT>(false, duration<Rep, ratio<1> >(1)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<60> >(2)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<60> >(1)),
- duration_unit_string<CharT>(false, duration<Rep, ratio<60> >(1)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<3600> >(2)),
- duration_unit_string<CharT>(true, duration<Rep, ratio<3600> >(1)),
- duration_unit_string<CharT>(false, duration<Rep, ratio<3600> >(1)),
+ duration_unit<CharT>(true, duration<Rep, atto>(2)),
+ duration_unit<CharT>(true, duration<Rep, atto>(1)),
+ duration_unit<CharT>(false, duration<Rep, atto>(1)),
+ duration_unit<CharT>(true, duration<Rep, femto>(2)),
+ duration_unit<CharT>(true, duration<Rep, femto>(1)),
+ duration_unit<CharT>(false, duration<Rep, femto>(1)),
+ duration_unit<CharT>(true, duration<Rep, pico>(2)),
+ duration_unit<CharT>(true, duration<Rep, pico>(1)),
+ duration_unit<CharT>(false, duration<Rep, pico>(1)),
+ duration_unit<CharT>(true, duration<Rep, nano>(2)),
+ duration_unit<CharT>(true, duration<Rep, nano>(1)),
+ duration_unit<CharT>(false, duration<Rep, nano>(1)),
+ duration_unit<CharT>(true, duration<Rep, micro>(2)),
+ duration_unit<CharT>(true, duration<Rep, micro>(1)),
+ duration_unit<CharT>(false, duration<Rep, micro>(1)),
+ duration_unit<CharT>(true, duration<Rep, milli>(2)),
+ duration_unit<CharT>(true, duration<Rep, milli>(1)),
+ duration_unit<CharT>(false, duration<Rep, milli>(1)),
+ duration_unit<CharT>(true, duration<Rep, centi>(2)),
+ duration_unit<CharT>(true, duration<Rep, centi>(1)),
+ duration_unit<CharT>(false, duration<Rep, centi>(1)),
+ duration_unit<CharT>(true, duration<Rep, deci>(2)),
+ duration_unit<CharT>(true, duration<Rep, deci>(1)),
+ duration_unit<CharT>(false, duration<Rep, deci>(1)),
+ duration_unit<CharT>(true, duration<Rep, deca>(2)),
+ duration_unit<CharT>(true, duration<Rep, deca>(1)),
+ duration_unit<CharT>(false, duration<Rep, deca>(1)),
+ duration_unit<CharT>(true, duration<Rep, hecto>(2)),
+ duration_unit<CharT>(true, duration<Rep, hecto>(1)),
+ duration_unit<CharT>(false, duration<Rep, hecto>(1)),
+ duration_unit<CharT>(true, duration<Rep, kilo>(2)),
+ duration_unit<CharT>(true, duration<Rep, kilo>(1)),
+ duration_unit<CharT>(false, duration<Rep, kilo>(1)),
+ duration_unit<CharT>(true, duration<Rep, mega>(2)),
+ duration_unit<CharT>(true, duration<Rep, mega>(1)),
+ duration_unit<CharT>(false, duration<Rep, mega>(1)),
+ duration_unit<CharT>(true, duration<Rep, giga>(2)),
+ duration_unit<CharT>(true, duration<Rep, giga>(1)),
+ duration_unit<CharT>(false, duration<Rep, giga>(1)),
+ duration_unit<CharT>(true, duration<Rep, giga>(2)),
+ duration_unit<CharT>(true, duration<Rep, tera>(1)),
+ duration_unit<CharT>(false, duration<Rep, giga>(1)),
+ duration_unit<CharT>(true, duration<Rep, peta>(2)),
+ duration_unit<CharT>(true, duration<Rep, peta>(1)),
+ duration_unit<CharT>(false, duration<Rep, peta>(1)),
+ duration_unit<CharT>(true, duration<Rep, exa>(2)),
+ duration_unit<CharT>(true, duration<Rep, exa>(1)),
+ duration_unit<CharT>(false, duration<Rep, exa>(1)),
+ duration_unit<CharT>(true, duration<Rep, ratio<1> >(2)),
+ duration_unit<CharT>(true, duration<Rep, ratio<1> >(1)),
+ duration_unit<CharT>(false, duration<Rep, ratio<1> >(1)),
+ duration_unit<CharT>(true, duration<Rep, ratio<60> >(2)),
+ duration_unit<CharT>(true, duration<Rep, ratio<60> >(1)),
+ duration_unit<CharT>(false, duration<Rep, ratio<60> >(1)),
+ duration_unit<CharT>(true, duration<Rep, ratio<3600> >(2)),
+ duration_unit<CharT>(true, duration<Rep, ratio<3600> >(1)),
+ duration_unit<CharT>(false, duration<Rep, ratio<3600> >(1)),
#endif
};
std::ios_base::iostate err = std::ios_base::goodbit;
Modified: trunk/boost/chrono/io/duration_unit_string.hpp
==============================================================================
--- trunk/boost/chrono/io/duration_unit_string.hpp (original)
+++ trunk/boost/chrono/io/duration_unit_string.hpp 2011-10-05 09:56:27 EDT (Wed, 05 Oct 2011)
@@ -11,6 +11,7 @@
#include <boost/chrono/config.hpp>
#include <boost/chrono/duration.hpp>
#include <boost/ratio/ratio_io.hpp>
+#include <boost/chrono/io/translate.hpp>
#include <string>
namespace boost
@@ -19,55 +20,64 @@
{
template <class Period, class CharT>
- struct duration_period_suffix
+ struct duration_unit_strings
{
static std::basic_string<CharT> plural()
{
static const CharT u[] =
{ 's', 'e', 'c', 'o', 'n', 'd', 's' };
- static const std::basic_string<CharT> str(u, u + sizeof(u)
+ static const std::basic_string<CharT> suffix(u, u + sizeof(u)
/ sizeof(u[0]));
- return str;
+ return ::boost::ratio_string<Period, CharT>::long_name()+suffix;
}
static std::basic_string<CharT> singular()
{
static const CharT u[] =
{ 's', 'e', 'c', 'o', 'n', 'd' };
- static const std::basic_string<CharT> str(u, u + sizeof(u)
+ static const std::basic_string<CharT> suffix(u, u + sizeof(u)
/ sizeof(u[0]));
- return str;
+ return ::boost::ratio_string<Period, CharT>::long_name()+suffix;
+ }
+ static std::basic_string<CharT> symbol()
+ {
+ static const std::basic_string<CharT> str(1, 's');
+ return ::boost::ratio_string<Period, CharT>::short_name()+str;
}
-
};
template <class CharT>
- struct duration_period_suffix<ratio<60>, CharT >
+ struct duration_unit_strings<ratio<1>, CharT >
{
static std::basic_string<CharT> plural()
{
static const CharT u[] =
- { 'm', 'i', 'n', 'u', 't', 'e', 's' };
- static const std::basic_string<CharT> str(u, u + sizeof(u)
+ { 's', 'e', 'c', 'o', 'n', 'd', 's' };
+ static const std::basic_string<CharT> suffix(u, u + sizeof(u)
/ sizeof(u[0]));
- return str;
+ return ::boost::ratio_string<ratio<1>, CharT>::long_name()+suffix;
}
static std::basic_string<CharT> singular()
{
static const CharT u[] =
- { 'm', 'i', 'n', 'u', 't', 'e' };
- static const std::basic_string<CharT> str(u, u + sizeof(u)
+ { 's', 'e', 'c', 'o', 'n', 'd' };
+ static const std::basic_string<CharT> suffix(u, u + sizeof(u)
/ sizeof(u[0]));
+ return ::boost::ratio_string<ratio<1>, CharT>::long_name()+suffix;
+ }
+ static std::basic_string<CharT> symbol()
+ {
+ static const std::basic_string<CharT> str(1, 's');
return str;
}
};
template <class CharT>
- struct duration_period_suffix<ratio<3600>, CharT >
+ struct duration_unit_strings<ratio<60>, CharT >
{
static std::basic_string<CharT> plural()
{
static const CharT u[] =
- { 'h', 'o', 'u', 'r', 's' };
+ { 'm', 'i', 'n', 'u', 't', 'e', 's' };
static const std::basic_string<CharT> str(u, u + sizeof(u)
/ sizeof(u[0]));
return str;
@@ -75,60 +85,37 @@
static std::basic_string<CharT> singular()
{
static const CharT u[] =
- { 'h', 'o', 'u', 'r' };
+ { 'm', 'i', 'n', 'u', 't', 'e' };
static const std::basic_string<CharT> str(u, u + sizeof(u)
/ sizeof(u[0]));
return str;
}
- };
-
- template <class Period, class CharT>
- struct duration_period
- {
- static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation)
- {
- return ::boost::ratio_string<Period, CharT>::long_name()+translation;
- }
static std::basic_string<CharT> symbol()
{
- static const std::basic_string<CharT> str(1, 's');
- return ::boost::ratio_string<Period, CharT>::short_name()+str;
+ static const std::basic_string<CharT> str(1, 'm');
+ return str;
}
};
template <class CharT>
- struct duration_period<ratio<1>, CharT >
+ struct duration_unit_strings<ratio<3600>, CharT >
{
- static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation)
- {
- return translation;
- }
- static std::basic_string<CharT> symbol()
+ static std::basic_string<CharT> plural()
{
- static const std::basic_string<CharT> str(1, 's');
+ static const CharT u[] =
+ { 'h', 'o', 'u', 'r', 's' };
+ static const std::basic_string<CharT> str(u, u + sizeof(u)
+ / sizeof(u[0]));
return str;
}
- };
- template <class CharT>
- struct duration_period<ratio<60>, CharT >
- {
- static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation)
- {
- return translation;
- }
- static std::basic_string<CharT> symbol()
+ static std::basic_string<CharT> singular()
{
- static const std::basic_string<CharT> str(1, 'm');
+ static const CharT u[] =
+ { 'h', 'o', 'u', 'r' };
+ static const std::basic_string<CharT> str(u, u + sizeof(u)
+ / sizeof(u[0]));
return str;
}
- };
- template <class CharT>
- struct duration_period<ratio<3600>, CharT >
- {
- static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation)
- {
- return translation;
- }
static std::basic_string<CharT> symbol()
{
static const std::basic_string<CharT> str(1, 'h');
@@ -136,29 +123,21 @@
}
};
-#if !defined BOOST_CHRONO_SPECIFIC_TRANSLATE
- template <class CharT, class Rep>
- std::basic_string<CharT> translate(CharT const *, std::basic_string<CharT> const &singular, std::basic_string<CharT> const &plural, Rep v)
- {
- if ( v > 1 ) return plural;
- else return singular;
- }
-#endif
template <class CharT, class Rep, class Period>
- std::basic_string<CharT> duration_unit_string(bool is_prefix, duration<Rep,Period> const& d) {
+ std::basic_string<CharT> duration_unit(bool is_prefix, duration<Rep,Period> const& d) {
if (is_prefix) {
- return duration_period<Period, CharT>::prefix(
- translate("Boost.Chrono",
- duration_period_suffix<Period, CharT>::singular(),
- duration_period_suffix<Period, CharT>::plural(),
+ duration_prefix_translate(
+ duration_unit_strings<Period, CharT>::singular(),
+ duration_unit_strings<Period, CharT>::plural(),
d.count()
- )
);
}
else
{
- return duration_period<Period, CharT>::symbol();
+ return duration_symbol_translate(
+ duration_unit_strings<Period, CharT>::symbol()
+ );
}
}
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-10-05 09:56:27 EDT (Wed, 05 Oct 2011)
@@ -18,6 +18,7 @@
#include <locale>
#include <boost/chrono/detail/scan_keyword.hpp>
#include <boost/chrono/round.hpp>
+#include <boost/chrono/io/translate.hpp>
namespace boost
{
@@ -152,7 +153,7 @@
operator<<(std::basic_ostream<CharT, Traits>& os, const time_point<Clock,
Duration>& tp)
{
- return os << tp.time_since_epoch() << clock_string<Clock, CharT>::since();
+ return os << tp.time_since_epoch() << epoch_translate(clock_string<Clock, CharT>::since());
}
template<class CharT, class Traits, class Clock, class Duration>
@@ -165,7 +166,7 @@
if (is.good())
{
const std::basic_string<CharT> units =
- clock_string<Clock, CharT>::since();
+ epoch_translate(clock_string<Clock, CharT>::since());
std::ios_base::iostate err = std::ios_base::goodbit;
typedef std::istreambuf_iterator<CharT, Traits> in_iterator;
in_iterator i(is);
Added: trunk/boost/chrono/io/translate.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/chrono/io/translate.hpp 2011-10-05 09:56:27 EDT (Wed, 05 Oct 2011)
@@ -0,0 +1,49 @@
+//
+// (C) Copyright 2010 Vicente J. Botet Escriba
+// Use, modification and distribution are subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt).
+//
+
+#ifndef BOOST_CHRONO_IO_TRANSLATE_HPP
+#define BOOST_CHRONO_IO_TRANSLATE_HPP
+
+#include <boost/chrono/config.hpp>
+#include <string>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+
+#if !defined BOOST_CHRONO_SPECIFIC_TRANSLATE
+ template <class CharT, class Rep>
+ std::basic_string<CharT> duration_prefix_translate(std::basic_string<CharT> const &singular, std::basic_string<CharT> const &plural, Rep v)
+ {
+ if ( v == 1 ) return singular;
+ if ( v == -1 ) return singular;
+ return plural;
+ }
+
+ template <class CharT, class Rep>
+ std::basic_string<CharT> duration_symbol_translate(std::basic_string<CharT> const &symbol)
+ {
+ return symbol;
+ }
+
+ template <class CharT>
+ std::basic_string<CharT> epoch_translate(std::basic_string<CharT> const &epoch)
+ {
+ return epoch;
+ }
+
+#endif
+
+
+
+ } // chrono
+
+}
+
+#endif // BOOST_CHRONO_CHRONO_IO_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk