ICU 78.2 78.2

messageformat2_arguments.h
Go to the documentation of this file.
1 // © 2024 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3
4 #include "unicode/utypes.h"
5
6 #ifndef MESSAGEFORMAT2_ARGUMENTS_H
7 #define MESSAGEFORMAT2_ARGUMENTS_H
8
9 #if U_SHOW_CPLUSPLUS_API
10
11 #if !UCONFIG_NO_NORMALIZATION
12
13 #if !UCONFIG_NO_FORMATTING
14
15 #if !UCONFIG_NO_MF2
16
22 #include "unicode/messageformat2_data_model_names.h"
23 #include "unicode/messageformat2_formattable.h"
24 #include "unicode/unistr.h"
25
26 #ifndef U_HIDE_DEPRECATED_API
27
28 #include <map>
29
30 U_NAMESPACE_BEGIN
31
32 namespace message2 {
33
34 class MessageFormatter;
35
36 // Arguments
37 // ----------
38
47 class U_I18N_API_CLASS MessageArguments : public UObject {
48 public:
60 U_I18N_API MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
61 if (U_FAILURE(status)) {
62 return;
63 }
64 argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
65 arguments = LocalArray<Formattable>(new Formattable[argsLen]);
66 if (!argumentNames.isValid() || !arguments.isValid()) {
67 status = U_MEMORY_ALLOCATION_ERROR;
68 return;
69 }
70 int32_t i = 0;
71 for (auto iter = args.begin(); iter != args.end(); ++iter) {
72 argumentNames[i] = iter->first;
73 arguments[i] = iter->second;
74 i++;
75 }
76 }
84 U_I18N_API MessageArguments& operator=(MessageArguments&&) noexcept;
92 U_I18N_API MessageArguments() = default;
99 U_I18N_API virtual ~MessageArguments();
100 private:
101 friend class MessageContext;
102
103 const Formattable* getArgument(const data_model::VariableName&,
104 UErrorCode&) const;
105
106 // Avoids using Hashtable so that code constructing a Hashtable
107 // doesn't have to appear in this header file
108 LocalArray<UnicodeString> argumentNames;
109 LocalArray<Formattable> arguments;
110 int32_t argsLen = 0;
111 }; // class MessageArguments
112
113 } // namespace message2
114
115 U_NAMESPACE_END
116
117 #endif // U_HIDE_DEPRECATED_API
118
119 #endif /* #if !UCONFIG_NO_MF2 */
120
121 #endif /* #if !UCONFIG_NO_FORMATTING */
122
123 #endif /* #if !UCONFIG_NO_NORMALIZATION */
124
125 #endif /* U_SHOW_CPLUSPLUS_API */
126
127 #endif // MESSAGEFORMAT2_ARGUMENTS_H
128
129 // eof
icu::LocalArray
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
Definition: localpointer.h:364
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
icu::message2::Formattable
The Formattable class represents a typed value that can be formatted, originating either from a messa...
Definition: messageformat2_formattable.h:113
icu::message2::MessageArguments
The MessageArguments class represents the named arguments to a message.
Definition: messageformat2_arguments.h:47
icu::message2::MessageArguments::MessageArguments
U_I18N_API MessageArguments(const std::map< UnicodeString, Formattable > &args, UErrorCode &status)
Message arguments constructor, which takes a map and returns a container of arguments that can be pas...
Definition: messageformat2_arguments.h:60
icu::message2::MessageArguments::operator=
U_I18N_API MessageArguments & operator=(MessageArguments &&) noexcept
Move operator: The source MessageArguments will be left in a valid but undefined state.
unistr.h
C++ API: Unicode String.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
U_MEMORY_ALLOCATION_ERROR
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:552
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:827
U_I18N_API_CLASS
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition: utypes.h:457
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:316