Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:16

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_LOCALIZATION_BACKEND_HPP
0008 #define BOOST_LOCALE_LOCALIZATION_BACKEND_HPP
0009 
0010 #include <boost/locale/generator.hpp>
0011 #include <boost/locale/hold_ptr.hpp>
0012 #include <locale>
0013 #include <memory>
0014 #include <string>
0015 #include <vector>
0016 
0017 #ifdef BOOST_MSVC
0018 #    pragma warning(push)
0019 #    pragma warning(disable : 4275 4251 4231 4660)
0020 #endif
0021 
0022 namespace boost { namespace locale {
0023 
0024     /// \brief this class represents a localization backend that can be used for localizing your application.
0025     ///
0026     /// Backends are usually registered inside the localization backends manager and allow transparent support
0027     /// of different backends, so a user can switch the backend by simply linking the application to the correct one.
0028     ///
0029     /// Backends may support different tuning options, but these are the default options available to the user
0030     /// for all of them
0031     ///
0032     /// -# \c locale - the name of the locale in POSIX format like en_US.UTF-8
0033     /// -# \c use_ansi_encoding - select system locale using ANSI codepages rather then UTF-8 under Windows
0034     ///     by default
0035     /// -# \c message_path - path to the location of message catalogs (vector of strings)
0036     /// -# \c message_application - the name of applications that use message catalogs (vector of strings)
0037     ///
0038     /// Each backend can be installed with a different default priority so when you work with two different backends,
0039     /// you can specify priority so this backend will be chosen according to their priority.
0040     class BOOST_LOCALE_DECL localization_backend {
0041     protected:
0042         localization_backend(const localization_backend&) = default;
0043         localization_backend& operator=(const localization_backend&) = default;
0044 
0045     public:
0046         localization_backend() = default;
0047         virtual ~localization_backend();
0048 
0049         /// Make a polymorphic copy of the backend
0050         virtual localization_backend* clone() const = 0;
0051 
0052         /// Set option for backend, for example "locale" or "encoding"
0053         virtual void set_option(const std::string& name, const std::string& value) = 0;
0054 
0055         /// Clear all options
0056         virtual void clear_options() = 0;
0057 
0058         /// Create a facet for category \a category and character type \a type
0059         virtual std::locale install(const std::locale& base, category_t category, char_facet_t type) = 0;
0060 
0061     }; // localization_backend
0062 
0063     /// \brief Localization backend manager is a class that holds various backend and allows creation
0064     /// of their combination or selection
0065     class BOOST_LOCALE_DECL localization_backend_manager {
0066     public:
0067         /// New empty localization_backend_manager
0068         localization_backend_manager();
0069         /// Copy localization_backend_manager
0070         localization_backend_manager(const localization_backend_manager&);
0071         /// Assign localization_backend_manager
0072         localization_backend_manager& operator=(const localization_backend_manager&);
0073         /// Move construct localization_backend_manager
0074         localization_backend_manager(localization_backend_manager&&) noexcept;
0075         /// Move assign localization_backend_manager
0076         localization_backend_manager& operator=(localization_backend_manager&&) noexcept;
0077 
0078         /// Destructor
0079         ~localization_backend_manager();
0080 
0081         /// Create new localization backend according to current settings. Ownership is passed to caller
0082         std::unique_ptr<localization_backend> create() const;
0083 
0084         BOOST_DEPRECATED("This function is deprecated, use 'create()' instead")
0085         std::unique_ptr<localization_backend> get() const { return create(); } // LCOV_EXCL_LINE
0086         BOOST_DEPRECATED("This function is deprecated, use 'create()' instead")
0087         std::unique_ptr<localization_backend> get_unique_ptr() const { return create(); } // LCOV_EXCL_LINE
0088 
0089         /// Add new backend to the manager, each backend should be uniquely defined by its name.
0090         ///
0091         /// This library provides: "icu", "posix", "winapi" and "std" backends.
0092         void add_backend(const std::string& name, std::unique_ptr<localization_backend> backend);
0093 
0094         // clang-format off
0095         BOOST_DEPRECATED("This function is deprecated, use 'add_backend' instead")
0096         void adopt_backend(const std::string& name, localization_backend* backend) { add_backend(name, std::unique_ptr<localization_backend>(backend)); } // LCOV_EXCL_LINE
0097         // clang-format on
0098 
0099         /// Clear backend
0100         void remove_all_backends();
0101 
0102         /// Get list of all available backends
0103         std::vector<std::string> get_all_backends() const;
0104 
0105         /// Select specific backend by name for a category \a category. It allows combining different
0106         /// backends for user preferences.
0107         void select(const std::string& backend_name, category_t category = all_categories);
0108 
0109         /// Set new global backend manager, the old one is returned.
0110         ///
0111         /// This function is thread safe
0112         static localization_backend_manager global(const localization_backend_manager&);
0113         /// Get global backend manager
0114         ///
0115         /// This function is thread safe
0116         static localization_backend_manager global();
0117 
0118     private:
0119         class impl;
0120         hold_ptr<impl> pimpl_;
0121     };
0122 
0123 }} // namespace boost::locale
0124 
0125 #ifdef BOOST_MSVC
0126 #    pragma warning(pop)
0127 #endif
0128 
0129 #endif