Boost.Locale
localization_backend.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_LOCALIZATION_BACKEND_HPP
8#define BOOST_LOCALE_LOCALIZATION_BACKEND_HPP
9
10#include <boost/locale/generator.hpp>
11#include <boost/locale/hold_ptr.hpp>
12#include <locale>
13#include <memory>
14#include <string>
15#include <vector>
16
17#ifdef BOOST_MSVC
18# pragma warning(push)
19# pragma warning(disable : 4275 4251 4231 4660)
20#endif
21
22namespace boost { namespace locale {
23
40 class BOOST_LOCALE_DECL localization_backend {
41 protected:
43 localization_backend& operator=(const localization_backend&) = default;
44
45 public:
46 localization_backend() = default;
47 virtual ~localization_backend();
48
50 virtual localization_backend* clone() const = 0;
51
53 virtual void set_option(const std::string& name, const std::string& value) = 0;
54
56 virtual void clear_options() = 0;
57
59 virtual std::locale install(const std::locale& base, category_t category, char_facet_t type) = 0;
60
61 }; // localization_backend
62
65 class BOOST_LOCALE_DECL localization_backend_manager {
66 public:
77
80
82 std::unique_ptr<localization_backend> create() const;
83
84 BOOST_DEPRECATED("This function is deprecated, use 'create()' instead")
85 std::unique_ptr<localization_backend> get() const { return create(); } // LCOV_EXCL_LINE
86 BOOST_DEPRECATED("This function is deprecated, use 'create()' instead")
87 std::unique_ptr<localization_backend> get_unique_ptr() const { return create(); } // LCOV_EXCL_LINE
88
92 void add_backend(const std::string& name, std::unique_ptr<localization_backend> backend);
93
94 // clang-format off
95 BOOST_DEPRECATED("This function is deprecated, use 'add_backend' instead")
96 void adopt_backend(const std::string& name, localization_backend* backend) { add_backend(name, std::unique_ptr<localization_backend>(backend)); } // LCOV_EXCL_LINE
97 // clang-format on
98
101
103 std::vector<std::string> get_all_backends() const;
104
107 void select(const std::string& backend_name, category_t category = all_categories);
108
117
118 private:
119 class impl;
120 hold_ptr<impl> pimpl_;
121 };
122
123}} // namespace boost::locale
124
125#ifdef BOOST_MSVC
126# pragma warning(pop)
127#endif
128
129#endif
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
localization_backend_manager()
New empty localization_backend_manager.
static localization_backend_manager global()
static localization_backend_manager global(const localization_backend_manager &)
localization_backend_manager(const localization_backend_manager &)
Copy localization_backend_manager.
localization_backend_manager & operator=(const localization_backend_manager &)
Assign localization_backend_manager.
localization_backend_manager(localization_backend_manager &&) noexcept
Move construct localization_backend_manager.
void select(const std::string &backend_name, category_t category=all_categories)
void add_backend(const std::string &name, std::unique_ptr< localization_backend > backend)
std::vector< std::string > get_all_backends() const
Get list of all available backends.
this class represents a localization backend that can be used for localizing your application.
Definition: localization_backend.hpp:40
virtual localization_backend * clone() const =0
Make a polymorphic copy of the backend.
virtual void clear_options()=0
Clear all options.
virtual std::locale install(const std::locale &base, category_t category, char_facet_t type)=0
Create a facet for category category and character type type.
virtual void set_option(const std::string &name, const std::string &value)=0
Set option for backend, for example "locale" or "encoding".
char_facet_t
Definition: generator.hpp:34
category_t
Definition: generator.hpp:69