1 // 2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) 3 // 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) 7 // 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> 12 #ifdef BOOST_MSVC 13 # pragma warning(push) 14 # pragma warning(disable : 4275 4251 4231 4660) 15 #endif 16 #include <string> 17 #include <locale> 18 #include <vector> 19 #include <memory> 20 21 namespace boost { 22 namespace locale { 23 24 /// 25 /// \brief this class represents a localization backend that can be used for localizing your application. 26 /// 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. 29 /// 30 /// Backends may support different tuning options, but these are the default options available to the user 31 /// for all of them 32 /// 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 35 /// by default 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) 38 /// 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. 41 /// 42 43 class localization_backend { 44 localization_backend(localization_backend const &); 45 void operator=(localization_backend const &); 46 public: 47 localization_backend()48 localization_backend() 49 { 50 } 51 ~localization_backend()52 virtual ~localization_backend() 53 { 54 } 55 56 /// 57 /// Make a polymorphic copy of the backend 58 /// 59 virtual localization_backend *clone() const = 0; 60 61 /// 62 /// Set option for backend, for example "locale" or "encoding" 63 /// 64 virtual void set_option(std::string const &name,std::string const &value) = 0; 65 66 /// 67 /// Clear all options 68 /// 69 virtual void clear_options() = 0; 70 71 /// 72 /// Create a facet for category \a category and character type \a type 73 /// 74 virtual std::locale install(std::locale const &base,locale_category_type category,character_facet_type type = nochar_facet) = 0; 75 76 }; // localization_backend 77 78 79 /// 80 /// \brief Localization backend manager is a class that holds various backend and allows creation 81 /// of their combination or selection 82 /// 83 84 class BOOST_LOCALE_DECL localization_backend_manager { 85 public: 86 /// 87 /// New empty localization_backend_manager 88 /// 89 localization_backend_manager(); 90 /// 91 /// Copy localization_backend_manager 92 /// 93 localization_backend_manager(localization_backend_manager const &); 94 /// 95 /// Assign localization_backend_manager 96 /// 97 localization_backend_manager const &operator=(localization_backend_manager const &); 98 99 /// 100 /// Destructor 101 /// 102 ~localization_backend_manager(); 103 104 /// 105 /// Create new localization backend according to current settings. 106 /// 107 std::auto_ptr<localization_backend> get() const; 108 109 /// 110 /// Add new backend to the manager, each backend should be uniquely defined by its name. 111 /// 112 /// This library provides: "icu", "posix", "winapi" and "std" backends. 113 /// 114 void add_backend(std::string const &name,std::auto_ptr<localization_backend> backend); 115 116 /// 117 /// Clear backend 118 /// 119 void remove_all_backends(); 120 121 /// 122 /// Get list of all available backends 123 /// 124 std::vector<std::string> get_all_backends() const; 125 126 /// 127 /// Select specific backend by name for a category \a category. It allows combining different 128 /// backends for user preferences. 129 /// 130 void select(std::string const &backend_name,locale_category_type category = all_categories); 131 132 /// 133 /// Set new global backend manager, the old one is returned. 134 /// 135 /// This function is thread safe 136 /// 137 static localization_backend_manager global(localization_backend_manager const &); 138 /// 139 /// Get global backend manager 140 /// 141 /// This function is thread safe 142 /// 143 static localization_backend_manager global(); 144 private: 145 class impl; 146 std::auto_ptr<impl> pimpl_; 147 }; 148 149 } // locale 150 } // boost 151 152 153 #ifdef BOOST_MSVC 154 #pragma warning(pop) 155 #endif 156 157 #endif 158 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 159 160