2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_LOCALE_FORMATTER_HPP_INCLUDED
9 #define BOOST_LOCALE_FORMATTER_HPP_INCLUDED
13 #include <boost/cstdint.hpp>
14 #include <boost/locale/config.hpp>
15 #include <unicode/locid.h>
22 /// \brief Special base polymorphic class that is used as a character type independent base for all formatter classes
25 class base_formatter {
27 virtual ~base_formatter()
33 /// \brief A class that is used for formatting numbers, currency and dates/times
35 template<typename CharType>
36 class formatter : public base_formatter {
38 typedef CharType char_type;
39 typedef std::basic_string<CharType> string_type;
42 /// Format the value and return the number of Unicode code points
44 virtual string_type format(double value,size_t &code_points) const = 0;
46 /// Format the value and return the number of Unicode code points
48 virtual string_type format(int64_t value,size_t &code_points) const = 0;
50 /// Format the value and return the number of Unicode code points
52 virtual string_type format(int32_t value,size_t &code_points) const = 0;
55 /// Parse the string and return the number of used characters. If it returns 0
56 /// then parsing failed.
58 virtual size_t parse(string_type const &str,double &value) const = 0;
60 /// Parse the string and return the number of used characters. If it returns 0
61 /// then parsing failed.
63 virtual size_t parse(string_type const &str,int64_t &value) const = 0;
65 /// Parse the string and return the number of used characters. If it returns 0
66 /// then parsing failed.
68 virtual size_t parse(string_type const &str,int32_t &value) const = 0;
71 /// Get formatter for the current state of ios_base -- flags and locale,
72 /// NULL may be returned if an invalid combination of flags is provided or this type
73 /// of formatting is not supported by locale. See: create
75 /// Note: formatter is cached. If \a ios is not changed (no flags or locale changed)
76 /// the formatter would remain the same. Otherwise it would be rebuild and cached
77 /// for future use. It is useful for saving time for generation
78 /// of multiple values with same locale.
80 /// For example, this code:
83 /// std::cout << as::spellout;
84 /// for(int i=1;i<=10;i++)
85 /// std::cout << i <<std::endl;
88 /// Would create a new spelling formatter only once.
90 static std::auto_ptr<formatter> create(std::ios_base &ios,icu::Locale const &l,std::string const &enc);
98 /// Specialization for real implementation
101 std::auto_ptr<formatter<char> > formatter<char>::create(std::ios_base &ios,icu::Locale const &l,std::string const &enc);
104 /// Specialization for real implementation
107 std::auto_ptr<formatter<wchar_t> > formatter<wchar_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
109 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
111 /// Specialization for real implementation
114 std::auto_ptr<formatter<char16_t> > formatter<char16_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
117 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
119 /// Specialization for real implementation
122 std::auto_ptr<formatter<char32_t> > formatter<char32_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
125 } // namespace impl_icu
126 } // namespace locale
132 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4