ICU 75.1 75.1
Loading...
Searching...
No Matches
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_FORMATTING
12
13#if !UCONFIG_NO_MF2
14
20#include "unicode/messageformat2_data_model_names.h"
21#include "unicode/messageformat2_formattable.h"
22#include "unicode/unistr.h"
23
24#ifndef U_HIDE_DEPRECATED_API
25
26#include <map>
27
28U_NAMESPACE_BEGIN
29
31// Export an explicit template instantiation of the LocalPointer that is used as a
32// data member of various MessageFormatDataModel classes.
33// (When building DLLs for Windows this is required.)
34// (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
35// for similar examples.)
36#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
37#if defined(_MSC_VER)
38// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
39#pragma warning(push)
40#pragma warning(disable: 4661)
41#endif
42template class U_I18N_API LocalPointerBase<UnicodeString>;
43template class U_I18N_API LocalPointerBase<message2::Formattable>;
44template class U_I18N_API LocalArray<UnicodeString>;
45template class U_I18N_API LocalArray<message2::Formattable>;
46#if defined(_MSC_VER)
47// Ignore warning 4661 as LocalPointerBase does not use operator== or operator!=
48#pragma warning(pop)
49#endif
50#endif
52
53namespace message2 {
54
55 class MessageContext;
56
57 // Arguments
58 // ----------
59
69 public:
81 MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
82 if (U_FAILURE(status)) {
83 return;
84 }
85 argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = (int32_t) args.size()]);
86 arguments = LocalArray<Formattable>(new Formattable[argsLen]);
87 if (!argumentNames.isValid() || !arguments.isValid()) {
89 return;
90 }
91 int32_t i = 0;
92 for (auto iter = args.begin(); iter != args.end(); ++iter) {
93 argumentNames[i] = iter->first;
94 arguments[i] = iter->second;
95 i++;
96 }
97 }
121 private:
122 friend class MessageContext;
123
124 const Formattable* getArgument(const data_model::VariableName&, UErrorCode&) const;
125
126 // Avoids using Hashtable so that code constructing a Hashtable
127 // doesn't have to appear in this header file
128 LocalArray<UnicodeString> argumentNames;
129 LocalArray<Formattable> arguments;
130 int32_t argsLen = 0;
131 }; // class MessageArguments
132
133} // namespace message2
134
136
137#endif // U_HIDE_DEPRECATED_API
138
139#endif /* #if !UCONFIG_NO_MF2 */
140
141#endif /* #if !UCONFIG_NO_FORMATTING */
142
143#endif /* U_SHOW_CPLUSPLUS_API */
144
145#endif // MESSAGEFORMAT2_ARGUMENTS_H
146
147// eof
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
"Smart pointer" base class; do not use directly: use LocalPointer etc.
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...
The MessageArguments class represents the named arguments to a message.
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:415
@ U_MEMORY_ALLOCATION_ERROR
Memory allocation error.
Definition utypes.h:458
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition utypes.h:733
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301