* MaybeStackVector<ConversionRateInfo> -> ConversionRates.
* Inherit from UMemory to make MaybeStackVector happy (UnitConverter
and ConverterPreference).
* Hack around getUnitsData's bad interface.
Code is still bad though, unit tests don't cover everything:
* getUnitsData does not work correctly, and various things are marked
with "WIP" comments (Work In Progress).
U_NAMESPACE_BEGIN
ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits,
- const MaybeStackVector<ConversionRateInfo> &ratesInfo,
- UErrorCode &status) {
+ const ConversionRates &ratesInfo, UErrorCode &status) {
int32_t length;
auto singleUnits = outputUnits.splitToSingleUnits(length, status);
MaybeStackVector<MeasureUnit> singleUnitsInOrder;
ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit,
const MaybeStackVector<MeasureUnit> outputUnits,
- const MaybeStackVector<ConversionRateInfo> &ratesInfo,
- UErrorCode &status) {
+ const ConversionRates &ratesInfo, UErrorCode &status) {
if (outputUnits.length() == 0) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
* @param status
*/
ComplexUnitsConverter(const MeasureUnit inputUnit, const MaybeStackVector<MeasureUnit> outputUnits,
- const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status);
+ const ConversionRates &ratesInfo, UErrorCode &status);
ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits,
- const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status);
+ const ConversionRates &ratesInfo, UErrorCode &status);
// Returns true if the `quantity` in the `inputUnit` is greater than or equal than the `limit` in the
// biggest `outputUnits`
/*
* Extracts `Factor` from a complete string factor. e.g. "ft2m^3*1007/cup2m3*3"
*
- * TODO: unused parameter 'status' [-Wunused-parameter]
+ * TODO: warning: unused parameter 'status' [-Wunused-parameter]
*/
Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) {
Factor result;
}
}
-// TODO: unused parameter 'status' [-Wunused-parameter]
+// TODO: warning: unused parameter 'status' [-Wunused-parameter]
void substituteConstants(Factor &factor, UErrorCode &status) {
double constantsValues[CONSTANTS_COUNT];
/**
* Converts from a source `MeasureUnit` to a target `MeasureUnit`.
*/
-class U_I18N_API UnitConverter {
+class U_I18N_API UnitConverter : public UMemory {
public:
/**
* Constructor of `UnitConverter`.
const char *region = "001"; // FIXME extract from locale.
CharString category;
MeasureUnit baseUnit;
- MaybeStackVector<ConversionRateInfo> conversionRates;
+ ConversionRates conversionRates(status);
+
+ // WIP/TODO(hugovdm): drop tmpConversionRates, redo getUnitsData.
+ MaybeStackVector<ConversionRateInfo> tmpConversionRates;
MaybeStackVector<UnitPreference> unitPreferences;
- getUnitsData(region, usage.data(), inputUnit, category, baseUnit, conversionRates, unitPreferences,
+ getUnitsData(region, usage.data(), inputUnit, category, baseUnit, tmpConversionRates, unitPreferences,
status);
for (int i = 0, n = unitPreferences.length(); i < n; ++i) {
U_NAMESPACE_BEGIN
-struct ConverterPreference {
+struct ConverterPreference : UMemory {
ComplexUnitsConverter converter;
double limit;
ConverterPreference(MeasureUnit source, MeasureUnit complexTarget, double limit,
- const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status)
+ const ConversionRates &ratesInfo, UErrorCode &status)
: converter(source, complexTarget, ratesInfo, status), limit(limit) {}
};
MeasureUnit sourceUnit = MeasureUnit::forIdentifier(testCase.source, status);
MeasureUnit targetUnit = MeasureUnit::forIdentifier(testCase.target, status);
- MaybeStackVector<ConversionRateInfo> unitsInfos;
- getAllConversionRates(unitsInfos, status);
-
- UnitConverter converter(sourceUnit, targetUnit, unitsInfos, status);
+ ConversionRates conversionRates(status);
+ UnitConverter converter(sourceUnit, targetUnit, conversionRates, status);
double actual = converter.convert(testCase.inputValue);