#ifndef NFRLIST_H
#define NFRLIST_H
#include "unicode/rbnf.h"
#if U_HAVE_RBNF
#include "unicode/uobject.h"
#include "nfrule.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN
class NFRuleList : public UMemory {
protected:
NFRule** fStuff;
uint32_t fCount;
uint32_t fCapacity;
public:
NFRuleList(uint32_t capacity = 10)
: fStuff(capacity ? (NFRule**)uprv_malloc(capacity * sizeof(NFRule*)) : NULL)
, fCount(0)
, fCapacity(capacity) {};
~NFRuleList() {
if (fStuff) {
for(uint32_t i = 0; i < fCount; ++i) {
delete fStuff[i];
}
uprv_free(fStuff);
}
}
NFRule* operator[](uint32_t index) const { return fStuff[index]; }
NFRule* remove(uint32_t index) {
NFRule* result = fStuff[index];
fCount -= 1;
for (uint32_t i = index; i < fCount; ++i) { fStuff[i] = fStuff[i+1];
}
return result;
}
void add(NFRule* thing) {
if (fCount == fCapacity) {
fCapacity += 10;
fStuff = (NFRule**)uprv_realloc(fStuff, fCapacity * sizeof(NFRule*)); }
fStuff[fCount++] = thing;
}
uint32_t size() const { return fCount; }
NFRule* last() const { return fCount > 0 ? fStuff[fCount-1] : NULL; }
NFRule** release() {
add(NULL); NFRule** result = fStuff;
fStuff = NULL;
fCount = 0;
fCapacity = 0;
return result;
}
private:
NFRuleList(const NFRuleList &other); NFRuleList &operator=(const NFRuleList &other); };
U_NAMESPACE_END
#endif
#endif