Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:15:14

0001 //
0002 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0.
0005 // https://www.boost.org/LICENSE_1_0.txt
0006 
0007 #ifndef BOOST_LOCALE_GENERATOR_HPP
0008 #define BOOST_LOCALE_GENERATOR_HPP
0009 
0010 #include <boost/locale/hold_ptr.hpp>
0011 #include <cstdint>
0012 #include <locale>
0013 #include <memory>
0014 #include <string>
0015 
0016 #ifdef BOOST_MSVC
0017 #    pragma warning(push)
0018 #    pragma warning(disable : 4275 4251 4231 4660)
0019 #endif
0020 
0021 namespace boost {
0022 
0023 ///
0024 /// \brief This is the main namespace that encloses all localization classes
0025 ///
0026 namespace locale {
0027 
0028     class localization_backend;
0029     class localization_backend_manager;
0030 
0031     /// Type that specifies the character type that locales can be generated for
0032     ///
0033     /// Supports bitwise OR and bitwise AND (the latter returning if the type is set)
0034     enum class char_facet_t : uint32_t {
0035         nochar = 0,       ///< Unspecified character category for character independent facets
0036         char_f = 1 << 0,  ///< 8-bit character facets
0037         wchar_f = 1 << 1, ///< wide character facets
0038 #ifdef __cpp_char8_t
0039         char8_f = 1 << 2, ///< C++20 char8_t facets
0040 #endif
0041 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
0042         char16_f = 1 << 3, ///< C++11 char16_t facets
0043 #endif
0044 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
0045         char32_f = 1 << 4, ///< C++11 char32_t facets
0046 #endif
0047     };
0048     typedef BOOST_DEPRECATED("Use char_facet_t") char_facet_t character_facet_type;
0049 
0050     /// First facet specific for character type
0051     constexpr char_facet_t character_facet_first = char_facet_t::char_f;
0052     /// Last facet specific for character type
0053     constexpr char_facet_t character_facet_last =
0054 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
0055       char_facet_t::char32_f;
0056 #elif defined BOOST_LOCALE_ENABLE_CHAR16_T
0057       char_facet_t::char16_f;
0058 #elif defined __cpp_char8_t
0059       char_facet_t::char8_f;
0060 #else
0061       char_facet_t::wchar_f;
0062 #endif
0063     /// Special mask -- generate all
0064     constexpr char_facet_t all_characters = char_facet_t(0xFFFFFFFFu);
0065 
0066     /// Type used for more fine grained generation of facets
0067     ///
0068     /// Supports bitwise OR and bitwise AND (the latter returning if the type is set)
0069     enum class category_t : uint32_t {
0070         convert = 1 << 0,      ///< Generate conversion facets
0071         collation = 1 << 1,    ///< Generate collation facets
0072         formatting = 1 << 2,   ///< Generate numbers, currency, date-time formatting facets
0073         parsing = 1 << 3,      ///< Generate numbers, currency, date-time formatting facets
0074         message = 1 << 4,      ///< Generate message facets
0075         codepage = 1 << 5,     ///< Generate character set conversion facets (derived from std::codecvt)
0076         boundary = 1 << 6,     ///< Generate boundary analysis facet
0077         calendar = 1 << 16,    ///< Generate boundary analysis facet
0078         information = 1 << 17, ///< Generate general locale information facet
0079     };
0080     typedef BOOST_DEPRECATED("Use category_t") category_t locale_category_type;
0081 
0082     /// First facet specific for character
0083     constexpr category_t per_character_facet_first = category_t::convert;
0084     /// Last facet specific for character
0085     constexpr category_t per_character_facet_last = category_t::boundary;
0086     /// First character independent facet
0087     constexpr category_t non_character_facet_first = category_t::calendar;
0088     /// Last character independent facet
0089     constexpr category_t non_character_facet_last = category_t::information;
0090     /// First category facet
0091     constexpr category_t category_first = category_t::convert;
0092     /// Last category facet
0093     constexpr category_t category_last = category_t::information;
0094     /// Generate all of them
0095     constexpr category_t all_categories = category_t(0xFFFFFFFFu);
0096 
0097     /// \brief the major class used for locale generation
0098     ///
0099     /// This class is used for specification of all parameters required for locale generation and
0100     /// caching. This class const member functions are thread safe if locale class implementation is thread safe.
0101     class BOOST_LOCALE_DECL generator {
0102     public:
0103         /// Create new generator using global localization_backend_manager
0104         generator();
0105         /// Create new generator using specific localization_backend_manager
0106         generator(const localization_backend_manager&);
0107 
0108         ~generator();
0109 
0110         /// Set types of facets that should be generated, default all
0111         void categories(category_t cats);
0112         /// Get types of facets that should be generated, default all
0113         category_t categories() const;
0114 
0115         /// Set the characters type for which the facets should be generated, default all supported
0116         void characters(char_facet_t chars);
0117         /// Get the characters type for which the facets should be generated, default all supported
0118         char_facet_t characters() const;
0119 
0120         /// Add a new domain of messages that would be generated. It should be set in order to enable
0121         /// messages support.
0122         ///
0123         /// Messages domain has following format: "name" or "name/encoding"
0124         /// where name is the base name of the "mo" file where the catalog is stored
0125         /// without ".mo" extension. For example for file \c /usr/share/locale/he/LC_MESSAGES/blog.mo
0126         /// it would be \c blog.
0127         ///
0128         /// You can optionally specify the encoding of the keys in the sources by adding "/encoding_name"
0129         /// For example blog/cp1255.
0130         ///
0131         /// If not defined all keys are assumed to be UTF-8 encoded.
0132         ///
0133         /// \note When you select a domain for the program using dgettext or message API, you
0134         /// do not specify the encoding part. So for example if the provided
0135         /// domain name was "blog/windows-1255" then for translation
0136         /// you should use dgettext("blog","Hello")
0137         void add_messages_domain(const std::string& domain);
0138 
0139         /// Set default message domain. If this member was not called, the first added messages domain is used.
0140         /// If the domain \a domain is not added yet it is added.
0141         void set_default_messages_domain(const std::string& domain);
0142 
0143         /// Remove all added domains from the list
0144         void clear_domains();
0145 
0146         /// Add a search path where dictionaries are looked in.
0147         ///
0148         /// \note
0149         ///
0150         /// - Under the Windows platform the path is treated as a path in the locale's encoding so
0151         ///   if you create locale "en_US.windows-1251" then path would be treated as cp1255,
0152         ///   and if it is en_US.UTF-8 it is treated as UTF-8. File name is always opened with
0153         ///   a wide file name as wide file names are the native file name on Windows.
0154         ///
0155         /// - Under POSIX platforms all paths passed as-is regardless of encoding as narrow
0156         ///   encodings are the native encodings for POSIX platforms.
0157         ///
0158         void add_messages_path(const std::string& path);
0159 
0160         /// Remove all added paths
0161         void clear_paths();
0162 
0163         /// Remove all cached locales
0164         void clear_cache();
0165 
0166         /// Turn locale caching ON
0167         void locale_cache_enabled(bool on);
0168 
0169         /// Get locale cache option
0170         bool locale_cache_enabled() const;
0171 
0172         /// Check if by default ANSI encoding is selected or UTF-8 onces. The default is false.
0173         bool use_ansi_encoding() const;
0174 
0175         /// Select ANSI encodings as default system encoding rather then UTF-8 by default
0176         /// under Windows.
0177         ///
0178         /// The default is the most portable and most powerful encoding, UTF-8, but the user
0179         /// can select "system" one if dealing with legacy applications
0180         void use_ansi_encoding(bool enc);
0181 
0182         /// Generate a locale with id \a id
0183         std::locale generate(const std::string& id) const;
0184         /// Generate a locale with id \a id. Use \a base as a locale to which all facets are added,
0185         /// instead of std::locale::classic().
0186         std::locale generate(const std::locale& base, const std::string& id) const;
0187         /// Shortcut to generate(id)
0188         std::locale operator()(const std::string& id) const { return generate(id); }
0189 
0190     private:
0191         void set_all_options(localization_backend& backend, const std::string& id) const;
0192 
0193         generator(const generator&);
0194         void operator=(const generator&);
0195 
0196         struct data;
0197         hold_ptr<data> d;
0198     };
0199 
0200     constexpr char_facet_t operator|(const char_facet_t lhs, const char_facet_t rhs)
0201     {
0202         return char_facet_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
0203     }
0204     constexpr char_facet_t operator^(const char_facet_t lhs, const char_facet_t rhs)
0205     {
0206         return char_facet_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
0207     }
0208     constexpr bool operator&(const char_facet_t lhs, const char_facet_t rhs)
0209     {
0210         return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
0211     }
0212     // Prefix increment: Return the next value
0213     BOOST_CXX14_CONSTEXPR inline char_facet_t& operator++(char_facet_t& v)
0214     {
0215         return v = char_facet_t(static_cast<uint32_t>(v) ? static_cast<uint32_t>(v) << 1 : 1);
0216     }
0217 
0218     constexpr category_t operator|(const category_t lhs, const category_t rhs)
0219     {
0220         return category_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
0221     }
0222     constexpr category_t operator^(const category_t lhs, const category_t rhs)
0223     {
0224         return category_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
0225     }
0226     constexpr bool operator&(const category_t lhs, const category_t rhs)
0227     {
0228         return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
0229     }
0230     // Prefix increment: Return the next value
0231     BOOST_CXX14_CONSTEXPR inline category_t& operator++(category_t& v)
0232     {
0233         return v = category_t(static_cast<uint32_t>(v) << 1);
0234     }
0235 } // namespace locale
0236 } // namespace boost
0237 #ifdef BOOST_MSVC
0238 #    pragma warning(pop)
0239 #endif
0240 
0241 #endif