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 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
59 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
90 constexpr category_t all_categories = category_t(0xFFFFFFFFu);
91
96 class BOOST_LOCALE_DECL generator {
97 public:
102
103 ~generator();
104
109
114
132 void add_messages_domain(const std::string& domain);
133
136 void set_default_messages_domain(const std::string& domain);
137
140
153 void add_messages_path(const std::string& path);
154
157
160
162 void locale_cache_enabled(bool on);
163
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
185 private:
186 void set_all_options(localization_backend& backend, const std::string& id) const;
187
188 generator(const generator&);
189 void operator=(const generator&);
190
191 struct data;
193 };
194
195 constexpr char_facet_t operator|(const char_facet_t lhs, const char_facet_t rhs)
196 {
197 return char_facet_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
198 }
199 constexpr char_facet_t operator^(const char_facet_t lhs, const char_facet_t rhs)
200 {
201 return char_facet_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
202 }
203 constexpr bool operator&(const char_facet_t lhs, const char_facet_t rhs)
204 {
205 return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
206 }
207 // Prefix increment: Return the next value
208 BOOST_CXX14_CONSTEXPR inline char_facet_t& operator++(char_facet_t& v)
209 {
210 return v = char_facet_t(static_cast<uint32_t>(v) ? static_cast<uint32_t>(v) << 1 : 1);
211 }
212
213 constexpr category_t operator|(const category_t lhs, const category_t rhs)
214 {
215 return category_t(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
216 }
217 constexpr category_t operator^(const category_t lhs, const category_t rhs)
218 {
219 return category_t(static_cast<uint32_t>(lhs) ^ static_cast<uint32_t>(rhs));
220 }
221 constexpr bool operator&(const category_t lhs, const category_t rhs)
222 {
223 return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs)) != 0u;
224 }
225 // Prefix increment: Return the next value
226 BOOST_CXX14_CONSTEXPR inline category_t& operator++(category_t& v)
227 {
228 return v = category_t(static_cast<uint32_t>(v) << 1);
229 }
230} // namespace locale
231} // namespace boost
232#ifdef BOOST_MSVC
233# pragma warning(pop)
234#endif
235
236#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:469
the major class used for locale generation
Definition: generator.hpp:96
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:183
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:50
constexpr char_facet_t all_characters
Special mask – generate all.
Definition: generator.hpp:59
constexpr category_t category_last
Last category facet.
Definition: generator.hpp:88
constexpr category_t per_character_facet_last
Last facet specific for character.
Definition: generator.hpp:80
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:48
category_t
Definition: generator.hpp:64
@ 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:82
constexpr category_t all_categories
Generate all of them.
Definition: generator.hpp:90
constexpr category_t category_first
First category facet.
Definition: generator.hpp:86
constexpr category_t non_character_facet_last
Last character independent facet.
Definition: generator.hpp:84
constexpr category_t per_character_facet_first
First facet specific for character.
Definition: generator.hpp:78