winnmfmt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ********************************************************************************
  5. * Copyright (C) 2005-2015, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ********************************************************************************
  8. *
  9. * File WINNMFMT.H
  10. *
  11. ********************************************************************************
  12. */
  13. #ifndef __WINNMFMT
  14. #define __WINNMFMT
  15. #include "unicode/utypes.h"
  16. #if U_PLATFORM_USES_ONLY_WIN32_API
  17. #include "unicode/format.h"
  18. #include "unicode/datefmt.h"
  19. #include "unicode/calendar.h"
  20. #include "unicode/ustring.h"
  21. #include "unicode/locid.h"
  22. #if !UCONFIG_NO_FORMATTING
  23. /**
  24. * \file
  25. * \brief C++ API: Format numbers using Windows API.
  26. */
  27. U_NAMESPACE_BEGIN
  28. union FormatInfo;
  29. class Win32NumberFormat : public NumberFormat
  30. {
  31. public:
  32. Win32NumberFormat(const Locale &locale, UBool currency, UErrorCode &status);
  33. Win32NumberFormat(const Win32NumberFormat &other);
  34. virtual ~Win32NumberFormat();
  35. virtual Win32NumberFormat *clone() const;
  36. Win32NumberFormat &operator=(const Win32NumberFormat &other);
  37. /**
  38. * Format a double number. Concrete subclasses must implement
  39. * these pure virtual methods.
  40. *
  41. * @param number The value to be formatted.
  42. * @param appendTo Output parameter to receive result.
  43. * Result is appended to existing contents.
  44. * @param pos On input: an alignment field, if desired.
  45. * On output: the offsets of the alignment field.
  46. * @return Reference to 'appendTo' parameter.
  47. */
  48. virtual UnicodeString& format(double number,
  49. UnicodeString& appendTo,
  50. FieldPosition& pos) const;
  51. /**
  52. * Format a long number. Concrete subclasses must implement
  53. * these pure virtual methods.
  54. *
  55. * @param number The value to be formatted.
  56. * @param appendTo Output parameter to receive result.
  57. * Result is appended to existing contents.
  58. * @param pos On input: an alignment field, if desired.
  59. * On output: the offsets of the alignment field.
  60. * @return Reference to 'appendTo' parameter.
  61. */
  62. virtual UnicodeString& format(int32_t number,
  63. UnicodeString& appendTo,
  64. FieldPosition& pos) const;
  65. /**
  66. * Format an int64 number.
  67. *
  68. * @param number The value to be formatted.
  69. * @param appendTo Output parameter to receive result.
  70. * Result is appended to existing contents.
  71. * @param pos On input: an alignment field, if desired.
  72. * On output: the offsets of the alignment field.
  73. * @return Reference to 'appendTo' parameter.
  74. */
  75. virtual UnicodeString& format(int64_t number,
  76. UnicodeString& appendTo,
  77. FieldPosition& pos) const;
  78. using NumberFormat::format;
  79. // Use the default behavior for the following.
  80. // virtual UnicodeString &format(double number, UnicodeString &appendTo) const;
  81. // virtual UnicodeString &format(int32_t number, UnicodeString &appendTo) const;
  82. // virtual UnicodeString &format(int64_t number, UnicodeString &appendTo) const;
  83. virtual void parse(const UnicodeString& text, Formattable& result, ParsePosition& parsePosition) const;
  84. /**
  85. * Sets the maximum number of digits allowed in the fraction portion of a
  86. * number. maximumFractionDigits must be >= minimumFractionDigits. If the
  87. * new value for maximumFractionDigits is less than the current value
  88. * of minimumFractionDigits, then minimumFractionDigits will also be set to
  89. * the new value.
  90. * @param newValue the new value to be set.
  91. * @see getMaximumFractionDigits
  92. */
  93. virtual void setMaximumFractionDigits(int32_t newValue);
  94. /**
  95. * Sets the minimum number of digits allowed in the fraction portion of a
  96. * number. minimumFractionDigits must be <= maximumFractionDigits. If the
  97. * new value for minimumFractionDigits exceeds the current value
  98. * of maximumFractionDigits, then maximumIntegerDigits will also be set to
  99. * the new value
  100. * @param newValue the new value to be set.
  101. * @see getMinimumFractionDigits
  102. */
  103. virtual void setMinimumFractionDigits(int32_t newValue);
  104. /**
  105. * Return the class ID for this class. This is useful only for comparing to
  106. * a return value from getDynamicClassID(). For example:
  107. * <pre>
  108. * . Base* polymorphic_pointer = createPolymorphicObject();
  109. * . if (polymorphic_pointer->getDynamicClassID() ==
  110. * . derived::getStaticClassID()) ...
  111. * </pre>
  112. * @return The class ID for all objects of this class.
  113. */
  114. U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
  115. /**
  116. * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  117. * method is to implement a simple version of RTTI, since not all C++
  118. * compilers support genuine RTTI. Polymorphic operator==() and clone()
  119. * methods call this method.
  120. *
  121. * @return The class ID for this object. All objects of a
  122. * given class have the same class ID. Objects of
  123. * other classes have different class IDs.
  124. */
  125. virtual UClassID getDynamicClassID(void) const;
  126. private:
  127. UnicodeString &format(int32_t numDigits, UnicodeString &appendTo, const wchar_t *format, ...) const;
  128. UBool fCurrency;
  129. Locale fLocale;
  130. int32_t fLCID;
  131. FormatInfo *fFormatInfo;
  132. UBool fFractionDigitsSet;
  133. UnicodeString* fWindowsLocaleName; // Stores the equivalent Windows locale name.
  134. };
  135. U_NAMESPACE_END
  136. #endif /* #if !UCONFIG_NO_FORMATTING */
  137. #endif // U_PLATFORM_USES_ONLY_WIN32_API
  138. #endif // __WINNMFMT