ICU 77.1  77.1
numberrangeformatter.h
Go to the documentation of this file.
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 #ifndef __NUMBERRANGEFORMATTER_H__
5 #define __NUMBERRANGEFORMATTER_H__
6 
7 #include "unicode/utypes.h"
8 
9 #if U_SHOW_CPLUSPLUS_API
10 
11 #if !UCONFIG_NO_FORMATTING
12 
13 #include <atomic>
14 #include "unicode/appendable.h"
15 #include "unicode/fieldpos.h"
16 #include "unicode/formattedvalue.h"
17 #include "unicode/fpositer.h"
20 
48 U_NAMESPACE_BEGIN
49 
50 // Forward declarations:
51 class PluralRules;
52 
53 namespace number { // icu::number
54 
55 // Forward declarations:
56 class UnlocalizedNumberRangeFormatter;
57 class LocalizedNumberRangeFormatter;
58 class FormattedNumberRange;
59 
60 namespace impl {
61 
62 // Forward declarations:
63 struct RangeMacroProps;
64 class DecimalQuantity;
65 class UFormattedNumberRangeData;
66 class NumberRangeFormatterImpl;
67 struct UFormattedNumberRangeImpl;
68 
69 } // namespace impl
70 
76 #if U_PLATFORM == U_PF_WINDOWS && !defined(U_IN_DOXYGEN) && !defined(U_STATIC_IMPLEMENTATION)
77 } // namespace icu::number
78 U_NAMESPACE_END
79 
80 template struct U_I18N_API std::atomic< U_NAMESPACE_QUALIFIER number::impl::NumberRangeFormatterImpl*>;
81 
82 U_NAMESPACE_BEGIN
83 namespace number { // icu::number
84 #endif
87 // Other helper classes would go here, but there are none.
88 
89 namespace impl { // icu::number::impl
90 
91 // Do not enclose entire MacroProps with #ifndef U_HIDE_INTERNAL_API, needed for a protected field
95  UnlocalizedNumberFormatter formatter1; // = NumberFormatter::with();
96 
98  UnlocalizedNumberFormatter formatter2; // = NumberFormatter::with();
99 
101  bool singleFormatter = true;
102 
105 
108 
111 
112  // NOTE: Uses default copy and move constructors.
113 
118  bool copyErrorTo(UErrorCode &status) const {
119  return formatter1.copyErrorTo(status) || formatter2.copyErrorTo(status);
120  }
121 };
122 
123 } // namespace impl
124 
130 template<typename Derived>
132  public:
145  Derived numberFormatterBoth(const UnlocalizedNumberFormatter &formatter) const &;
146 
156  Derived numberFormatterBoth(const UnlocalizedNumberFormatter &formatter) &&;
157 
167  Derived numberFormatterBoth(UnlocalizedNumberFormatter &&formatter) const &;
168 
179 
191  Derived numberFormatterFirst(const UnlocalizedNumberFormatter &formatterFirst) const &;
192 
202  Derived numberFormatterFirst(const UnlocalizedNumberFormatter &formatterFirst) &&;
203 
213  Derived numberFormatterFirst(UnlocalizedNumberFormatter &&formatterFirst) const &;
214 
224  Derived numberFormatterFirst(UnlocalizedNumberFormatter &&formatterFirst) &&;
225 
237  Derived numberFormatterSecond(const UnlocalizedNumberFormatter &formatterSecond) const &;
238 
248  Derived numberFormatterSecond(const UnlocalizedNumberFormatter &formatterSecond) &&;
249 
259  Derived numberFormatterSecond(UnlocalizedNumberFormatter &&formatterSecond) const &;
260 
270  Derived numberFormatterSecond(UnlocalizedNumberFormatter &&formatterSecond) &&;
271 
289  Derived collapse(UNumberRangeCollapse collapse) const &;
290 
300  Derived collapse(UNumberRangeCollapse collapse) &&;
301 
322  Derived identityFallback(UNumberRangeIdentityFallback identityFallback) const &;
323 
333  Derived identityFallback(UNumberRangeIdentityFallback identityFallback) &&;
334 
347 
355  LocalPointer<Derived> clone() &&;
356 
363  UBool copyErrorTo(UErrorCode &outErrorCode) const {
364  if (U_FAILURE(outErrorCode)) {
365  // Do not overwrite the older error code
366  return true;
367  }
368  fMacros.copyErrorTo(outErrorCode);
369  return U_FAILURE(outErrorCode);
370  }
371 
372  // NOTE: Uses default copy and move constructors.
373 
374  private:
375  impl::RangeMacroProps fMacros;
376 
377  // Don't construct me directly! Use (Un)LocalizedNumberFormatter.
378  NumberRangeFormatterSettings() = default;
379 
380  friend class LocalizedNumberRangeFormatter;
381  friend class UnlocalizedNumberRangeFormatter;
382 };
383 
384 // Explicit instantiations in source/i18n/numrange_fluent.cpp.
385 // (MSVC treats imports/exports of explicit instantiations differently.)
386 #ifndef _MSC_VER
387 extern template class NumberRangeFormatterSettings<UnlocalizedNumberRangeFormatter>;
388 extern template class NumberRangeFormatterSettings<LocalizedNumberRangeFormatter>;
389 #endif
390 
401 
402  public:
413 
424 
431 
437 
444 
450 
457 
458  private:
461 
464 
466 
468 
469  // To give the fluent setters access to this class's constructor:
471 
472  // To give NumberRangeFormatter::with() access to this class's constructor: