ICU 76.1  76.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_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 
28 U_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 template class U_I18N_API LocalPointerBase<UnicodeString>;
38 template class U_I18N_API LocalPointerBase<message2::Formattable>;
39 template class U_I18N_API LocalArray<UnicodeString>;
40 template class U_I18N_API LocalArray<message2::Formattable>;
41 #endif
42 
44 namespace message2 {
45 
46  class MessageContext;
47 
48  // Arguments
49  // ----------
50 
60  public:
72  MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
73  if (U_FAILURE(status)) {
74  return;
75  }
76  argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
77  arguments = LocalArray<Formattable>(new Formattable[argsLen]);
78  if (!argumentNames.isValid() || !arguments.isValid()) {
80  return;
81  }
82  int32_t i = 0;
83  for (auto iter = args.begin(); iter != args.end(); ++iter) {
84  argumentNames[i] = iter->first;
85  arguments[i] = iter->second;
86  i++;
87  }
88  }
96  MessageArguments& operator=(MessageArguments&&) noexcept;
104  MessageArguments() = default;
111  virtual ~MessageArguments();
112  private:
113  friend class MessageContext;
114 
115  const Formattable* getArgument(const data_model::VariableName&, UErrorCode&) const;
116 
117  // Avoids using Hashtable so that code constructing a Hashtable
118  // doesn't have to appear in this header file
119  LocalArray<UnicodeString> argumentNames;
120  LocalArray<Formattable> arguments;
121  int32_t argsLen = 0;
122  }; // class MessageArguments
123 
124 } // namespace message2
125 
126 U_NAMESPACE_END
127 
128 #endif // U_HIDE_DEPRECATED_API
129 
130 #endif /* #if !UCONFIG_NO_MF2 */
131 
132 #endif /* #if !UCONFIG_NO_FORMATTING */
133 
134 #endif /* U_SHOW_CPLUSPLUS_API */
135 
136 #endif // MESSAGEFORMAT2_ARGUMENTS_H
137 
138 // eof
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:747
C++ API: Unicode String.
The MessageArguments class represents the named arguments to a message.
Memory allocation error.
Definition: utypes.h:473
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:316
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...
"Smart pointer" class, deletes objects via the C++ array delete[] operator.
Definition: localpointer.h:366
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
The Formattable class represents a typed value that can be formatted, originating either from a messa...
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223