| OLD | NEW |
| 1 /* | 1 /* |
| 2 ********************************************************************** | 2 ********************************************************************** |
| 3 * Copyright (C) 1999-2006, International Business Machines | 3 * Copyright (C) 1999-2008, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
| 5 ********************************************************************** | 5 ********************************************************************** |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 // | 8 // |
| 9 // UVector32 is a class implementing a vector of 32 bit integers. | 9 // UVector32 is a class implementing a vector of 32 bit integers. |
| 10 // It is similar to UVector, but holds int32_t values rather than poi
nters. | 10 // It is similar to UVector, but holds int32_t values rather than poi
nters. |
| 11 // Most of the code is unchanged from UVector. | 11 // Most of the code is unchanged from UVector. |
| 12 // | 12 // |
| 13 | 13 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 * | 54 * |
| 55 * <p>Improve the handling of index out of bounds errors. | 55 * <p>Improve the handling of index out of bounds errors. |
| 56 * | 56 * |
| 57 * @author Alan Liu | 57 * @author Alan Liu |
| 58 */ | 58 */ |
| 59 class U_COMMON_API UVector32 : public UObject { | 59 class U_COMMON_API UVector32 : public UObject { |
| 60 private: | 60 private: |
| 61 int32_t count; | 61 int32_t count; |
| 62 | 62 |
| 63 int32_t capacity; | 63 int32_t capacity; |
| 64 |
| 65 int32_t maxCapacity; // Limit beyond which capacity is not permitted to
grow. |
| 64 | 66 |
| 65 int32_t* elements; | 67 int32_t* elements; |
| 66 | 68 |
| 67 public: | 69 public: |
| 68 UVector32(UErrorCode &status); | 70 UVector32(UErrorCode &status); |
| 69 | 71 |
| 70 UVector32(int32_t initialCapacity, UErrorCode &status); | 72 UVector32(int32_t initialCapacity, UErrorCode &status); |
| 71 | 73 |
| 72 virtual ~UVector32(); | 74 virtual ~UVector32(); |
| 73 | 75 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 * The current elements are assumed to be sorted already. | 157 * The current elements are assumed to be sorted already. |
| 156 */ | 158 */ |
| 157 void sortedInsert(int32_t elem, UErrorCode& ec); | 159 void sortedInsert(int32_t elem, UErrorCode& ec); |
| 158 | 160 |
| 159 /** | 161 /** |
| 160 * Returns a pointer to the internal array holding the vector. | 162 * Returns a pointer to the internal array holding the vector. |
| 161 */ | 163 */ |
| 162 int32_t *getBuffer() const; | 164 int32_t *getBuffer() const; |
| 163 | 165 |
| 164 /** | 166 /** |
| 167 * Set the maximum allowed buffer capacity for this vector/stack. |
| 168 * Default with no limit set is unlimited, go until malloc() fails. |
| 169 * A Limit of zero means unlimited capacity. |
| 170 * Units are vector elements (32 bits each), not bytes. |
| 171 */ |
| 172 void setMaxCapacity(int32_t limit); |
| 173 |
| 174 /** |
| 165 * ICU "poor man's RTTI", returns a UClassID for this class. | 175 * ICU "poor man's RTTI", returns a UClassID for this class. |
| 166 */ | 176 */ |
| 167 static UClassID U_EXPORT2 getStaticClassID(); | 177 static UClassID U_EXPORT2 getStaticClassID(); |
| 168 | 178 |
| 169 /** | 179 /** |
| 170 * ICU "poor man's RTTI", returns a UClassID for the actual class. | 180 * ICU "poor man's RTTI", returns a UClassID for the actual class. |
| 171 */ | 181 */ |
| 172 virtual UClassID getDynamicClassID() const; | 182 virtual UClassID getDynamicClassID() const; |
| 173 | 183 |
| 174 private: | 184 private: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 224 |
| 215 | 225 |
| 216 inline void UVector32::addElement(int32_t elem, UErrorCode &status) { | 226 inline void UVector32::addElement(int32_t elem, UErrorCode &status) { |
| 217 if (ensureCapacity(count + 1, status)) { | 227 if (ensureCapacity(count + 1, status)) { |
| 218 elements[count] = elem; | 228 elements[count] = elem; |
| 219 count++; | 229 count++; |
| 220 } | 230 } |
| 221 } | 231 } |
| 222 | 232 |
| 223 inline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) { | 233 inline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) { |
| 224 ensureCapacity(count+size, status); | 234 if (ensureCapacity(count+size, status) == FALSE) { |
| 235 return NULL; |
| 236 } |
| 225 int32_t *rp = elements+count; | 237 int32_t *rp = elements+count; |
| 226 count += size; | 238 count += size; |
| 227 return rp; | 239 return rp; |
| 228 } | 240 } |
| 229 | 241 |
| 230 inline int32_t *UVector32::popFrame(int32_t size) { | 242 inline int32_t *UVector32::popFrame(int32_t size) { |
| 231 U_ASSERT(count >= size); | 243 U_ASSERT(count >= size); |
| 232 count -= size; | 244 count -= size; |
| 233 if (count < 0) { | 245 if (count < 0) { |
| 234 count = 0; | 246 count = 0; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (count > 0) { | 295 if (count > 0) { |
| 284 count--; | 296 count--; |
| 285 result = elements[count]; | 297 result = elements[count]; |
| 286 } | 298 } |
| 287 return result; | 299 return result; |
| 288 } | 300 } |
| 289 | 301 |
| 290 U_NAMESPACE_END | 302 U_NAMESPACE_END |
| 291 | 303 |
| 292 #endif | 304 #endif |
| OLD | NEW |