6#ifndef MESSAGEFORMAT2_FUNCTION_REGISTRY_H
7#define MESSAGEFORMAT2_FUNCTION_REGISTRY_H
9#if U_SHOW_CPLUSPLUS_API
11#if !UCONFIG_NO_NORMALIZATION
13#if !UCONFIG_NO_FORMATTING
17#include "unicode/messageformat2_data_model_names.h"
18#include "unicode/messageformat2_formattable.h"
21#ifndef U_HIDE_DEPRECATED_API
32 using namespace data_model;
49 using FunctionMap = Hashtable;
92 FunctionMap* functions;
94 Hashtable* formattersByType =
nullptr;
97 Builder& operator=(
const Builder&) =
delete;
98 Builder(
const Builder&) =
delete;
148 const data_model::FunctionName& functionName,
217 friend class MessageContext;
218 friend class MessageFormatter;
219 friend class MF2RegistrySingleton;
231 void checkFunction(std::u16string_view)
const;
232 void checkStandard()
const;
234 bool hasFunction(
const data_model::FunctionName& f)
const;
235 void cleanup() noexcept;
238 FunctionMap* functions =
nullptr;
240 Hashtable* formattersByType =
nullptr;
309 const FunctionName& calledFunction;
312 : locale(loc), dir(d), id(i), calledFunction(calledFn) {}
579 friend class FunctionOptions;
595 virtual UBool wasCreatedFromLiteral()
const {
return false; }
"Smart pointer" class, deletes objects via the standard C++ delete operator.
A Locale object represents a specific geographical, political, or cultural region.
UObject is the common ICU "boilerplate" class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Class implementing data from contextual options.
U_I18N_API const UnicodeString & getID() const
Returns the ID from this context.
U_I18N_API const FunctionName & getCalledFunctionName() const
Returns the original called function name from this context.
U_I18N_API UMFBidiOption getDirection() const
Returns the text direction from this context.
U_I18N_API FunctionContext withLocale(const Locale &loc) const
Returns a new context with the specified locale.
U_I18N_API const Locale & getLocale() const
Returns the locale from this context.
Structure encapsulating named options passed to a custom selector or formatter.
Type representing argument and return values for custom functions.
virtual U_I18N_API UMFBidiOption getDirectionAnnotation() const
Returns the directionality that this value was annotated with.
virtual U_I18N_API ~FunctionValue()
Destructor.
Formattable innerValue
Computed result of the function invocation that returned this FunctionValue.
Locale locale
Locale from u:locale option.
UMFBidiOption inputDir
Input directionality from u:dir option.
virtual U_I18N_API const UnicodeString & getFallback() const
Returns a fallback string that can be used as output if processing this function results in an error.
virtual U_I18N_API void selectKeys(const UnicodeString *keys, int32_t keysLen, int32_t *prefs, int32_t &prefsLen, UErrorCode &status) const
Compares this value to an array of keys, and returns an array of matching keys sorted by preference.
virtual U_I18N_API UnicodeString formatToString(UErrorCode &status) const
Returns the string representation of this value.
virtual U_I18N_API UBool isSelectable() const
Returns true if this value supports selection.
FunctionOptions opts
Resolved options attached to this value.
UnicodeString fallback
Fallback string that can be used if a later function encounters an error when processing this Functio...
FunctionName functionName
The name of the function that constructed this FunctionValue.
virtual U_I18N_API UBool isNullOperand() const
Returns true if this value represents a null operand, that is, the absence of an argument.
virtual U_I18N_API const FunctionOptions & getResolvedOptions() const
Returns a reference to the resolved options for this value.
UMFDirectionality dir
Directionality of formatted result.
virtual U_I18N_API UMFDirectionality getDirection() const
Returns the directionality of this value, i.e.
virtual U_I18N_API const FunctionName & getFunctionName() const
Returns the name of the function that constructed this value.
virtual U_I18N_API const Formattable & unwrap() const
Returns the Formattable operand that was used to construct this value.
Interface that function handler classes must implement.
virtual ~Function()
Destructor.
virtual LocalPointer< FunctionValue > call(const FunctionContext &context, const FunctionValue &operand, const FunctionOptions &options, UErrorCode &status) const =0
Calls this Function on a FunctionValue operand and its FunctionOptions options, returning a LocalPoin...
Builder(UErrorCode &errorCode)
Default constructor.
MFFunctionRegistry build()
Creates an immutable MFFunctionRegistry object with the selectors and formatters that were previously...
Builder & adoptFunction(const data_model::FunctionName &functionName, Function *function, UErrorCode &errorCode)
Registers a function to a given name.
Builder & setDefaultFormatterNameByType(const UnicodeString &type, const data_model::FunctionName &functionName, UErrorCode &errorCode)
Registers a formatter factory to a given type tag.
virtual ~Builder()
Destructor.
virtual ~MFFunctionRegistry()
Destructor.
MFFunctionRegistry(MFFunctionRegistry &&other)
Move constructor: The source MFFunctionRegistry will be left in a valid but undefined state.
MFFunctionRegistry & operator=(MFFunctionRegistry &&) noexcept
Move assignment operator: The source MFFunctionRegistry will be left in a valid but undefined state.
UBool getDefaultFormatterNameByType(const UnicodeString &formatterType, FunctionName &name) const
Looks up a function by a type tag.
static const MFFunctionRegistry * getStandardFunctionsRegistry(UErrorCode &status)
Get the standard function registry.
const Function * getFunction(const FunctionName &functionName) const
Looks up a function by the name of the function.
UMFBidiOption
Used to denote the directionality of the input to a function.
@ U_MF_BIDI_OPTION_INHERIT
Directionality inherited from the message without requiring isolation of the expression value.
UMFDirectionality
Used to represent the directionality of a message, where the AUTO setting has been resolved based on ...
@ U_MF_DIRECTIONALITY_UNKNOWN
Denotes a message with unknown directionality.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
@ U_MF_FORMATTING_ERROR
Covers all runtime errors: for example, an internally inconsistent set of options.
@ U_MF_SELECTOR_ERROR
A selector function is applied to an operand of the wrong type.
#define U_SUCCESS(x)
Does the error code indicate success?
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.