2 ******************************************************************************
3 * Copyright (C) 1997-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
8 * tab size: 8 (not used)
11 * Modification history
13 * 10/11/2001 Doug Ported from ICU4J
19 #include "unicode/rbnf.h"
23 #include "unicode/uobject.h"
30 // unsafe class for internal use only. assume memory allocations succeed, indexes are valid.
31 // should be a template, but we can't use them
33 class NFRuleList : public UMemory {
39 NFRuleList(uint32_t capacity = 10)
40 : fStuff(capacity ? (NFRule**)uprv_malloc(capacity * sizeof(NFRule*)) : NULL)
42 , fCapacity(capacity) {}
45 for(uint32_t i = 0; i < fCount; ++i) {
51 NFRule* operator[](uint32_t index) const { return fStuff != NULL ? fStuff[index] : NULL; }
52 NFRule* remove(uint32_t index) {
56 NFRule* result = fStuff[index];
58 for (uint32_t i = index; i < fCount; ++i) { // assumes small arrays
59 fStuff[i] = fStuff[i+1];
63 void add(NFRule* thing) {
64 if (fCount == fCapacity) {
66 fStuff = (NFRule**)uprv_realloc(fStuff, fCapacity * sizeof(NFRule*)); // assume success
69 fStuff[fCount++] = thing;
75 uint32_t size() const { return fCount; }
76 NFRule* last() const { return (fCount > 0 && fStuff != NULL) ? fStuff[fCount-1] : NULL; }
78 add(NULL); // ensure null termination
79 NFRule** result = fStuff;
87 NFRuleList(const NFRuleList &other); // forbid copying of this class
88 NFRuleList &operator=(const NFRuleList &other); // forbid copying of this class