|
ICU 73.2
73.2
|
00001 // © 2022 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 00004 #ifndef __FORMATTEDNUMBER_H__ 00005 #define __FORMATTEDNUMBER_H__ 00006 00007 #include "unicode/utypes.h" 00008 00009 #if U_SHOW_CPLUSPLUS_API 00010 00011 #if !UCONFIG_NO_FORMATTING 00012 00013 #include "unicode/uobject.h" 00014 #include "unicode/formattedvalue.h" 00015 #include "unicode/measunit.h" 00016 #include "unicode/udisplayoptions.h" 00017 00025 U_NAMESPACE_BEGIN 00026 00027 class FieldPositionIteratorHandler; 00028 00029 namespace number { // icu::number 00030 00031 namespace impl { 00032 class DecimalQuantity; 00033 class UFormattedNumberData; 00034 struct UFormattedNumberImpl; 00035 } // icu::number::impl 00036 00037 00038 00047 class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { 00048 public: 00049 00054 FormattedNumber() 00055 : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {} 00056 00061 FormattedNumber(FormattedNumber&& src) noexcept; 00062 00067 virtual ~FormattedNumber() override; 00068 00070 FormattedNumber(const FormattedNumber&) = delete; 00071 00073 FormattedNumber& operator=(const FormattedNumber&) = delete; 00074 00079 FormattedNumber& operator=(FormattedNumber&& src) noexcept; 00080 00081 // Copybrief: this method is older than the parent method 00089 UnicodeString toString(UErrorCode& status) const override; 00090 00091 // Copydoc: this method is new in ICU 64 00093 UnicodeString toTempString(UErrorCode& status) const override; 00094 00095 // Copybrief: this method is older than the parent method 00103 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const override; 00104 00105 // Copydoc: this method is new in ICU 64 00107 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const override; 00108 00127 template<typename StringClass> 00128 inline StringClass toDecimalNumber(UErrorCode& status) const; 00129 00141 MeasureUnit getOutputUnit(UErrorCode& status) const; 00142 00143 #ifndef U_HIDE_DRAFT_API 00144 00152 UDisplayOptionsNounClass getNounClass(UErrorCode &status) const; 00153 00154 #endif // U_HIDE_DRAFT_API 00155 00156 #ifndef U_HIDE_INTERNAL_API 00157 00162 void getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const; 00163 00168 void getAllFieldPositionsImpl(FieldPositionIteratorHandler& fpih, UErrorCode& status) const; 00169 00170 #endif /* U_HIDE_INTERNAL_API */ 00171 00172 private: 00173 // Can't use LocalPointer because UFormattedNumberData is forward-declared 00174 impl::UFormattedNumberData *fData; 00175 00176 // Error code for the terminal methods 00177 UErrorCode fErrorCode; 00178 00183 explicit FormattedNumber(impl::UFormattedNumberData *results) 00184 : fData(results), fErrorCode(U_ZERO_ERROR) {} 00185 00186 explicit FormattedNumber(UErrorCode errorCode) 00187 : fData(nullptr), fErrorCode(errorCode) {} 00188 00189 void toDecimalNumber(ByteSink& sink, UErrorCode& status) const; 00190 00191 // To give LocalizedNumberFormatter format methods access to this class's constructor: 00192 friend class LocalizedNumberFormatter; 00193 friend class SimpleNumberFormatter; 00194 00195 // To give C API access to internals 00196 friend struct impl::UFormattedNumberImpl; 00197 }; 00198 00199 template<typename StringClass> 00200 StringClass FormattedNumber::toDecimalNumber(UErrorCode& status) const { 00201 StringClass result; 00202 StringByteSink<StringClass> sink(&result); 00203 toDecimalNumber(sink, status); 00204 return result; 00205 } 00206 00207 } // namespace number 00208 U_NAMESPACE_END 00209 00210 #endif /* #if !UCONFIG_NO_FORMATTING */ 00211 00212 #endif /* U_SHOW_CPLUSPLUS_API */ 00213 00214 #endif // __FORMATTEDNUMBER_H__ 00215
1.7.6.1