blob: fa56c1ea5c799791b9630520d8e57079474ce3b4 [file] [log] [blame]
// © 2020 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#ifndef __NUMBER_USAGEPREFS_H__
#define __NUMBER_USAGEPREFS_H__
#include "cmemory.h"
#include "number_types.h"
#include "unicode/locid.h"
#include "unicode/measunit.h"
#include "unicode/stringpiece.h"
#include "unicode/uobject.h"
#include "unitsrouter.h"
U_NAMESPACE_BEGIN
namespace number {
namespace impl {
using ::icu::units::UnitsRouter;
/**
* A MicroPropsGenerator which uses UnitsRouter to produce output converted to a
* MeasureUnit appropriate for a particular localized usage: see
* NumberFormatterSettings::usage().
*/
class U_I18N_API UsagePrefsHandler : public MicroPropsGenerator, public UMemory {
public:
UsagePrefsHandler(const Locale &locale, const MeasureUnit inputUnit, const StringPiece usage,
const MicroPropsGenerator *parent, UErrorCode &status);
/**
* Obtains the appropriate output value, MeasurementUnit and
* rounding/precision behaviour from the UnitsRouter.
*/
void processQuantity(DecimalQuantity &quantity, MicroProps &micros,
UErrorCode &status) const U_OVERRIDE;
/**
* Returns the list of possible output units, i.e. the full set of
* preferences, for the localized, usage-specific unit preferences.
*
* The returned pointer should be valid for the lifetime of the
* UsagePrefsHandler instance.
*/
const MaybeStackVector<MeasureUnit> *getOutputUnits() const {
return fUnitsRouter.getOutputUnits();
}
private:
UnitsRouter fUnitsRouter;
const MicroPropsGenerator *fParent;
};
} // namespace impl
} // namespace number
U_NAMESPACE_END
#endif // __NUMBER_USAGEPREFS_H__
#endif /* #if !UCONFIG_NO_FORMATTING */