Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/displayoptions.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2022 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 
0004 #ifndef __DISPLAYOPTIONS_H__
0005 #define __DISPLAYOPTIONS_H__
0006 
0007 #include "unicode/utypes.h"
0008 
0009 #if U_SHOW_CPLUSPLUS_API
0010 
0011 #if !UCONFIG_NO_FORMATTING
0012 
0013 /**
0014  * \file
0015  * \brief C++ API: Display options class
0016  *
0017  * This class is designed as a more modern version of the UDisplayContext mechanism.
0018  */
0019 
0020 #include "unicode/udisplayoptions.h"
0021 #include "unicode/uversion.h"
0022 
0023 U_NAMESPACE_BEGIN
0024 
0025 /**
0026  * Represents all the display options that are supported by CLDR such as grammatical case, noun
0027  * class, ... etc. It currently supports enums, but may be extended in the future to have other
0028  * types of data. It replaces a DisplayContext[] as a method parameter.
0029  *
0030  * NOTE: This class is Immutable, and uses a Builder interface.
0031  *
0032  * For example:
0033  * ```
0034  * DisplayOptions x =
0035  *     DisplayOptions::builder().
0036  *         .setGrammaticalCase(UDISPOPT_GRAMMATICAL_CASE_DATIVE)
0037  *         .setPluralCategory(UDISPOPT_PLURAL_CATEGORY_FEW)
0038  *         .build();
0039  * ```
0040  *
0041  * @stable ICU 72
0042  */
0043 class U_I18N_API DisplayOptions {
0044 public:
0045     /**
0046      * Responsible for building `DisplayOptions`.
0047      *
0048      * @stable ICU 72
0049      */
0050     class U_I18N_API Builder {
0051     public:
0052         /**
0053          * Sets the grammatical case.
0054          *
0055          * @param grammaticalCase The grammatical case.
0056          * @return Builder
0057          * @stable ICU 72
0058          */
0059         Builder &setGrammaticalCase(UDisplayOptionsGrammaticalCase grammaticalCase) {
0060             this->grammaticalCase = grammaticalCase;
0061             return *this;
0062         }
0063 
0064         /**
0065          * Sets the noun class.
0066          *
0067          * @param nounClass The noun class.
0068          * @return Builder
0069          * @stable ICU 72
0070          */
0071         Builder &setNounClass(UDisplayOptionsNounClass nounClass) {
0072             this->nounClass = nounClass;
0073             return *this;
0074         }
0075 
0076         /**
0077          * Sets the plural category.
0078          *
0079          * @param pluralCategory The plural category.
0080          * @return Builder
0081          * @stable ICU 72
0082          */
0083         Builder &setPluralCategory(UDisplayOptionsPluralCategory pluralCategory) {
0084             this->pluralCategory = pluralCategory;
0085             return *this;
0086         }
0087 
0088         /**
0089          * Sets the capitalization.
0090          *
0091          * @param capitalization The capitalization.
0092          * @return Builder
0093          * @stable ICU 72
0094          */
0095         Builder &setCapitalization(UDisplayOptionsCapitalization capitalization) {
0096             this->capitalization = capitalization;
0097             return *this;
0098         }
0099 
0100         /**
0101          * Sets the dialect handling.
0102          *
0103          * @param nameStyle The name style.
0104          * @return Builder
0105          * @stable ICU 72
0106          */
0107         Builder &setNameStyle(UDisplayOptionsNameStyle nameStyle) {
0108             this->nameStyle = nameStyle;
0109             return *this;
0110         }
0111 
0112         /**
0113          * Sets the display length.
0114          *
0115          * @param displayLength The display length.
0116          * @return Builder
0117          * @stable ICU 72
0118          */
0119         Builder &setDisplayLength(UDisplayOptionsDisplayLength displayLength) {
0120             this->displayLength = displayLength;
0121             return *this;
0122         }
0123 
0124         /**
0125          * Sets the substitute handling.
0126          *
0127          * @param substituteHandling The substitute handling.
0128          * @return Builder
0129          * @stable ICU 72
0130          */
0131         Builder &setSubstituteHandling(UDisplayOptionsSubstituteHandling substituteHandling) {
0132             this->substituteHandling = substituteHandling;
0133             return *this;
0134         }
0135 
0136         /**
0137          * Builds the display options.
0138          *
0139          * @return DisplayOptions
0140          * @stable ICU 72
0141          */
0142         DisplayOptions build() { return DisplayOptions(*this); }
0143 
0144     private:
0145         friend DisplayOptions;
0146 
0147         Builder();
0148         Builder(const DisplayOptions &displayOptions);
0149 
0150         UDisplayOptionsGrammaticalCase grammaticalCase;
0151         UDisplayOptionsNounClass nounClass;
0152         UDisplayOptionsPluralCategory pluralCategory;
0153         UDisplayOptionsCapitalization capitalization;
0154         UDisplayOptionsNameStyle nameStyle;
0155         UDisplayOptionsDisplayLength displayLength;
0156         UDisplayOptionsSubstituteHandling substituteHandling;
0157     };
0158 
0159     /**
0160      * Creates a builder with the `UNDEFINED` values for all the parameters.
0161      *
0162      * @return Builder
0163      * @stable ICU 72
0164      */
0165     static Builder builder();
0166     /**
0167      * Creates a builder with the same parameters from this object.
0168      *
0169      * @return Builder
0170      * @stable ICU 72
0171      */
0172     Builder copyToBuilder() const;
0173     /**
0174      * Gets the grammatical case.
0175      *
0176      * @return UDisplayOptionsGrammaticalCase
0177      * @stable ICU 72
0178      */
0179     UDisplayOptionsGrammaticalCase getGrammaticalCase() const { return grammaticalCase; }
0180 
0181     /**
0182      * Gets the noun class.
0183      *
0184      * @return UDisplayOptionsNounClass
0185      * @stable ICU 72
0186      */
0187     UDisplayOptionsNounClass getNounClass() const { return nounClass; }
0188 
0189     /**
0190      * Gets the plural category.
0191      *
0192      * @return UDisplayOptionsPluralCategory
0193      * @stable ICU 72
0194      */
0195     UDisplayOptionsPluralCategory getPluralCategory() const { return pluralCategory; }
0196 
0197     /**
0198      * Gets the capitalization.
0199      *
0200      * @return UDisplayOptionsCapitalization
0201      * @stable ICU 72
0202      */
0203     UDisplayOptionsCapitalization getCapitalization() const { return capitalization; }
0204 
0205     /**
0206      * Gets the dialect handling.
0207      *
0208      * @return UDisplayOptionsNameStyle
0209      * @stable ICU 72
0210      */
0211     UDisplayOptionsNameStyle getNameStyle() const { return nameStyle; }
0212 
0213     /**
0214      * Gets the display length.
0215      *
0216      * @return UDisplayOptionsDisplayLength
0217      * @stable ICU 72
0218      */
0219     UDisplayOptionsDisplayLength getDisplayLength() const { return displayLength; }
0220 
0221     /**
0222      * Gets the substitute handling.
0223      *
0224      * @return UDisplayOptionsSubstituteHandling
0225      * @stable ICU 72
0226      */
0227     UDisplayOptionsSubstituteHandling getSubstituteHandling() const { return substituteHandling; }
0228 
0229     /**
0230      * Copies the DisplayOptions.
0231      *
0232      * @param other The options to copy.
0233      * @stable ICU 72
0234      */
0235     DisplayOptions &operator=(const DisplayOptions &other) = default;
0236 
0237     /**
0238      * Moves the DisplayOptions.
0239      *
0240      * @param other The options to move from.
0241      * @stable ICU 72
0242      */
0243     DisplayOptions &operator=(DisplayOptions &&other) noexcept = default;
0244 
0245     /**
0246      * Copies the DisplayOptions.
0247      *
0248      * @param other The options to copy.
0249      * @stable ICU 72
0250      */
0251     DisplayOptions(const DisplayOptions &other) = default;
0252 
0253 private:
0254     DisplayOptions(const Builder &builder);
0255     UDisplayOptionsGrammaticalCase grammaticalCase;
0256     UDisplayOptionsNounClass nounClass;
0257     UDisplayOptionsPluralCategory pluralCategory;
0258     UDisplayOptionsCapitalization capitalization;
0259     UDisplayOptionsNameStyle nameStyle;
0260     UDisplayOptionsDisplayLength displayLength;
0261     UDisplayOptionsSubstituteHandling substituteHandling;
0262 };
0263 
0264 U_NAMESPACE_END
0265 
0266 #endif /* #if !UCONFIG_NO_FORMATTING */
0267 
0268 #endif /* U_SHOW_CPLUSPLUS_API */
0269 
0270 #endif // __DISPLAYOPTIONS_H__