ICU 56.1: scientificnumberformatter.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

scientificnumberformatter.h
Go to the documentation of this file.
1 /*
2 **********************************************************************
3 * Copyright (c) 2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 */
7 #ifndef SCINUMBERFORMATTER_H
8 #define SCINUMBERFORMATTER_H
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13
14 #ifndef U_HIDE_DRAFT_API
15
16 #include "unicode/unistr.h"
17
23 U_NAMESPACE_BEGIN
24
25 class FieldPositionIterator;
26 class DecimalFormatStaticSets;
27 class DecimalFormatSymbols;
28 class DecimalFormat;
29 class Formattable;
30
50 class U_I18N_API ScientificNumberFormatter : public UObject {
51 public:
52
63 static ScientificNumberFormatter *createSuperscriptInstance(
64 DecimalFormat *fmtToAdopt, UErrorCode &status);
65
75 static ScientificNumberFormatter *createSuperscriptInstance(
76 const Locale &locale, UErrorCode &status);
77
78
91 static ScientificNumberFormatter *createMarkupInstance(
92 DecimalFormat *fmtToAdopt,
93 const UnicodeString &beginMarkup,
94 const UnicodeString &endMarkup,
95 UErrorCode &status);
96
108 static ScientificNumberFormatter *createMarkupInstance(
109 const Locale &locale,
110 const UnicodeString &beginMarkup,
111 const UnicodeString &endMarkup,
112 UErrorCode &status);
113
114
119 ScientificNumberFormatter *clone() const {
120 return new ScientificNumberFormatter(*this);
121 }
122
127 virtual ~ScientificNumberFormatter();
128
139 UnicodeString &format(
140 const Formattable &number,
141 UnicodeString &appendTo,
142 UErrorCode &status) const;
143 private:
144 class U_I18N_API Style : public UObject {
145 public:
146 virtual Style *clone() const = 0;
147 protected:
148 virtual UnicodeString &format(
149 const UnicodeString &original,
150 FieldPositionIterator &fpi,
151 const UnicodeString &preExponent,
152 const DecimalFormatStaticSets &decimalFormatSets,
153 UnicodeString &appendTo,
154 UErrorCode &status) const = 0;
155 private:
156 friend class ScientificNumberFormatter;
157 };
158
159 class U_I18N_API SuperscriptStyle : public Style {
160 public:
161 virtual Style *clone() const;
162 protected:
163 virtual UnicodeString &format(
164 const UnicodeString &original,
165 FieldPositionIterator &fpi,
166 const UnicodeString &preExponent,
167 const DecimalFormatStaticSets &decimalFormatSets,
168 UnicodeString &appendTo,
169 UErrorCode &status) const;
170 };
171
172 class U_I18N_API MarkupStyle : public Style {
173 public:
174 MarkupStyle(
175 const UnicodeString &beginMarkup,
176 const UnicodeString &endMarkup)
177 : Style(),
178 fBeginMarkup(beginMarkup),
179 fEndMarkup(endMarkup) { }
180 virtual Style *clone() const;
181 protected:
182 virtual UnicodeString &format(
183 const UnicodeString &original,
184 FieldPositionIterator &fpi,
185 const UnicodeString &preExponent,
186 const DecimalFormatStaticSets &decimalFormatSets,
187 UnicodeString &appendTo,
188 UErrorCode &status) const;
189 private:
190 UnicodeString fBeginMarkup;
191 UnicodeString fEndMarkup;
192 };
193
194 ScientificNumberFormatter(
195 DecimalFormat *fmtToAdopt,
196 Style *styleToAdopt,
197 UErrorCode &status);
198
199 ScientificNumberFormatter(const ScientificNumberFormatter &other);
200 ScientificNumberFormatter &operator=(const ScientificNumberFormatter &);
201
202 static void getPreExponent(
203 const DecimalFormatSymbols &dfs, UnicodeString &preExponent);
204
205 static ScientificNumberFormatter *createInstance(
206 DecimalFormat *fmtToAdopt,
207 Style *styleToAdopt,
208 UErrorCode &status);
209
210 UnicodeString fPreExponent;
211 DecimalFormat *fDecimalFormat;
212 Style *fStyle;
213 const DecimalFormatStaticSets *fStaticSets;
214
215 };
216
217 U_NAMESPACE_END
218
219 #endif /* U_HIDE_DRAFT_API */
220
221 #endif /* !UCONFIG_NO_FORMATTING */
222 #endif
icu::DecimalFormat
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers.
Definition: decimfmt.h:668
unistr.h
C++ API: Unicode String.
icu::ScientificNumberFormatter::clone
ScientificNumberFormatter * clone() const
Returns a copy of this object.
Definition: scientificnumberformatter.h:119
icu::ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation.
Definition: scientificnumberformatter.h:50
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:358
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:53
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:221
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185