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_LOCALIZATION_BACKEND_HPP
9 #define BOOST_LOCALE_LOCALIZATION_BACKEND_HPP
10 #include <boost/locale/config.hpp>
11 #include <boost/locale/generator.hpp>
13 # pragma warning(push)
14 # pragma warning(disable : 4275 4251 4231 4660)
25 /// \brief this class represents a localization backend that can be used for localizing your application.
27 /// Backends are usually registered inside the localization backends manager and allow transparent support
28 /// of different backends, so a user can switch the backend by simply linking the application to the correct one.
30 /// Backends may support different tuning options, but these are the default options available to the user
33 /// -# \c locale - the name of the locale in POSIX format like en_US.UTF-8
34 /// -# \c use_ansi_encoding - select system locale using ANSI codepages rather then UTF-8 under Windows
36 /// -# \c message_path - path to the location of message catalogs (vector of strings)
37 /// -# \c message_application - the name of applications that use message catalogs (vector of strings)
39 /// Each backend can be installed with a different default priotiry so when you work with two different backends, you
40 /// can specify priotiry so this backend will be chosen according to their priority.
43 class localization_backend {
44 localization_backend(localization_backend const &);
45 void operator=(localization_backend const &);
48 localization_backend()
52 virtual ~localization_backend()
57 /// Make a polymorphic copy of the backend
59 virtual localization_backend *clone() const = 0;
62 /// Set option for backend, for example "locale" or "encoding"
64 virtual void set_option(std::string const &name,std::string const &value) = 0;
69 virtual void clear_options() = 0;
72 /// Create a facet for category \a category and character type \a type
74 virtual std::locale install(std::locale const &base,locale_category_type category,character_facet_type type = nochar_facet) = 0;
76 }; // localization_backend
80 /// \brief Localization backend manager is a class that holds various backend and allows creation
81 /// of their combination or selection
84 class BOOST_LOCALE_DECL localization_backend_manager {
87 /// New empty localization_backend_manager
89 localization_backend_manager();
91 /// Copy localization_backend_manager
93 localization_backend_manager(localization_backend_manager const &);
95 /// Assign localization_backend_manager
97 localization_backend_manager const &operator=(localization_backend_manager const &);
102 ~localization_backend_manager();
105 /// Create new localization backend according to current settings.
107 std::auto_ptr<localization_backend> get() const;
110 /// Add new backend to the manager, each backend should be uniquely defined by its name.
112 /// This library provides: "icu", "posix", "winapi" and "std" backends.
114 void add_backend(std::string const &name,std::auto_ptr<localization_backend> backend);
119 void remove_all_backends();
122 /// Get list of all available backends
124 std::vector<std::string> get_all_backends() const;
127 /// Select specific backend by name for a category \a category. It allows combining different
128 /// backends for user preferences.
130 void select(std::string const &backend_name,locale_category_type category = all_categories);
133 /// Set new global backend manager, the old one is returned.
135 /// This function is thread safe
137 static localization_backend_manager global(localization_backend_manager const &);
139 /// Get global backend manager
141 /// This function is thread safe
143 static localization_backend_manager global();
146 std::auto_ptr<impl> pimpl_;
158 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4