/*
**********************************************************************
-* Copyright (C) 1999-2004, 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').
*/
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 UClassID U_EXPORT2 getStaticClassID();
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
- *
- * @draft ICU 2.2
*/
virtual UClassID getDynamicClassID() const;
// 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