Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-07 10:23:59

0001 // © 2024 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 
0004 #include "unicode/utypes.h"
0005 
0006 #ifndef MESSAGEFORMAT2_ARGUMENTS_H
0007 #define MESSAGEFORMAT2_ARGUMENTS_H
0008 
0009 #if U_SHOW_CPLUSPLUS_API
0010 
0011 #if !UCONFIG_NO_FORMATTING
0012 
0013 #if !UCONFIG_NO_MF2
0014 
0015 /**
0016  * \file
0017  * \brief C++ API: Formats messages using the draft MessageFormat 2.0.
0018  */
0019 
0020 #include "unicode/messageformat2_data_model_names.h"
0021 #include "unicode/messageformat2_formattable.h"
0022 #include "unicode/unistr.h"
0023 
0024 #ifndef U_HIDE_DEPRECATED_API
0025 
0026 #include <map>
0027 
0028 U_NAMESPACE_BEGIN
0029 
0030 /// @cond DOXYGEN_IGNORE
0031 // Export an explicit template instantiation of the LocalPointer that is used as a
0032 // data member of various MessageFormatDataModel classes.
0033 // (When building DLLs for Windows this is required.)
0034 // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
0035 // for similar examples.)
0036 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
0037 template class U_I18N_API LocalPointerBase<UnicodeString>;
0038 template class U_I18N_API LocalPointerBase<message2::Formattable>;
0039 template class U_I18N_API LocalArray<UnicodeString>;
0040 template class U_I18N_API LocalArray<message2::Formattable>;
0041 #endif
0042 /// @endcond
0043 
0044 namespace message2 {
0045 
0046     class MessageContext;
0047 
0048     // Arguments
0049     // ----------
0050 
0051     /**
0052      *
0053      * The `MessageArguments` class represents the named arguments to a message.
0054      * It is immutable and movable. It is not copyable.
0055      *
0056      * @internal ICU 75 technology preview
0057      * @deprecated This API is for technology preview only.
0058      */
0059     class U_I18N_API MessageArguments : public UObject {
0060     public:
0061         /**
0062          * Message arguments constructor, which takes a map and returns a container
0063          * of arguments that can be passed to a `MessageFormatter`.
0064          *
0065          * @param args A reference to a map from strings (argument names) to `message2::Formattable`
0066          *        objects (argument values). The keys and values of the map are copied into the result.
0067          * @param status Input/output error code.
0068          *
0069          * @internal ICU 75 technology preview
0070          * @deprecated This API is for technology preview only.
0071          */
0072         MessageArguments(const std::map<UnicodeString, Formattable>& args, UErrorCode& status) {
0073             if (U_FAILURE(status)) {
0074                 return;
0075             }
0076             argumentNames = LocalArray<UnicodeString>(new UnicodeString[argsLen = static_cast<int32_t>(args.size())]);
0077             arguments = LocalArray<Formattable>(new Formattable[argsLen]);
0078             if (!argumentNames.isValid() || !arguments.isValid()) {
0079                 status = U_MEMORY_ALLOCATION_ERROR;
0080                 return;
0081             }
0082             int32_t i = 0;
0083             for (auto iter = args.begin(); iter != args.end(); ++iter) {
0084                 argumentNames[i] = iter->first;
0085                 arguments[i] = iter->second;
0086                 i++;
0087             }
0088         }
0089         /**
0090          * Move operator:
0091          * The source MessageArguments will be left in a valid but undefined state.
0092          *
0093          * @internal ICU 75 technology preview
0094          * @deprecated This API is for technology preview only.
0095          */
0096         MessageArguments& operator=(MessageArguments&&) noexcept;
0097         /**
0098          * Default constructor.
0099          * Returns an empty arguments mapping.
0100          *
0101          * @internal ICU 75 technology preview
0102          * @deprecated This API is for technology preview only.
0103          */
0104         MessageArguments() = default;
0105         /**
0106          * Destructor.
0107          *
0108          * @internal ICU 75 technology preview
0109          * @deprecated This API is for technology preview only.
0110          */
0111         virtual ~MessageArguments();
0112     private:
0113         friend class MessageContext;
0114 
0115         const Formattable* getArgument(const data_model::VariableName&, UErrorCode&) const;
0116 
0117         // Avoids using Hashtable so that code constructing a Hashtable
0118         // doesn't have to appear in this header file
0119         LocalArray<UnicodeString> argumentNames;
0120         LocalArray<Formattable> arguments;
0121         int32_t argsLen = 0;
0122     }; // class MessageArguments
0123 
0124 } // namespace message2
0125 
0126 U_NAMESPACE_END
0127 
0128 #endif // U_HIDE_DEPRECATED_API
0129 
0130 #endif /* #if !UCONFIG_NO_MF2 */
0131 
0132 #endif /* #if !UCONFIG_NO_FORMATTING */
0133 
0134 #endif /* U_SHOW_CPLUSPLUS_API */
0135 
0136 #endif // MESSAGEFORMAT2_ARGUMENTS_H
0137 
0138 // eof