+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
********************************************************************************
-* Copyright (C) {1997-2004}, International Business Machines Corporation and others. All Rights Reserved.
+* Copyright (C) 1997-2011, International Business Machines Corporation and others.
+* All Rights Reserved.
********************************************************************************
*
* File FORMAT.H
#include "unicode/utypes.h"
+/**
+ * \file
+ * \brief C++ API: Base class for all formats.
+ */
+
#if !UCONFIG_NO_FORMATTING
#include "unicode/unistr.h"
#include "unicode/fmtable.h"
#include "unicode/fieldpos.h"
+#include "unicode/fpositer.h"
#include "unicode/parsepos.h"
#include "unicode/parseerr.h"
#include "unicode/locid.h"
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
/**
UnicodeString& appendTo,
FieldPosition& pos,
UErrorCode& status) const = 0;
+ /**
+ * Format an object to produce a string. Subclasses should override this
+ * method. This method allows polymorphic formatting of Formattable objects.
+ * If a subclass of Format receives a Formattable object type it doesn't
+ * handle (e.g., if a numeric Formattable is passed to a DateFormat object)
+ * then it returns a failing UErrorCode.
+ *
+ * @param obj The object to format.
+ * @param appendTo Output parameter to receive result.
+ * Result is appended to existing contents.
+ * @param posIter On return, can be used to iterate over positions
+ * of fields generated by this format call.
+ * @param status Output param filled with success/failure status.
+ * @return Reference to 'appendTo' parameter.
+ * @stable ICU 4.4
+ */
+ virtual UnicodeString& format(const Formattable& obj,
+ UnicodeString& appendTo,
+ FieldPositionIterator* posIter,
+ UErrorCode& status) const;
/**
* Parse a string to produce an object. This is a pure virtual
Formattable& result,
UErrorCode& status) const;
- /**
- * Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
- * This method is to implement a simple version of RTTI, since not all
- * C++ compilers support genuine RTTI. Polymorphic operator==() and
- * clone() methods call this method.
- * Concrete subclasses of Format must implement getDynamicClassID()
- *
- * @return The class ID for this object. All objects of a
- * given class have the same class ID. Objects of
- * other classes have different class IDs.
- * @stable ICU 2.0
- */
- virtual UClassID getDynamicClassID() const = 0;
-
/** Get the locale for this format object. You can choose between valid and actual locale.
* @param type type of the locale we're looking for (valid or actual)
* @param status error code for the operation
* @return the locale
- * @draft ICU 2.8 likely to change in ICU 3.0, based on feedback
+ * @stable ICU 2.8
*/
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+#ifndef U_HIDE_INTERNAL_API
/** Get the locale for this format object. You can choose between valid and actual locale.
* @param type type of the locale we're looking for (valid or actual)
* @param status error code for the operation
* @internal
*/
const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
+#endif /* U_HIDE_INTERNAL_API */
protected:
- /** @draft ICU 2.8 */
+ /** @stable ICU 2.8 */
void setLocaleIDs(const char* valid, const char* actual);
protected:
};
U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */