ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

199 lines
7.0 KiB

  1. //
  2. // Copyright (c) 2009 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 CPPCMS_LOCALE_GENERATOR_HPP
  9. #define CPPCMS_LOCALE_GENERATOR_HPP
  10. #include "defs.h"
  11. #include "config.h"
  12. #include <string>
  13. #include <locale>
  14. #include <memory>
  15. namespace cppcms {
  16. namespace locale {
  17. ///
  18. /// \brief a enum type that specifies the character type that locales can be generated for
  19. ///
  20. typedef enum {
  21. char_facet = 1 << 0, ///< 8-bit character facets
  22. wchar_t_facet = 1 << 1, ///< wide character facets
  23. char16_t_facet = 1 << 2, ///< C++0x char16_t facets
  24. char32_t_facet = 1 << 3, ///< C++0x char32_t facets
  25. all_characters = 0xFFFF ///< Special mask -- generate all
  26. } character_facet_type;
  27. ///
  28. /// \brief a special enum used for more fine grained generation of facets
  29. ///
  30. typedef enum {
  31. collation_facet = 1 << 0, ///< Generate collation facets
  32. formatting_facet= 1 << 1, ///< Generate numbers, currency, date-time formatting facets
  33. message_facet = 1 << 2, ///< Generate message facets
  34. codepage_facet= 1 << 3, ///< Generate codepage conversion facets (derived from std::codecvt)
  35. all_categories = 0xFFFFFFFFu ///< Generate all of them
  36. } locale_category_type;
  37. ///
  38. /// \brief the major class used for locale generation
  39. ///
  40. /// This class is used for specification of all parameters required for locale generation and
  41. /// caching. This class const member functions are thread safe if locale class implementation is thread safe.
  42. ///
  43. class CPPCMS_API generator {
  44. public:
  45. generator();
  46. ~generator();
  47. ///
  48. /// Set types of facets that should be generated, default all
  49. ///
  50. void categories(unsigned cats);
  51. ///
  52. /// Get types of facets that should be generated, default all
  53. ///
  54. unsigned categories() const;
  55. ///
  56. /// Set the characters type for which the facets should be generated, default all supported
  57. ///
  58. void characters(unsigned chars);
  59. ///
  60. /// Get the characters type for which the facets should be generated, default all supported
  61. ///
  62. unsigned characters() const;
  63. ///
  64. /// Set encoding used for 8-bit character encoding. Default is system default encoding
  65. ///
  66. void octet_encoding(std::string const &encoding);
  67. ///
  68. /// Get encoding used for 8-bit character encoding. Default is system default encoding
  69. ///
  70. std::string octet_encoding() const;
  71. ///
  72. /// Add a new domain of messages that would be generated. It should be set in order to enable
  73. /// messages support.
  74. ///
  75. void add_messages_domain(std::string const &domain);
  76. ///
  77. /// Set default message domain. If this member was not called, the first added messages domain is used.
  78. /// If the domain \a domain is not added yet it is added.
  79. ///
  80. void set_default_messages_domain(std::string const &domain);
  81. ///
  82. /// Remove all added domains from the list
  83. ///
  84. void clear_domains();
  85. ///
  86. /// Add a search path where dictionaries are looked in.
  87. ///
  88. void add_messages_path(std::string const &path);
  89. ///
  90. /// Remove all added paths
  91. ///
  92. void clear_paths();
  93. ///
  94. /// Remove all cached locales
  95. ///
  96. void clear_cache();
  97. ///
  98. /// Generate a locale with id \a id and put it in cache
  99. ///
  100. void preload(std::string const &id);
  101. ///
  102. /// Generate a locale with id \a id, encoding \a encoding and put it in cache
  103. ///
  104. void preload(std::string const &id,std::string const &encoding);
  105. ///
  106. /// Generate a locale with id \a id and put it in cache, use \a base as a locale for which all facets are added,
  107. /// instead of global one
  108. ///
  109. void preload(std::locale const &base,std::string const &id);
  110. ///
  111. /// Generate a locale with id \a id, encoding \a encoding and put it in cache, use \a base as a locale for which all facets are added,
  112. /// instead of global one
  113. ///
  114. void preload(std::locale const &base,std::string const &id,std::string const &encoding);
  115. ///
  116. /// Generate a locale with id \a id
  117. ///
  118. std::locale generate(std::string const &id) const;
  119. ///
  120. /// Generate a locale with id \a id, encoding \a encoding
  121. ///
  122. std::locale generate(std::string const &id,std::string const &encoding) const;
  123. ///
  124. /// Generate a locale with id \a id, use \a base as a locale for which all facets are added,
  125. /// instead of global one
  126. ///
  127. std::locale generate(std::locale const &base,std::string const &id) const;
  128. ///
  129. /// Generate a locale with id \a id, encoding \a encoding, use \a base as a locale for which all facets are added,
  130. /// instead of global one
  131. ///
  132. std::locale generate(std::locale const &base,std::string const &id,std::string const &encoding) const;
  133. ///
  134. /// Get a locale with id \a id from cache, if not found, generate one
  135. ///
  136. std::locale get(std::string const &id) const;
  137. ///
  138. /// Get a locale with id \a id and encoding \a encociding from cache, if not found, generate one
  139. ///
  140. std::locale get(std::string const &id,std::string const &encoding) const;
  141. ///
  142. /// Shortcut to get(id)
  143. ///
  144. std::locale operator()(std::string const &id) const
  145. {
  146. return get(id);
  147. }
  148. ///
  149. /// Shortcut to get(id,encoding)
  150. ///
  151. std::locale operator()(std::string const &id,std::string const &encoding) const
  152. {
  153. return get(id,encoding);
  154. }
  155. private:
  156. template<typename CharType>
  157. std::locale generate_for(std::locale const &source) const;
  158. std::locale complete_generation(std::locale const &source) const;
  159. generator(generator const &);
  160. void operator=(generator const &);
  161. struct data;
  162. std::auto_ptr<data> d;
  163. };
  164. }
  165. }
  166. #endif
  167. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4