1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// french.cpp ----------------------------------------------------------//
// Copyright 2010 Howard Hinnant
// Copyright 2011 Vicente J. Botet Escriba
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Adapted to Boost from the original Hawards's code
#include <boost/chrono/config.hpp>
#include <boost/chrono/chrono_io.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
#include <boost/chrono/thread_clock.hpp>
#include <iostream>
#include <locale>
#if BOOST_CHRONO_VERSION==2
#include <boost/chrono/io/duration_units.hpp>
using namespace boost;
using namespace boost::chrono;
template <typename CharT=char>
class duration_units_fr: public duration_units_default<CharT>
{
public:
typedef CharT char_type;
explicit duration_units_fr(size_t refs = 0) :
duration_units_default<CharT>(refs)
{
}
protected:
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;
}
std::basic_string<CharT> do_get_unit(duration_style style, ratio<1> , std::size_t pf) const
{
static const CharT t[] =
{ 's' };
static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
static const CharT u[] =
{ 's', 'e', 'c', 'o', 'n', 'd', 'e' };
static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
static const CharT v[] =
{ 's', 'e', 'c', 'o', 'n', 'd', 'e', 's' };
static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
if (style == duration_style::symbol) return symbol;
if (pf == 0) return singular;
if (pf == 1) return plural;
// assert
//throw "exception";
return "";
}
std::basic_string<CharT> do_get_unit(duration_style style, ratio<60> , std::size_t pf) const
{
static const CharT t[] =
{ 'm', 'i', 'n' };
static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
static const CharT u[] =
{ 'm', 'i', 'n', 'u', 't', 'e' };
static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
static const CharT v[] =
{ 'm', 'i', 'n', 'u', 't', 'e', 's' };
static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
if (style == duration_style::symbol) return symbol;
if (pf == 0) return singular;
if (pf == 1) return plural;
// assert
//throw "exception";
return "";
}
std::basic_string<CharT> do_get_unit(duration_style style, ratio<3600> , std::size_t pf) const
{
static const CharT t[] =
{ 'h' };
static const std::basic_string<CharT> symbol(t, t + sizeof (t) / sizeof (t[0]));
static const CharT u[] =
{ 'h', 'e', 'u', 'r', 'e' };
static const std::basic_string<CharT> singular(u, u + sizeof (u) / sizeof (u[0]));
static const CharT v[] =
{ 'h', 'e', 'u', 'r', 'e', 's' };
static const std::basic_string<CharT> plural(v, v + sizeof (v) / sizeof (v[0]));
if (style == duration_style::symbol) return symbol;
if (pf == 0) return singular;
if (pf == 1) return plural;
// assert
//throw "exception";
return "";
}
};
#endif
int main()
{
using std::cout;
using std::locale;
using namespace boost;
using namespace boost::chrono;
#if BOOST_CHRONO_VERSION==2
cout.imbue(locale(locale(), new duration_units_fr<>()));
#else
cout.imbue(locale(locale(), new duration_punct<char>
(
duration_punct<char>::use_long,
"secondes", "minutes", "heures",
"s", "m", "h"
)));
#endif
hours h(5);
minutes m(45);
seconds s(15);
milliseconds ms(763);
cout << h << ", " << m << ", " << s << " et " << ms << '\n';
cout << hours(0) << ", " << minutes(0) << ", " << s << " et " << ms << '\n';
return 0;
}
|