Boost.Locale
generator.hpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // https://www.boost.org/LICENSE_1_0.txt
6 
7 #ifndef BOOST_LOCALE_GENERATOR_HPP
8 #define BOOST_LOCALE_GENERATOR_HPP
9 #include <boost/locale/config.hpp>
10 #include <boost/locale/hold_ptr.hpp>
11 #include <boost/cstdint.hpp>
12 #include <locale>
13 #include <memory>
14 #include <string>
15 
16 #ifdef BOOST_MSVC
17 # pragma warning(push)
18 # pragma warning(disable : 4275 4251 4231 4660)
19 #endif
20 
21 namespace boost {
22 
26 namespace locale {
27 
28  class localization_backend;
29  class localization_backend_manager;
30 
34  enum class char_facet_t : uint32_t {
35  nochar = 0,
36  char_f = 1 << 0,
37  wchar_f = 1 << 1,
38 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
39  char16_f = 1 << 2,
40 #endif
41 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
42  char32_f = 1 << 3,
43 #endif
44  };
45  typedef BOOST_DEPRECATED("Use char_facet_t") char_facet_t character_facet_type;
46 
51 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
53 #elif defined BOOST_LOCALE_ENABLE_CHAR16_T
55 #else
57 #endif
58  constexpr char_facet_t all_characters = char_facet_t(0xFFFFFFFFu);
60 
64  enum class category_t : uint32_t {
65  convert = 1 << 0,
66  collation = 1 << 1,
67  formatting = 1 << 2,
68  parsing = 1 << 3,
69  message = 1 << 4,
70  codepage = 1 << 5,
71  boundary = 1 << 6,
72  calendar = 1 << 16,
73  information = 1 << 17,
74  };
75  typedef BOOST_DEPRECATED("Use category_t") category_t locale_category_type;
76 
86  constexpr category_t category_first = category_t::convert;
88  constexpr category_t category_last = category_t::information;
90  constexpr category_t all_categories = category_t(0xFFFFFFFFu);
91 
96  class BOOST_LOCALE_DECL generator {
97  public:
99  generator();
102 
103  ~generator();
104 
106  void categories(category_t cats);
108  category_t categories() const;
109 
111  void characters(char_facet_t chars);
113  char_facet_t characters() const;
114 
132  void add_messages_domain(const std::string& domain);
133 
136  void set_default_messages_domain(const std::string& domain);
137 
139  void clear_domains();
140 
153  void add_messages_path(const std::string& path);
154 
156  void clear_paths();
157 
159  void clear_cache();
160 
162  void locale_cache_enabled(bool on);
163 
165  bool locale_cache_enabled() const;
166 
168  bool use_ansi_encoding() const;
169 
175  void use_ansi_encoding(bool enc);
176 
178  std::locale generate(const std::string& id) const;
181  std::locale generate(const std::locale& base, const std::string& id) const;
183  std::locale operator()(const std::string& id) const { return generate(id); }
184 
186  void set_option(const std::string& name, const std::string& value);
187 
189  void clear_options();
190 
191  private:
192  void set_all_options(localization_backend& backend, const std::string& id) const;
193 
194  generator(const generator&);
195  void operator=(const generator&);
196 
197  struct data;
198  hold_ptr<data> d;
199  };
200 
201  constexpr char_facet_t operator|(const char_facet_t lhs, const char_facet_t rhs)
202  {
203  return char_facet_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
204  }
205  constexpr char_facet_t operator^(const char_facet_t lhs, const char_facet_t rhs)
206  {
207  return char_facet_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
208  }
209  constexpr bool operator&(const char_facet_t lhs, const char_facet_t rhs)
210  {
211  return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
212  }
213  // Prefix increment: Return the next value
214  BOOST_CXX14_CONSTEXPR inline char_facet_t& operator++(char_facet_t& v)
215  {
216  return v = char_facet_t(static_cast<uint32_t>(v) ? static_cast<uint32_t>(v) << 1 : 1);
217  }
218 
219  constexpr category_t operator|(const category_t lhs, const category_t rhs)
220  {
221  return category_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
222  }
223  constexpr category_t operator^(const category_t lhs, const category_t rhs)
224  {
225  return category_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
226  }
227  constexpr bool operator&(const category_t lhs, const category_t rhs)
228  {
229  return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
230  }
231  // Prefix increment: Return the next value
232  BOOST_CXX14_CONSTEXPR inline category_t& operator++(category_t& v)
233  {
234  return v = category_t(static_cast<uint32_t>(v) << 1);
235  }
236 } // namespace locale
237 } // namespace boost
238 #ifdef BOOST_MSVC
239 # pragma warning(pop)
240 #endif
241 
242 #endif
constexpr category_t per_character_facet_first
First facet specific for character.
Definition: generator.hpp:78
Unspecified character category for character independent facets.
Localization backend manager is a class that holds various backend and allows creation of their combi...
Definition: localization_backend.hpp:66
category_t
Definition: generator.hpp:64
constexpr category_t per_character_facet_last
Last facet specific for character.
Definition: generator.hpp:80
constexpr char_facet_t character_facet_first
First facet specific for character type.
Definition: generator.hpp:48
This class represents a message that can be converted to a specific locale message.
Definition: message.hpp:142
char_facet_t
Definition: generator.hpp:34
Generate general locale information facet.
Generate conversion facets.
this class provides an access to general calendar information.
Definition: date_time.hpp:469
this class represents a localization backend that can be used for localizing your application.
Definition: localization_backend.hpp:41
Generate numbers, currency, date-time formatting facets.
constexpr category_t non_character_facet_first
First character independent facet.
Definition: generator.hpp:82
unspecified_type domain(const std::string &id)
Definition: message.hpp:575
Generate numbers, currency, date-time formatting facets.
constexpr char_facet_t character_facet_last
Last facet specific for character type.
Definition: generator.hpp:50
constexpr category_t category_first
First category facet.
Definition: generator.hpp:86
constexpr char_facet_t all_characters
Special mask – generate all.
Definition: generator.hpp:59
Generate collation facets.
std::locale operator()(const std::string &id) const
Shortcut to generate(id)
Definition: generator.hpp:183
Generate character set conversion facets (derived from std::codecvt)
constexpr category_t category_last
Last category facet.
Definition: generator.hpp:88
constexpr category_t non_character_facet_last
Last character independent facet.
Definition: generator.hpp:84
the major class used for locale generation
Definition: generator.hpp:96
constexpr category_t all_categories
Generate all of them.
Definition: generator.hpp:90
Generate boundary analysis facet.