Debian Codegraph @

intl/icu/source/i18n/unicode/displayoptions.h

raw
1 // © 2022 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #ifndef __DISPLAYOPTIONS_H__
5 #define __DISPLAYOPTIONS_H__
6
7 #include "unicode/utypes.h"
8
9 #if U_SHOW_CPLUSPLUS_API
10
11 #if !UCONFIG_NO_FORMATTING
12
13 /**
14 * \file
15 * \brief C++ API: Display options class
16 *
17 * This class is designed as a more modern version of the UDisplayContext mechanism.
18 */
19
20 #include "unicode/udisplayoptions.h"
21 #include "unicode/uversion.h"
22
23 U_NAMESPACE_BEGIN
24
25 /**
26 * Represents all the display options that are supported by CLDR such as grammatical case, noun
27 * class, ... etc. It currently supports enums, but may be extended in the future to have other
28 * types of data. It replaces a DisplayContext[] as a method parameter.
29 *
30 * NOTE: This class is Immutable, and uses a Builder interface.
31 *
32 * For example:
33 * ```
34 * DisplayOptions x =
35 * DisplayOptions::builder().
36 * .setGrammaticalCase(UDISPOPT_GRAMMATICAL_CASE_DATIVE)
37 * .setPluralCategory(UDISPOPT_PLURAL_CATEGORY_FEW)
38 * .build();
39 * ```
40 *
41 * @stable ICU 72
42 */
43 class U_I18N_API DisplayOptions {
44 public:
45 /**
46 * Responsible for building `DisplayOptions`.
47 *
48 * @stable ICU 72
49 */
50 class U_I18N_API Builder {
51 public:
52 /**
53 * Sets the grammatical case.
54 *
55 * @param grammaticalCase The grammatical case.
56 * @return Builder
57 * @stable ICU 72
58 */
59 Builder &setGrammaticalCase(UDisplayOptionsGrammaticalCase grammaticalCase) {
60 this->grammaticalCase = grammaticalCase;
61 return *this;
62 }
63
64 /**
65 * Sets the noun class.
66 *
67 * @param nounClass The noun class.
68 * @return Builder
69 * @stable ICU 72
70 */
71 Builder &setNounClass(UDisplayOptionsNounClass nounClass) {
72 this->nounClass = nounClass;
73 return *this;
74 }
75
76 /**
77 * Sets the plural category.
78 *
79 * @param pluralCategory The plural category.
80 * @return Builder
81 * @stable ICU 72
82 */
83 Builder &setPluralCategory(UDisplayOptionsPluralCategory pluralCategory) {
84 this->pluralCategory = pluralCategory;
85 return *this;
86 }
87
88 /**
89 * Sets the capitalization.
90 *
91 * @param capitalization The capitalization.
92 * @return Builder
93 * @stable ICU 72
94 */
95 Builder &setCapitalization(UDisplayOptionsCapitalization capitalization) {
96 this->capitalization = capitalization;
97 return *this;
98 }
99
100 /**
101 * Sets the dialect handling.
102 *
103 * @param nameStyle The name style.
104 * @return Builder
105 * @stable ICU 72
106 */
107 Builder &setNameStyle(UDisplayOptionsNameStyle nameStyle) {
108 this->nameStyle = nameStyle;
109 return *this;
110 }
111
112 /**
113 * Sets the display length.
114 *
115 * @param displayLength The display length.
116 * @return Builder
117 * @stable ICU 72
118 */
119 Builder &setDisplayLength(UDisplayOptionsDisplayLength displayLength) {
120 this->displayLength = displayLength;
121 return *this;
122 }
123
124 /**
125 * Sets the substitute handling.
126 *
127 * @param substituteHandling The substitute handling.
128 * @return Builder
129 * @stable ICU 72
130 */
131 Builder &setSubstituteHandling(UDisplayOptionsSubstituteHandling substituteHandling) {
132 this->substituteHandling = substituteHandling;
133 return *this;
134 }
135
136 /**
137 * Builds the display options.
138 *
139 * @return DisplayOptions
140 * @stable ICU 72
141 */
142 DisplayOptions build() { return DisplayOptions(*this); }
143
144 private:
145 friend DisplayOptions;
146
147 Builder();
148 Builder(const DisplayOptions &displayOptions);
149
150 UDisplayOptionsGrammaticalCase grammaticalCase;
151 UDisplayOptionsNounClass nounClass;
152 UDisplayOptionsPluralCategory pluralCategory;
153 UDisplayOptionsCapitalization capitalization;
154 UDisplayOptionsNameStyle nameStyle;
155 UDisplayOptionsDisplayLength displayLength;
156 UDisplayOptionsSubstituteHandling substituteHandling;
157 };
158
159 /**
160 * Creates a builder with the `UNDEFINED` values for all the parameters.
161 *
162 * @return Builder
163 * @stable ICU 72
164 */
165 static Builder builder();
166 /**
167 * Creates a builder with the same parameters from this object.
168 *
169 * @return Builder
170 * @stable ICU 72
171 */
172 Builder copyToBuilder() const;
173 /**
174 * Gets the grammatical case.
175 *
176 * @return UDisplayOptionsGrammaticalCase
177 * @stable ICU 72
178 */
179 UDisplayOptionsGrammaticalCase getGrammaticalCase() const { return grammaticalCase; }
180
181 /**
182 * Gets the noun class.
183 *
184 * @return UDisplayOptionsNounClass
185 * @stable ICU 72
186 */
187 UDisplayOptionsNounClass getNounClass() const { return nounClass; }
188
189 /**
190 * Gets the plural category.
191 *
192 * @return UDisplayOptionsPluralCategory
193 * @stable ICU 72
194 */
195 UDisplayOptionsPluralCategory getPluralCategory() const { return pluralCategory; }
196
197 /**
198 * Gets the capitalization.
199 *
200 * @return UDisplayOptionsCapitalization
201 * @stable ICU 72
202 */
203 UDisplayOptionsCapitalization getCapitalization() const { return capitalization; }
204
205 /**
206 * Gets the dialect handling.
207 *
208 * @return UDisplayOptionsNameStyle
209 * @stable ICU 72
210 */
211 UDisplayOptionsNameStyle getNameStyle() const { return nameStyle; }
212
213 /**
214 * Gets the display length.
215 *
216 * @return UDisplayOptionsDisplayLength
217 * @stable ICU 72
218 */
219 UDisplayOptionsDisplayLength getDisplayLength() const { return displayLength; }
220
221 /**
222 * Gets the substitute handling.
223 *
224 * @return UDisplayOptionsSubstituteHandling
225 * @stable ICU 72
226 */
227 UDisplayOptionsSubstituteHandling getSubstituteHandling() const { return substituteHandling; }
228
229 /**
230 * Copies the DisplayOptions.
231 *
232 * @param other The options to copy.
233 * @stable ICU 72
234 */
235 DisplayOptions &operator=(const DisplayOptions &other) = default;
236
237 /**
238 * Moves the DisplayOptions.
239 *
240 * @param other The options to move from.
241 * @stable ICU 72
242 */
243 DisplayOptions &operator=(DisplayOptions &&other) noexcept = default;
244
245 /**
246 * Copies the DisplayOptions.
247 *
248 * @param other The options to copy.
249 * @stable ICU 72
250 */
251 DisplayOptions(const DisplayOptions &other) = default;
252
253 private:
254 DisplayOptions(const Builder &builder);
255 UDisplayOptionsGrammaticalCase grammaticalCase;
256 UDisplayOptionsNounClass nounClass;
257 UDisplayOptionsPluralCategory pluralCategory;
258 UDisplayOptionsCapitalization capitalization;
259 UDisplayOptionsNameStyle nameStyle;
260 UDisplayOptionsDisplayLength displayLength;
261 UDisplayOptionsSubstituteHandling substituteHandling;
262 };
263
264 U_NAMESPACE_END
265
266 #endif /* #if !UCONFIG_NO_FORMATTING */
267
268 #endif /* U_SHOW_CPLUSPLUS_API */
269
270 #endif // __DISPLAYOPTIONS_H__