• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <boost/locale/hold_ptr.hpp>
21 
22 namespace boost {
23     namespace locale {
24 
25         ///
26         /// \brief this class represents a localization backend that can be used for localizing your application.
27         ///
28         /// Backends are usually registered inside the localization backends manager and allow transparent support
29         /// of different backends, so a user can switch the backend by simply linking the application to the correct one.
30         ///
31         /// Backends may support different tuning options, but these are the default options available to the user
32         /// for all of them
33         ///
34         /// -# \c locale - the name of the locale in POSIX format like en_US.UTF-8
35         /// -# \c use_ansi_encoding - select system locale using ANSI codepages rather then UTF-8 under Windows
36         ///     by default
37         /// -# \c message_path - path to the location of message catalogs (vector of strings)
38         /// -# \c message_application - the name of applications that use message catalogs (vector of strings)
39         ///
40         /// Each backend can be installed with a different default priotiry so when you work with two different backends, you
41         /// can specify priotiry so this backend will be chosen according to their priority.
42         ///
43 
44         class localization_backend {
45             localization_backend(localization_backend const &);
46             void operator=(localization_backend const &);
47         public:
48 
localization_backend()49             localization_backend()
50             {
51             }
52 
~localization_backend()53             virtual ~localization_backend()
54             {
55             }
56 
57             ///
58             /// Make a polymorphic copy of the backend
59             ///
60             virtual localization_backend *clone() const = 0;
61 
62             ///
63             /// Set option for backend, for example "locale" or "encoding"
64             ///
65             virtual void set_option(std::string const &name,std::string const &value) = 0;
66 
67             ///
68             /// Clear all options
69             ///
70             virtual void clear_options() = 0;
71 
72             ///
73             /// Create a facet for category \a category and character type \a type
74             ///
75             virtual std::locale install(std::locale const &base,locale_category_type category,character_facet_type type = nochar_facet) = 0;
76 
77         }; // localization_backend
78 
79 
80         ///
81         /// \brief Localization backend manager is a class that holds various backend and allows creation
82         /// of their combination or selection
83         ///
84 
85         class BOOST_LOCALE_DECL localization_backend_manager {
86         public:
87             ///
88             /// New empty localization_backend_manager
89             ///
90             localization_backend_manager();
91             ///
92             /// Copy localization_backend_manager
93             ///
94             localization_backend_manager(localization_backend_manager const &);
95             ///
96             /// Assign localization_backend_manager
97             ///
98             localization_backend_manager const &operator=(localization_backend_manager const &);
99 
100             ///
101             /// Destructor
102             ///
103             ~localization_backend_manager();
104 
105             #if !defined(BOOST_LOCALE_HIDE_AUTO_PTR) && !defined(BOOST_NO_AUTO_PTR)
106             ///
107             /// Create new localization backend according to current settings.
108             ///
109             std::auto_ptr<localization_backend> get() const;
110 
111             ///
112             /// Add new backend to the manager, each backend should be uniquely defined by its name.
113             ///
114             /// This library provides: "icu", "posix", "winapi" and "std" backends.
115             ///
116             void add_backend(std::string const &name,std::auto_ptr<localization_backend> backend);
117             #endif
118 
119             ///
120             /// Create new localization backend according to current settings. Ownership is passed to caller
121             ///
122             localization_backend *create() const;
123             ///
124             /// Add new backend to the manager, each backend should be uniquely defined by its name.
125             /// ownership on backend is transfered
126             ///
127             /// This library provides: "icu", "posix", "winapi" and "std" backends.
128             ///
129             void adopt_backend(std::string const &name,localization_backend *backend);
130             #ifndef BOOST_NO_CXX11_SMART_PTR
131             ///
132             /// Create new localization backend according to current settings.
133             ///
134             std::unique_ptr<localization_backend> get_unique_ptr() const;
135 
136             ///
137             /// Add new backend to the manager, each backend should be uniquely defined by its name.
138             ///
139             /// This library provides: "icu", "posix", "winapi" and "std" backends.
140             ///
141             void add_backend(std::string const &name,std::unique_ptr<localization_backend> backend);
142             #endif
143 
144             ///
145             /// Clear backend
146             ///
147             void remove_all_backends();
148 
149             ///
150             /// Get list of all available backends
151             ///
152             std::vector<std::string> get_all_backends() const;
153 
154             ///
155             /// Select specific backend by name for a category \a category. It allows combining different
156             /// backends for user preferences.
157             ///
158             void select(std::string const &backend_name,locale_category_type category = all_categories);
159 
160             ///
161             /// Set new global backend manager, the old one is returned.
162             ///
163             /// This function is thread safe
164             ///
165             static localization_backend_manager global(localization_backend_manager const &);
166             ///
167             /// Get global backend manager
168             ///
169             /// This function is thread safe
170             ///
171             static localization_backend_manager global();
172         private:
173             class impl;
174             hold_ptr<impl> pimpl_;
175         };
176 
177     } // locale
178 } // boost
179 
180 
181 #ifdef BOOST_MSVC
182 #pragma warning(pop)
183 #endif
184 
185 #endif
186 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
187 
188