localization_backend.hpp 6.6 KB

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