|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65500 - sandbox/chrono/boost/ratio
From: vicente.botet_at_[hidden]
Date: 2010-09-21 00:48:45
Author: viboes
Date: 2010-09-21 00:48:42 EDT (Tue, 21 Sep 2010)
New Revision: 65500
URL: http://svn.boost.org/trac/boost/changeset/65500
Log:
Added ratio_io.hpp
Added:
sandbox/chrono/boost/ratio/ratio_io.hpp (contents, props changed)
Added: sandbox/chrono/boost/ratio/ratio_io.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/ratio/ratio_io.hpp 2010-09-21 00:48:42 EDT (Tue, 21 Sep 2010)
@@ -0,0 +1,644 @@
+// ratio_io
+//
+// (C) Copyright Howard Hinnant
+// (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).
+//
+// This code was adapted by Vicente from Howard Hinnant's experimental work
+// on chrono i/o under lvm/libc++ to Boost
+
+#ifndef BOOST_RATIO_RATIO_IO_HPP
+#define BOOST_RATIO_RATIO_IO_HPP
+
+/*
+
+ ratio_io synopsis
+
+#include <ratio>
+#include <string>
+
+namespace std
+{
+
+template <class Ratio, class CharT>
+struct ratio_string
+{
+ static basic_string<CharT> short_name();
+ static basic_string<CharT> long_name();
+};
+
+} // std
+
+*/
+
+#include <boost/ratio.hpp>
+#include <boost/config.hpp>
+#include <string>
+#include <sstream>
+
+
+#if defined(BOOST_NO_UNICODE_LITERALS) || defined(BOOST_NO_CHAR16_T) || defined(BOOST_NO_CHAR32_T)
+//~ #define BOOST_HAS_UNICODE_SUPPORT
+#else
+#define BOOST_HAS_UNICODE_SUPPORT 1
+#endif
+namespace boost {
+
+template <class Ratio, class CharT>
+struct ratio_string
+{
+ static std::basic_string<CharT> short_name() {return long_name();}
+ static std::basic_string<CharT> long_name();
+};
+
+template <class Ratio, class CharT>
+std::basic_string<CharT>
+ratio_string<Ratio, CharT>::long_name()
+{
+ std::basic_ostringstream<CharT> os;
+ os << CharT('[') << Ratio::num << CharT('/')
+ << Ratio::den << CharT(']');
+ return os.str();
+}
+
+// atto
+
+template <>
+struct ratio_string<atto, char>
+{
+ static std::string short_name() {return std::string(1, 'a');}
+ static std::string long_name() {return std::string("atto");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<atto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'a');}
+ static std::u16string long_name() {return std::u16string(u"atto");}
+};
+
+template <>
+struct ratio_string<atto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'a');}
+ static std::u32string long_name() {return std::u32string(U"atto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<atto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'a');}
+ static std::wstring long_name() {return std::wstring(L"atto");}
+};
+#endif
+
+// femto
+
+template <>
+struct ratio_string<femto, char>
+{
+ static std::string short_name() {return std::string(1, 'f');}
+ static std::string long_name() {return std::string("femto");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<femto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'f');}
+ static std::u16string long_name() {return std::u16string(u"femto");}
+};
+
+template <>
+struct ratio_string<femto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'f');}
+ static std::u32string long_name() {return std::u32string(U"femto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<femto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'f');}
+ static std::wstring long_name() {return std::wstring(L"femto");}
+};
+#endif
+
+// pico
+
+template <>
+struct ratio_string<pico, char>
+{
+ static std::string short_name() {return std::string(1, 'p');}
+ static std::string long_name() {return std::string("pico");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<pico, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'p');}
+ static std::u16string long_name() {return std::u16string(u"pico");}
+};
+
+template <>
+struct ratio_string<pico, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'p');}
+ static std::u32string long_name() {return std::u32string(U"pico");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<pico, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'p');}
+ static std::wstring long_name() {return std::wstring(L"pico");}
+};
+#endif
+
+// nano
+
+template <>
+struct ratio_string<nano, char>
+{
+ static std::string short_name() {return std::string(1, 'n');}
+ static std::string long_name() {return std::string("nano");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<nano, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'n');}
+ static std::u16string long_name() {return std::u16string(u"nano");}
+};
+
+template <>
+struct ratio_string<nano, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'n');}
+ static std::u32string long_name() {return std::u32string(U"nano");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<nano, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'n');}
+ static std::wstring long_name() {return std::wstring(L"nano");}
+};
+#endif
+
+// micro
+
+template <>
+struct ratio_string<micro, char>
+{
+ static std::string short_name() {return std::string("\xC2\xB5");}
+ static std::string long_name() {return std::string("micro");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<micro, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'\xB5');}
+ static std::u16string long_name() {return std::u16string(u"micro");}
+};
+
+template <>
+struct ratio_string<micro, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'\xB5');}
+ static std::u32string long_name() {return std::u32string(U"micro");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<micro, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'\xB5');}
+ static std::wstring long_name() {return std::wstring(L"micro");}
+};
+#endif
+
+// milli
+
+template <>
+struct ratio_string<milli, char>
+{
+ static std::string short_name() {return std::string(1, 'm');}
+ static std::string long_name() {return std::string("milli");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<milli, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'm');}
+ static std::u16string long_name() {return std::u16string(u"milli");}
+};
+
+template <>
+struct ratio_string<milli, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'm');}
+ static std::u32string long_name() {return std::u32string(U"milli");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<milli, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'm');}
+ static std::wstring long_name() {return std::wstring(L"milli");}
+};
+#endif
+
+// centi
+
+template <>
+struct ratio_string<centi, char>
+{
+ static std::string short_name() {return std::string(1, 'c');}
+ static std::string long_name() {return std::string("centi");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<centi, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'c');}
+ static std::u16string long_name() {return std::u16string(u"centi");}
+};
+
+template <>
+struct ratio_string<centi, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'c');}
+ static std::u32string long_name() {return std::u32string(U"centi");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<centi, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'c');}
+ static std::wstring long_name() {return std::wstring(L"centi");}
+};
+#endif
+
+// deci
+
+template <>
+struct ratio_string<deci, char>
+{
+ static std::string short_name() {return std::string(1, 'd');}
+ static std::string long_name() {return std::string("deci");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<deci, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'd');}
+ static std::u16string long_name() {return std::u16string(u"deci");}
+};
+
+template <>
+struct ratio_string<deci, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'd');}
+ static std::u32string long_name() {return std::u32string(U"deci");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<deci, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'd');}
+ static std::wstring long_name() {return std::wstring(L"deci");}
+};
+#endif
+
+// deca
+
+template <>
+struct ratio_string<deca, char>
+{
+ static std::string short_name() {return std::string("da");}
+ static std::string long_name() {return std::string("deca");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<deca, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(u"da");}
+ static std::u16string long_name() {return std::u16string(u"deca");}
+};
+
+template <>
+struct ratio_string<deca, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(U"da");}
+ static std::u32string long_name() {return std::u32string(U"deca");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<deca, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(L"da");}
+ static std::wstring long_name() {return std::wstring(L"deca");}
+};
+#endif
+
+// hecto
+
+template <>
+struct ratio_string<hecto, char>
+{
+ static std::string short_name() {return std::string(1, 'h');}
+ static std::string long_name() {return std::string("hecto");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<hecto, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'h');}
+ static std::u16string long_name() {return std::u16string(u"hecto");}
+};
+
+template <>
+struct ratio_string<hecto, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'h');}
+ static std::u32string long_name() {return std::u32string(U"hecto");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<hecto, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'h');}
+ static std::wstring long_name() {return std::wstring(L"hecto");}
+};
+#endif
+
+// kilo
+
+template <>
+struct ratio_string<kilo, char>
+{
+ static std::string short_name() {return std::string(1, 'k');}
+ static std::string long_name() {return std::string("kilo");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<kilo, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'k');}
+ static std::u16string long_name() {return std::u16string(u"kilo");}
+};
+
+template <>
+struct ratio_string<kilo, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'k');}
+ static std::u32string long_name() {return std::u32string(U"kilo");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<kilo, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'k');}
+ static std::wstring long_name() {return std::wstring(L"kilo");}
+};
+#endif
+
+// mega
+
+template <>
+struct ratio_string<mega, char>
+{
+ static std::string short_name() {return std::string(1, 'M');}
+ static std::string long_name() {return std::string("mega");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<mega, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'M');}
+ static std::u16string long_name() {return std::u16string(u"mega");}
+};
+
+template <>
+struct ratio_string<mega, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'M');}
+ static std::u32string long_name() {return std::u32string(U"mega");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<mega, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'M');}
+ static std::wstring long_name() {return std::wstring(L"mega");}
+};
+#endif
+
+// giga
+
+template <>
+struct ratio_string<giga, char>
+{
+ static std::string short_name() {return std::string(1, 'G');}
+ static std::string long_name() {return std::string("giga");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<giga, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'G');}
+ static std::u16string long_name() {return std::u16string(u"giga");}
+};
+
+template <>
+struct ratio_string<giga, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'G');}
+ static std::u32string long_name() {return std::u32string(U"giga");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<giga, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'G');}
+ static std::wstring long_name() {return std::wstring(L"giga");}
+};
+#endif
+
+// tera
+
+template <>
+struct ratio_string<tera, char>
+{
+ static std::string short_name() {return std::string(1, 'T');}
+ static std::string long_name() {return std::string("tera");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<tera, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'T');}
+ static std::u16string long_name() {return std::u16string(u"tera");}
+};
+
+template <>
+struct ratio_string<tera, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'T');}
+ static std::u32string long_name() {return std::u32string(U"tera");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<tera, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'T');}
+ static std::wstring long_name() {return std::wstring(L"tera");}
+};
+#endif
+
+// peta
+
+template <>
+struct ratio_string<peta, char>
+{
+ static std::string short_name() {return std::string(1, 'P');}
+ static std::string long_name() {return std::string("peta");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<peta, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'P');}
+ static std::u16string long_name() {return std::u16string(u"peta");}
+};
+
+template <>
+struct ratio_string<peta, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'P');}
+ static std::u32string long_name() {return std::u32string(U"peta");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<peta, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'P');}
+ static std::wstring long_name() {return std::wstring(L"peta");}
+};
+#endif
+
+// exa
+
+template <>
+struct ratio_string<exa, char>
+{
+ static std::string short_name() {return std::string(1, 'E');}
+ static std::string long_name() {return std::string("exa");}
+};
+
+#if BOOST_HAS_UNICODE_SUPPORT
+
+template <>
+struct ratio_string<exa, char16_t>
+{
+ static std::u16string short_name() {return std::u16string(1, u'E');}
+ static std::u16string long_name() {return std::u16string(u"exa");}
+};
+
+template <>
+struct ratio_string<exa, char32_t>
+{
+ static std::u32string short_name() {return std::u32string(1, U'E');}
+ static std::u32string long_name() {return std::u32string(U"exa");}
+};
+
+#endif
+
+#ifndef BOOST_NO_STD_WSTRING
+template <>
+struct ratio_string<exa, wchar_t>
+{
+ static std::wstring short_name() {return std::wstring(1, L'E');}
+ static std::wstring long_name() {return std::wstring(L"exa");}
+};
+#endif
+
+}
+
+#endif // BOOST_RATIO_RATIO_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