+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
-* Copyright (C) 1999-2003, International Business Machines
+* Copyright (C) 1999-2011, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
int32_t count;
int32_t capacity;
+
+ int32_t maxCapacity; // Limit beyond which capacity is not permitted to grow.
int32_t* elements;
UVector32(int32_t initialCapacity, UErrorCode &status);
- ~UVector32();
+ virtual ~UVector32();
/**
* Assign this object to another (make this a copy of 'other').
// java.util.Vector API
//------------------------------------------------------------
- void addElement(int32_t elem, UErrorCode &status);
+ inline void addElement(int32_t elem, UErrorCode &status);
void setElementAt(int32_t elem, int32_t index);
void insertElementAt(int32_t elem, int32_t index, UErrorCode &status);
- int32_t elementAti(int32_t index) const;
+ inline int32_t elementAti(int32_t index) const;
UBool equals(const UVector32 &other) const;
- int32_t lastElementi(void) const;
+ inline int32_t lastElementi(void) const;
- int32_t indexOf(int32_t obj, int32_t startIndex = 0) const;
+ int32_t indexOf(int32_t elem, int32_t startIndex = 0) const;
- UBool contains(int32_t obj) const;
+ inline UBool contains(int32_t elem) const;
UBool containsAll(const UVector32& other) const;
void removeAllElements();
- int32_t size(void) const;
+ inline int32_t size(void) const;
- UBool isEmpty(void) const;
+ inline UBool isEmpty(void) const;
// Inline. Use this one for speedy size check.
inline UBool ensureCapacity(int32_t minimumCapacity, UErrorCode &status);
* Insert the given integer into this vector at its sorted position.
* The current elements are assumed to be sorted already.
*/
- void sortedInsert(int32_t obj, UErrorCode& ec);
+ void sortedInsert(int32_t elem, UErrorCode& ec);
/**
* Returns a pointer to the internal array holding the vector.
*/
- int32_t *getBuffer() const;
+ inline int32_t *getBuffer() const;
+
+ /**
+ * Set the maximum allowed buffer capacity for this vector/stack.
+ * Default with no limit set is unlimited, go until malloc() fails.
+ * A Limit of zero means unlimited capacity.
+ * Units are vector elements (32 bits each), not bytes.
+ */
+ void setMaxCapacity(int32_t limit);
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
- *
- * @draft ICU 2.2
*/
- static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
+ static UClassID U_EXPORT2 getStaticClassID();
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
- *
- * @draft ICU 2.2
*/
- virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
+ virtual UClassID getDynamicClassID() const;
private:
void _init(int32_t initialCapacity, UErrorCode &status);
// Disallow
UVector32& operator=(const UVector32&);
- /**
- * The address of this static class variable serves as this class's ID
- * for ICU "poor man's RTTI".
- */
- static const char fgClassID;
-
// API Functions for Stack operations.
// In the original UVector, these were in a separate derived class, UStack.
// Here in UVector32, they are all together.
public:
- UBool empty(void) const;
+ inline UBool empty(void) const; // TODO: redundant, same as empty(). Remove it?
- int32_t peeki(void) const;
+ inline int32_t peeki(void) const;
- int32_t popi(void);
+ inline int32_t popi(void);
- int32_t push(int32_t i, UErrorCode &status);
+ inline int32_t push(int32_t i, UErrorCode &status);
- int32_t *reserveBlock(int32_t size, UErrorCode &status);
- int32_t *popFrame(int32_t size);
+ inline int32_t *reserveBlock(int32_t size, UErrorCode &status);
+ inline int32_t *popFrame(int32_t size);
};
// UVector32 inlines
inline UBool UVector32::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
- if (capacity >= minimumCapacity) {
+ if ((minimumCapacity >= 0) && (capacity >= minimumCapacity)) {
return TRUE;
} else {
return expandCapacity(minimumCapacity, status);
}
inline int32_t UVector32::elementAti(int32_t index) const {
- return (0 <= index && index < count) ? elements[index] : 0;
+ return (index >= 0 && count > 0 && count - index > 0) ? elements[index] : 0;
}
}
inline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) {
- ensureCapacity(count+size, status);
+ if (ensureCapacity(count+size, status) == FALSE) {
+ return NULL;
+ }
int32_t *rp = elements+count;
count += size;
return rp;
inline int32_t *UVector32::getBuffer() const {
return elements;
-};
+}
// UStack inlines