Fix dependencies.txt, add documentation, add appropriate UMemory inheritence.

This commit is contained in:
Hugo van der Merwe 2020-05-04 21:39:37 +02:00
parent cb3e32625e
commit ebb9e634ae
2 changed files with 43 additions and 12 deletions

View file

@ -74,7 +74,7 @@ class U_I18N_API ConversionRates {
// Encapsulates unitPreferenceData information from units resources, specifying
// a sequence of output unit preferences.
struct U_I18N_API UnitPreference {
struct U_I18N_API UnitPreference : public UMemory {
UnitPreference() : geq(1) {}
CharString unit;
double geq;
@ -83,13 +83,26 @@ struct U_I18N_API UnitPreference {
namespace {
// UnitPreferenceMetadata lives in the anonymous namespace, because it should
// only be useful to internal code and unit testing code.
struct U_I18N_API UnitPreferenceMetadata {
/**
* Metadata about the preferences in UnitPreferences::unitPrefs_.
*
* UnitPreferenceMetadata lives in the anonymous namespace, because it should
* only be useful to internal code and unit testing code.
*/
struct U_I18N_API UnitPreferenceMetadata : public UMemory {
// Unit category (e.g. "length", "mass", "electric-capacitance").
CharString category;
// Usage (e.g. "road", "vehicle-fuel", "blood-glucose"). Every category
// should have an entry for "default" usage. TODO(hugovdm): add a test for
// this.
CharString usage;
// Region code (e.g. "US", "CZ", "001"). Every usage should have an entry
// for the "001" region ("world"). TODO(hugovdm): add a test for this.
CharString region;
// Offset into the UnitPreferences::unitPrefs_ list where the relevant
// preferences are found.
int32_t prefsOffset;
// The number of preferences that form this set.
int32_t prefsCount;
};
@ -97,31 +110,49 @@ struct U_I18N_API UnitPreferenceMetadata {
/**
* Unit Preferences information for various locales and usages.
*
* TODO(hugovdm): add a function to look up the category based on the input
* unit.
*/
class U_I18N_API UnitPreferences {
public:
/**
* Constructor that loads data.
* Constructor, loads all the preference data.
*
* @param status Receives status.
*/
UnitPreferences(UErrorCode &status);
/**
* FIXME/WIP document me!
* Returns the set of unit preferences in the particular cateogry that best
* matches the specified usage and region.
*
* If region can't be found, falls back to global (001). If usage can't be found, falls back to
* If region can't be found, falls back to global (001). If usage can't be
* found, falls back to "default". Copies the preferences structures.
* TODO(hugovdm/review): Consider returning pointers (references) instead?
*
* @param category The category within which to look up usage and region.
* (TODO(hugovdm): improve docs on how to find the category, once the lookup
* function is added.)
* @param usage The usage parameter. (TODO(hugovdm): improve this
* documentation. Add reference to some list of usages we support.) If the
* given usage is not found, the function automatically falls back to
* "default".
*
* Copies the preferences structures. Consider returning pointers (references) instead?
* @param region The region whose preferences are desired. If there are no
* specific preferences for the requested region, the function automatically
* falls back to region "001" ("world").
* @param outPreferences The vector to which preferences will be added.
* @param status Receives status.
*/
void getPreferencesFor(const char *category, const char *usage, const char *region,
MaybeStackVector<UnitPreference> *outPreferences, UErrorCode &status);
protected:
int32_t binarySearch(const char *category, const char *usage, const char *region);
// Metadata about the sets of preferences, this is the index for looking up
// preferences in the unitPrefs_ list.
MaybeStackVector<UnitPreferenceMetadata> metadata_;
// All the preferences as a flat list: which usage and region preferences
// are associated with is stored in `metadata_`.
MaybeStackVector<UnitPreference> unitPrefs_;
};

View file

@ -1075,7 +1075,7 @@ group: units
group: unitsformatter
unitsdata.o unitconverter.o
deps
resourcebundle units_extra
resourcebundle units_extra number_representation
group: decnumber
decContext.o decNumber.o