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
10#include <boost/locale/hold_ptr.hpp>
11#include <cstdint>
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
21namespace boost {
22
26namespace 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 __cpp_char8_t
39 char8_f = 1 << 2,
40#endif
41#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
42 char16_f = 1 << 3,
43#endif
44#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
45 char32_f = 1 << 4,
46#endif
47 };
48 typedef BOOST_DEPRECATED("Use char_facet_t") char_facet_t character_facet_type;
49
54#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
56#elif defined BOOST_LOCALE_ENABLE_CHAR16_T
58#elif defined __cpp_char8_t
59 char_facet_t::char8_f;
60#else
62#endif
64 constexpr char_facet_t all_characters = char_facet_t(0xFFFFFFFFu);
65
69 enum class category_t : uint32_t {
70 convert = 1 << 0,
71 collation = 1 << 1,
72 formatting = 1 << 2,
73 parsing = 1 << 3,
74 message = 1 << 4,
75 codepage = 1 << 5,
76 boundary = 1 << 6,
77 calendar = 1 << 16,
78 information = 1 << 17,
79 };
80 typedef BOOST_DEPRECATED("Use category_t") category_t locale_category_type;
81
95 constexpr category_t all_categories = category_t(0xFFFFFFFFu);
96
101 class BOOST_LOCALE_DECL generator {
102 public:
107
108 ~generator();
109
114
119
137 void add_messages_domain(const std::string& domain);
138
141 void set_default_messages_domain(const std::string& domain);
142
145
158 void add_messages_path(const std::string& path);
159
162
165
167 void locale_cache_enabled(bool on);
168
171
173 bool use_ansi_encoding() const;
174
180 void use_ansi_encoding(bool enc);
181
183 std::locale generate(const std::string& id) const;
186 std::locale generate(const std::locale& base, const std::string& id) const;
188 std::locale operator()(const std::string& id) const { return generate(id); }
189
190 private:
191 void set_all_options(localization_backend& backend, const std::string& id) const;
192
193 generator(const generator&);
194 void operator=(const generator&);
195
196 struct data;
198 };
199
200 constexpr char_facet_t operator|(const char_facet_t lhs, const char_facet_t rhs)
201 {
202 return char_facet_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
203 }
204 constexpr char_facet_t operator^(const char_facet_t lhs, const char_facet_t rhs)
205 {
206 return char_facet_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
207 }
208 constexpr bool operator&(const char_facet_t lhs, const char_facet_t rhs)
209 {
210 return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
211 }
212 // Prefix increment: Return the next value
213 BOOST_CXX14_CONSTEXPR inline char_facet_t& operator++(char_facet_t& v)
214 {
215 return v = char_facet_t(static_cast<uint32_t>(v) ? static_cast<uint32_t>(v) << 1 : 1);
216 }
217
218 constexpr category_t operator|(const category_t lhs, const category_t rhs)
219 {
220 return category_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
221 }
222 constexpr category_t operator^(const category_t lhs, const category_t rhs)
223 {
224 return category_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
225 }
226 constexpr bool operator&(const category_t lhs, const category_t rhs)
227 {
228 return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
229 }
230 // Prefix increment: Return the next value
231 BOOST_CXX14_CONSTEXPR inline category_t& operator++(category_t& v)
232 {
233 return v = category_t(static_cast<uint32_t>(v) << 1);
234 }
235} // namespace locale
236} // namespace boost
237#ifdef BOOST_MSVC
238# pragma warning(pop)
239#endif
240
241#endif
This class represents a message that can be converted to a specific locale message.
Definition: message.hpp:142
this class provides an access to general calendar information.
Definition: date_time.hpp:466
the major class used for locale generation
Definition: generator.hpp:101
generator(const localization_backend_manager &)
Create new generator using specific localization_backend_manager.
char_facet_t characters() const
Get the characters type for which the facets should be generated, default all supported.
std::locale generate(const std::locale &base, const std::string &id) const
generator()
Create new generator using global localization_backend_manager.
void add_messages_path(const std::string &path)
void clear_cache()
Remove all cached locales.
std::locale operator()(const std::string &id) const
Shortcut to generate(id)
Definition: generator.hpp:188
bool locale_cache_enabled() const
Get locale cache option.
void set_default_messages_domain(const std::string &domain)
void locale_cache_enabled(bool on)
Turn locale caching ON.
void categories(category_t cats)
Set types of facets that should be generated, default all.
void use_ansi_encoding(bool enc)
void clear_domains()
Remove all added domains from the list.
void clear_paths()
Remove all added paths.
void add_messages_domain(const std::string &domain)
category_t categories() const
Get types of facets that should be generated, default all.
bool use_ansi_encoding() const
Check if by default ANSI encoding is selected or UTF-8 onces. The default is false.
std::locale generate(const std::string &id) const
Generate a locale with id id.
void characters(char_facet_t chars)
Set the characters type for which the facets should be generated, default all supported.
a smart pointer similar to std::unique_ptr but the underlying object has the same constness as the po...
Definition: hold_ptr.hpp:17
Localization backend manager is a class that holds various backend and allows creation of their combi...
Definition: localization_backend.hpp:65
this class represents a localization backend that can be used for localizing your application.
Definition: localization_backend.hpp:40
constexpr char_facet_t character_facet_last
Last facet specific for character type.
Definition: generator.hpp:53
constexpr char_facet_t all_characters
Special mask – generate all.
Definition: generator.hpp:64
constexpr category_t category_last
Last category facet.
Definition: generator.hpp:93
constexpr category_t per_character_facet_last
Last facet specific for character.
Definition: generator.hpp:85
char_facet_t
Definition: generator.hpp:34
@ nochar
Unspecified character category for character independent facets.
@ char16_f
C++11 char16_t facets.
@ char_f
8-bit character facets
@ char32_f
C++11 char32_t facets.
@ wchar_f
wide character facets
constexpr char_facet_t character_facet_first
First facet specific for character type.
Definition: generator.hpp:51
category_t
Definition: generator.hpp:69
@ codepage
Generate character set conversion facets (derived from std::codecvt)
@ convert
Generate conversion facets.
@ boundary
Generate boundary analysis facet.
@ information
Generate general locale information facet.
@ collation
Generate collation facets.
@ parsing
Generate numbers, currency, date-time formatting facets.
@ formatting
Generate numbers, currency, date-time formatting facets.
constexpr category_t non_character_facet_first
First character independent facet.
Definition: generator.hpp:87
constexpr category_t all_categories
Generate all of them.
Definition: generator.hpp:95
constexpr category_t category_first
First category facet.
Definition: generator.hpp:91
constexpr category_t non_character_facet_last
Last character independent facet.
Definition: generator.hpp:89
constexpr category_t per_character_facet_first
First facet specific for character.
Definition: generator.hpp:83