/*
********************************************************************************
-* Copyright (C) {1997-2003}, 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/uobject.h"
#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"
U_NAMESPACE_BEGIN
+
/**
* Base class for all formats. This is an abstract base class which
* specifies the protocol for classes which convert other objects or
* retured for methods which take no ParsePosition. For the method
* that takes a ParsePosition, the index parameter is left unchanged.
* <P>
- * [Subclassing.] All base classes that provide static functions that
- * create objects for Locales must implement the following static:
- * <pre>
- * \code
- * public static const Locale* getAvailableLocales(long&)
- * \endcode
- * </pre>
+ * <em>User subclasses are not supported.</em> While clients may write
+ * subclasses, such code will not necessarily work and will not be
+ * guaranteed to work stably from release to release.
*/
class U_I18N_API Format : public UObject {
public:
/** Destructor
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
virtual ~Format();
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.
- * <P>
- * Concrete subclasses of Format must implement getDynamicClassID()
- * and also a static method and data member:
- *
- * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
- * static char fgClassID;
- *
- * @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
+ /** 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
+ * @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
+ * @return the locale
+ * @internal
*/
- virtual UClassID getDynamicClassID() const = 0;
+ const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
+#endif /* U_HIDE_INTERNAL_API */
+
+ protected:
+ /** @stable ICU 2.8 */
+ void setLocaleIDs(const char* valid, const char* actual);
protected:
/**
* @param pattern The pattern to copy into the parseError
* @param pos The position in pattern where the error occured
* @param parseError The UParseError object to fill in
- * @draft ICU 2.4
+ * @stable ICU 2.4
*/
static void syntaxError(const UnicodeString& pattern,
int32_t pos,
UParseError& parseError);
+
+ private:
+ char actualLocale[ULOC_FULLNAME_CAPACITY];
+ char validLocale[ULOC_FULLNAME_CAPACITY];
};
U_NAMESPACE_END