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
21
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
30U_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
39template class U_I18N_API LocalPointerBase<UnicodeString>;
40template class U_I18N_API LocalPointerBase<message2::Formattable>;
41template class U_I18N_API LocalArray<UnicodeString>;
42template class U_I18N_API LocalArray<message2::Formattable>;
43#endif
45
46namespace message2 {
47
48 class MessageFormatter;
49
50 // Arguments
51 // ----------
52
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()) {
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 }
91
106 MessageArguments() = default;
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
130U_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
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
The Formattable class represents a typed value that can be formatted, originating either from a messa...
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...
MessageArguments & operator=(MessageArguments &&) noexcept
Move operator: The source MessageArguments will be left in a valid but undefined state.
C++ API: Unicode String.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:430
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition utypes.h:473
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:748
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316