* @param p simple pointer to an array of T objects that is adopted
* @stable ICU 4.4
*/
- explicit LocalArray(T *p=nullptr) : LocalPointerBase<T>(p), fLength(0) {}
+ explicit LocalArray(T *p=NULL) : LocalPointerBase<T>(p) {}
/**
- * Constructor takes ownership and reports an error if nullptr.
+ * Constructor takes ownership and reports an error if NULL.
*
* This constructor is intended to be used with other-class constructors
* that may report a failure UErrorCode,
*
* @param p simple pointer to an array of T objects that is adopted
* @param errorCode in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR
- * if p==nullptr and no other failure code had been set
+ * if p==NULL and no other failure code had been set
* @stable ICU 56
*/
- LocalArray(T *p, UErrorCode &errorCode) : LocalArray<T>(p) {
- if(p==nullptr && U_SUCCESS(errorCode)) {
- errorCode=U_MEMORY_ALLOCATION_ERROR;
- }
- }
-
-private:
- /** Constructor for withLengthAndCheckErrorCode() */
- LocalArray(T *p, int32_t length, UErrorCode &errorCode) : LocalArray<T>(p) {
- if (p != nullptr) {
- fLength = length;
- } else if (U_SUCCESS(errorCode)) {
+ LocalArray(T *p, UErrorCode &errorCode) : LocalPointerBase<T>(p) {
+ if(p==NULL && U_SUCCESS(errorCode)) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
}
}
-
-public:
/**
* Move constructor, leaves src with isNull().
* @param src source smart pointer
* @stable ICU 56
*/
- LocalArray(LocalArray<T> &&src) U_NOEXCEPT : LocalArray<T>(src.ptr) {
- src.ptr=nullptr;
- }
-
-#ifndef U_HIDE_DRAFT_API
- /**
- * Construct a LocalArray with a specified length.
- *
- * @param p simple pointer to an array of T objects that is adopted
- * @param length number of valid objects in the array, accesible via length()
- * @param errorCode in/out UErrorCode, set to U_MEMORY_ALLOCATION_ERROR
- * if p==nullptr and no other failure code had been set
- *
- * @draft ICU 67
- */
- static LocalArray<T> withLengthAndCheckErrorCode(T *p, int32_t length, UErrorCode& status) {
- return LocalArray(p, length, status);
+ LocalArray(LocalArray<T> &&src) U_NOEXCEPT : LocalPointerBase<T>(src.ptr) {
+ src.ptr=NULL;
}
-#endif // U_HIDE_DRAFT_API
#ifndef U_HIDE_DRAFT_API
/**
* @draft ICU 64
*/
explicit LocalArray(std::unique_ptr<T[]> &&p)
- : LocalArray<T>(p.release()) {}
+ : LocalPointerBase<T>(p.release()) {}
#endif /* U_HIDE_DRAFT_API */
/**
LocalArray<T> &operator=(LocalArray<T> &&src) U_NOEXCEPT {
delete[] LocalPointerBase<T>::ptr;
LocalPointerBase<T>::ptr=src.ptr;
- src.ptr=nullptr;
- fLength=src.fLength;
- src.fLength=0;
+ src.ptr=NULL;
return *this;
}
*/
LocalArray<T> &operator=(std::unique_ptr<T[]> &&p) U_NOEXCEPT {
adoptInstead(p.release());
- fLength=0;
return *this;
}
#endif /* U_HIDE_DRAFT_API */
T *temp=LocalPointerBase<T>::ptr;
LocalPointerBase<T>::ptr=other.ptr;
other.ptr=temp;
- int32_t tempLength=fLength;
- fLength=other.fLength;
- other.fLength=tempLength;
}
/**
* Non-member LocalArray swap function.
void adoptInstead(T *p) {
delete[] LocalPointerBase<T>::ptr;
LocalPointerBase<T>::ptr=p;
- fLength=0;
}
/**
* Deletes the array it owns,
} else {
delete[] p;
}
- fLength=0;
}
/**
* Array item access (writable).
return std::unique_ptr<T[]>(LocalPointerBase<T>::orphan());
}
#endif /* U_HIDE_DRAFT_API */
-
-#ifndef U_HIDE_DRAFT_API
- /**
- * The length of the array contained in the LocalArray. The size must be
- * provided when the LocalArray is constructed.
- *
- * @return The length of the array, or 0 if unknown.
- * @draft ICU 67
- */
- int32_t length() const { return fLength; }
-#endif // U_HIDE_DRAFT_API
-
-private:
- int32_t fLength = 0;
-
- LocalArray(T *p, int32_t length) : LocalArray(p) {
- fLength = length;
- }
};
/**
return std::move(impl).build(status);
}
-LocalArray<MeasureUnit> MeasureUnit::splitToSingleUnits(UErrorCode& status) const {
+LocalArray<MeasureUnit> MeasureUnit::splitToSingleUnits(int32_t& outCount, UErrorCode& status) const {
MeasureUnitImpl temp;
const MeasureUnitImpl& impl = MeasureUnitImpl::forMeasureUnit(*this, temp, status);
- const int32_t length = impl.units.length();
- MeasureUnit* arr = new MeasureUnit[length];
- for (int32_t i = 0; i < length; i++) {
+ outCount = impl.units.length();
+ MeasureUnit* arr = new MeasureUnit[outCount];
+ for (int32_t i = 0; i < outCount; i++) {
arr[i] = impl.units[i]->build(status);
}
- return LocalArray<MeasureUnit>::withLengthAndCheckErrorCode(arr, length, status);
+ return LocalArray<MeasureUnit>(arr, status);
}
* @param prefix The SI prefix, from UMeasureSIPrefix.
* @param status Set if this is not a SINGLE unit or if another error occurs.
* @return A new SINGLE unit.
+ * @draft ICU 67
*/
MeasureUnit withSIPrefix(UMeasureSIPrefix prefix, UErrorCode& status) const;
*
* @param status Set if this is not a SINGLE unit or if another error occurs.
* @return The SI prefix of this SINGLE unit, from UMeasureSIPrefix.
+ * @draft ICU 67
*/
UMeasureSIPrefix getSIPrefix(UErrorCode& status) const;
* @param dimensionality The dimensionality (power).
* @param status Set if this is not a SINGLE unit or if another error occurs.
* @return A new SINGLE unit.
+ * @draft ICU 67
*/
MeasureUnit withDimensionality(int32_t dimensionality, UErrorCode& status) const;
*
* @param status Set if this is not a SINGLE unit or if another error occurs.
* @return The dimensionality (power) of this simple unit.
+ * @draft ICU 67
*/
int32_t getDimensionality(UErrorCode& status) const;
*
* @param status Set if this is a SEQUENCE unit or if another error occurs.
* @return The reciprocal of the target unit.
+ * @draft ICU 67
*/
MeasureUnit reciprocal(UErrorCode& status) const;
* @param other The MeasureUnit to multiply with the target.
* @param status Set if this or other is a SEQUENCE unit or if another error occurs.
* @return The product of the target unit with the provided unit.
+ * @draft ICU 67
*/
MeasureUnit product(const MeasureUnit& other, UErrorCode& status) const;
+#endif // U_HIDE_DRAFT_API
+#ifndef U_HIDE_INTERNAL_API
/**
* Gets the list of SINGLE units contained within a SEQUENCE of COMPOUND unit.
*
*
* If this is a SINGLE unit, an array of length 1 will be returned.
*
+ * TODO(ICU-21021): Finalize this API and propose it as draft.
+ *
+ * @param outCount The number of elements in the return array.
* @param status Set if an error occurs.
* @return An array of single units, owned by the caller.
+ * @internal ICU 67 Technical Preview
*/
- LocalArray<MeasureUnit> splitToSingleUnits(UErrorCode& status) const;
-#endif // U_HIDE_DRAFT_API
+ LocalArray<MeasureUnit> splitToSingleUnits(int32_t& outCount, UErrorCode& status) const;
+#endif // U_HIDE_INTERNAL_API
/**
* getAvailable gets all of the available units.
unit.getComplexity(status));
status.errIfFailureAndReset("%s: Complexity", identifier);
- LocalArray<MeasureUnit> subUnits = unit.splitToSingleUnits(status);
- assertEquals(uid + ": Length", subIdentifierCount, subUnits.length());
+ int32_t length;
+ LocalArray<MeasureUnit> subUnits = unit.splitToSingleUnits(length, status);
+ assertEquals(uid + ": Length", subIdentifierCount, length);
for (int32_t i = 0;; i++) {
- if (i >= subIdentifierCount || i >= subUnits.length()) break;
+ if (i >= subIdentifierCount || i >= length) break;
assertEquals(uid + ": Sub-unit #" + Int64ToUnicodeString(i),
subIdentifiers[i],
subUnits[i].getIdentifier());
unit.getComplexity(status));
status.errIfFailureAndReset("%s: Complexity", identifier);
- LocalArray<MeasureUnit> subUnits = unit.splitToSingleUnits(status);
- assertEquals(uid + ": Length", subIdentifierCount, subUnits.length());
+ int32_t length;
+ LocalArray<MeasureUnit> subUnits = unit.splitToSingleUnits(length, status);
+ assertEquals(uid + ": Length", subIdentifierCount, length);
for (int32_t i = 0;; i++) {
- if (i >= subIdentifierCount || i >= subUnits.length()) break;
+ if (i >= subIdentifierCount || i >= length) break;
assertEquals(uid + ": Sub-unit #" + Int64ToUnicodeString(i),
subIdentifiers[i],
subUnits[i].getIdentifier());