]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/nfrlist.h
ICU-6.2.15.tar.gz
[apple/icu.git] / icuSources / i18n / nfrlist.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3* Copyright (C) 1997-2001, International Business Machines
4* Corporation and others. All Rights Reserved.
5******************************************************************************
6* file name: nfrlist.h
7* encoding: US-ASCII
8* tab size: 8 (not used)
9* indentation:4
10*
11* Modification history
12* Date Name Comments
13* 10/11/2001 Doug Ported from ICU4J
14*/
15
16#ifndef NFRLIST_H
17#define NFRLIST_H
18
19#include "unicode/rbnf.h"
20
21#if U_HAVE_RBNF
22
23#include "unicode/uobject.h"
24#include "nfrule.h"
25
26#include "cmemory.h"
27
28U_NAMESPACE_BEGIN
29
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
32
33class NFRuleList : public UMemory {
34protected:
35 NFRule** fStuff;
36 uint32_t fCount;
37 uint32_t fCapacity;
38public:
39 NFRuleList(int capacity = 10)
40 : fStuff(capacity ? (NFRule**)uprv_malloc(capacity * sizeof(NFRule*)) : NULL)
41 , fCount(0)
42 , fCapacity(capacity) {};
43 ~NFRuleList() {
44 if (fStuff) {
45 for(uint32_t i = 0; i < fCount; ++i) {
46 delete fStuff[i];
47 }
48 uprv_free(fStuff);
49 }
50 }
51 NFRule* operator[](uint32_t index) const { return fStuff[index]; }
52 NFRule* remove(uint32_t index) {
53 NFRule* result = fStuff[index];
54 fCount -= 1;
55 for (uint32_t i = index; i < fCount; ++i) { // assumes small arrays
56 fStuff[i] = fStuff[i+1];
57 }
58 return result;
59 }
60 void add(NFRule* thing) {
61 if (fCount == fCapacity) {
62 fCapacity += 10;
63 fStuff = (NFRule**)uprv_realloc(fStuff, fCapacity * sizeof(NFRule*)); // assume success
64 }
65 fStuff[fCount++] = thing;
66 }
67 uint32_t size() const { return fCount; }
68 NFRule* last() const { return fCount > 0 ? fStuff[fCount-1] : NULL; }
69 NFRule** release() {
70 add(NULL); // ensure null termination
71 NFRule** result = fStuff;
72 fStuff = NULL;
73 fCount = 0;
74 fCapacity = 0;
75 return result;
76 }
77
78private:
79 NFRuleList(const NFRuleList &other); // forbid copying of this class
80 NFRuleList &operator=(const NFRuleList &other); // forbid copying of this class
81};
82
83U_NAMESPACE_END
84
85/* U_HAVE_RBNF */
86#endif
87
88// NFRLIST_H
89#endif