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.
 
 
 
 
 
 

133 lines
4.3 KiB

  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 BOOSTER_LOCALE_FORMATTER_H_INCLUDED
  9. #define BOOSTER_LOCALE_FORMATTER_H_INCLUDED
  10. #include <string>
  11. #include <booster/auto_ptr_inc.h>
  12. #include <booster/cstdint.h>
  13. #include <booster/config.h>
  14. #include <unicode/locid.h>
  15. namespace booster {
  16. namespace locale {
  17. namespace impl_icu {
  18. ///
  19. /// \brief Special base polymorphic class that is used as a character type independent base for all formatter classes
  20. ///
  21. class base_formatter {
  22. public:
  23. virtual ~base_formatter()
  24. {
  25. }
  26. };
  27. ///
  28. /// \brief A class that is used for formatting numbers, currency and dates/times
  29. ///
  30. template<typename CharType>
  31. class formatter : public base_formatter {
  32. public:
  33. typedef CharType char_type;
  34. typedef std::basic_string<CharType> string_type;
  35. ///
  36. /// Format the value and return the number of Unicode code points
  37. ///
  38. virtual string_type format(double value,size_t &code_points) const = 0;
  39. ///
  40. /// Format the value and return the number of Unicode code points
  41. ///
  42. virtual string_type format(int64_t value,size_t &code_points) const = 0;
  43. ///
  44. /// Format the value and return the number of Unicode code points
  45. ///
  46. virtual string_type format(int32_t value,size_t &code_points) const = 0;
  47. ///
  48. /// Parse the string and return the number of used characters. If it returns 0
  49. /// then parsing failed.
  50. ///
  51. virtual size_t parse(string_type const &str,double &value) const = 0;
  52. ///
  53. /// Parse the string and return the number of used characters. If it returns 0
  54. /// then parsing failed.
  55. ///
  56. virtual size_t parse(string_type const &str,int64_t &value) const = 0;
  57. ///
  58. /// Parse the string and return the number of used characters. If it returns 0
  59. /// then parsing failed.
  60. ///
  61. virtual size_t parse(string_type const &str,int32_t &value) const = 0;
  62. ///
  63. /// Get formatter for the current state of ios_base -- flags and locale,
  64. /// NULL may be returned if an invalid combination of flags is provided or this type
  65. /// of formatting is not supported by locale. See: create
  66. ///
  67. /// Note: formatter is cached. If \a ios is not changed (no flags or locale changed)
  68. /// the formatter would remain the same. Otherwise it would be rebuild and cached
  69. /// for future use. It is useful for saving time for generation
  70. /// of multiple values with same locale.
  71. ///
  72. /// For example, this code:
  73. ///
  74. /// \code
  75. /// std::cout << as::spellout;
  76. /// for(int i=1;i<=10;i++)
  77. /// std::cout << i <<std::endl;
  78. /// \endcode
  79. ///
  80. /// Would create a new spelling formatter only once.
  81. ///
  82. static std::auto_ptr<formatter> create(std::ios_base &ios,icu::Locale const &l,std::string const &enc);
  83. virtual ~formatter()
  84. {
  85. }
  86. }; // class formatter
  87. ///
  88. /// Specialization for real implementation
  89. ///
  90. template<>
  91. std::auto_ptr<formatter<char> > formatter<char>::create(std::ios_base &ios,icu::Locale const &l,std::string const &enc);
  92. ///
  93. /// Specialization for real implementation
  94. ///
  95. template<>
  96. std::auto_ptr<formatter<wchar_t> > formatter<wchar_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
  97. #ifdef BOOSTER_HAS_CHAR16_T
  98. ///
  99. /// Specialization for real implementation
  100. ///
  101. template<>
  102. std::auto_ptr<formatter<char16_t> > formatter<char16_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
  103. #endif
  104. #ifdef BOOSTER_HAS_CHAR32_T
  105. ///
  106. /// Specialization for real implementation
  107. ///
  108. template<>
  109. std::auto_ptr<formatter<char32_t> > formatter<char32_t>::create(std::ios_base &ios,icu::Locale const &l,std::string const &e);
  110. #endif
  111. } // namespace impl_icu
  112. } // namespace locale
  113. } // namespace boost
  114. #endif
  115. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4