ICU 77.1 77.1

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
33 // Export an explicit template instantiation of the LocalPointer that is used as a
34 // data member of various MessageFormatDataModel classes.
35 // (When building DLLs for Windows this is required.)
36 // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
37 // for similar examples.)
38 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
39 template class U_I18N_API LocalPointerBase<UnicodeString>;
40 template class U_I18N_API LocalPointerBase<message2::Formattable>;
41 template class U_I18N_API LocalArray<UnicodeString>;
42 template class U_I18N_API LocalArray<message2::Formattable>;
43 #endif
45
46 namespace message2 {
47
48 class MessageFormatter;
49
50 // Arguments
51 // ----------
52
61 class U_I18N_API MessageArguments : public UObject {
62 public:
74 MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
75 if (U_FAILURE(status)) {
76 return;
77 }
78 argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
79 arguments = LocalArray<Formattable>(new Formattable[argsLen]);
80 if (!argumentNames.isValid() || !arguments.isValid()) {
81 status = U_MEMORY_ALLOCATION_ERROR;
82 return;
83 }
84 int32_t i = 0;
85 for (auto iter = args.begin(); iter != args.end(); ++iter) {
86 argumentNames[i] = iter->first;
87 arguments[i] = iter->second;
88 i++;
89 }
90 }
98 MessageArguments& operator=(MessageArguments&&) noexcept;
106 MessageArguments() = default;
113 virtual ~MessageArguments();
114 private:
115 friend class MessageContext;
116
117 const Formattable* getArgument(const MessageFormatter&,
118 const data_model::VariableName&,
119 UErrorCode&) const;
120
121 // Avoids using Hashtable so that code constructing a Hashtable
122 // doesn't have to appear in this header file
123 LocalArray<UnicodeString> argumentNames;
124 LocalArray<Formattable> arguments;
125 int32_t argsLen = 0;
126 }; // class MessageArguments
127
128 } // namespace message2
129
130 U_NAMESPACE_END
131
132 #endif // U_HIDE_DEPRECATED_API
133
134 #endif /* #if !UCONFIG_NO_MF2 */
135
136 #endif /* #if !UCONFIG_NO_FORMATTING */
137
138 #endif /* #if !UCONFIG_NO_NORMALIZATION */
139
140 #endif /* U_SHOW_CPLUSPLUS_API */
141
142 #endif // MESSAGEFORMAT2_ARGUMENTS_H
143
144 // eof
icu::LocalArray
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
Definition: localpointer.h:366
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::message2::Formattable
The Formattable class represents a typed value that can be formatted, originating either from a messa...
Definition: messageformat2_formattable.h:118
icu::message2::MessageArguments
The MessageArguments class represents the named arguments to a message.
Definition: messageformat2_arguments.h:61
icu::message2::MessageArguments::MessageArguments
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:74
icu::message2::MessageArguments::operator=
MessageArguments & operator=(MessageArguments &&) noexcept
Move operator: The source MessageArguments will be left in a valid but undefined state.
icu::message2::MessageFormatter
Definition: messageformat2.h:54
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:430
U_MEMORY_ALLOCATION_ERROR
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition: utypes.h:473
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:748
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