mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-114 Fixed initial rudimentary bugs. This is the first version that links and works. It no doubt still has bugs in it.
X-SVN-Rev: 179
This commit is contained in:
parent
d60fe9d14e
commit
ede38c10de
2 changed files with 50 additions and 15 deletions
icu4c/source/common
|
@ -48,7 +48,7 @@ UVector::~UVector() {
|
|||
}
|
||||
|
||||
void UVector::addElement(void* obj) {
|
||||
if (ensureCapacity(count)) {
|
||||
if (ensureCapacity(count+1)) {
|
||||
elements[count++] = obj;
|
||||
}
|
||||
}
|
||||
|
@ -79,15 +79,10 @@ void* UVector::elementAt(int32_t index) const {
|
|||
}
|
||||
|
||||
void UVector::removeElementAt(int32_t index) {
|
||||
if (0 <= index && index < count) {
|
||||
if (deleter != 0) {
|
||||
(*deleter)(elements[index]);
|
||||
}
|
||||
for (int32_t i=index; i<count; ++i) {
|
||||
elements[i] = elements[i+1];
|
||||
}
|
||||
void* e = orphanElementAt(index);
|
||||
if (e != 0 && deleter != 0) {
|
||||
(*deleter)(e);
|
||||
}
|
||||
/* else index out of range */
|
||||
}
|
||||
|
||||
bool_t UVector::removeElement(void* obj) {
|
||||
|
@ -155,6 +150,28 @@ bool_t UVector::isOutOfMemory() {
|
|||
return outOfMemory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element at the given index from this vector and
|
||||
* transfer ownership of it to the caller. After this call, the
|
||||
* caller owns the result and must delete it and the vector entry
|
||||
* at 'index' is removed, shifting all subsequent entries back by
|
||||
* one index and shortening the size of the vector by one. If the
|
||||
* index is out of range or if there is no item at the given index
|
||||
* then 0 is returned and the vector is unchanged.
|
||||
*/
|
||||
void* UVector::orphanElementAt(int32_t index) {
|
||||
void* e = 0;
|
||||
if (0 <= index && index < count) {
|
||||
e = elements[index];
|
||||
for (int32_t i=index; i<count; ++i) {
|
||||
elements[i] = elements[i+1];
|
||||
}
|
||||
--count;
|
||||
}
|
||||
/* else index out of range */
|
||||
return e;
|
||||
}
|
||||
|
||||
UStack::UStack(int32_t initialCapacity) :
|
||||
UVector(initialCapacity) {
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
*
|
||||
* @author Alan Liu
|
||||
*/
|
||||
class UVector {
|
||||
class U_COMMON_API UVector {
|
||||
public:
|
||||
typedef void (*Deleter)(void*);
|
||||
typedef bool_t (*Comparer)(void*, void*);
|
||||
|
@ -88,6 +88,10 @@ public:
|
|||
|
||||
~UVector();
|
||||
|
||||
//------------------------------------------------------------
|
||||
// java.util.Vector API
|
||||
//------------------------------------------------------------
|
||||
|
||||
void addElement(void* obj);
|
||||
|
||||
void setElementAt(void* obj, int32_t index);
|
||||
|
@ -116,7 +120,10 @@ public:
|
|||
|
||||
bool_t ensureCapacity(int32_t minimumCapacity);
|
||||
|
||||
//------------------------------------------------------------
|
||||
// New API
|
||||
//------------------------------------------------------------
|
||||
|
||||
Deleter setDeleter(Deleter d);
|
||||
|
||||
Comparer setComparer(Comparer c);
|
||||
|
@ -125,6 +132,17 @@ public:
|
|||
|
||||
void* operator[](int32_t index) const;
|
||||
|
||||
/**
|
||||
* Removes the element at the given index from this vector and
|
||||
* transfer ownership of it to the caller. After this call, the
|
||||
* caller owns the result and must delete it and the vector entry
|
||||
* at 'index' is removed, shifting all subsequent entries back by
|
||||
* one index and shortening the size of the vector by one. If the
|
||||
* index is out of range or if there is no item at the given index
|
||||
* then 0 is returned and the vector is unchanged.
|
||||
*/
|
||||
void* orphanElementAt(int32_t index);
|
||||
|
||||
private:
|
||||
void _init(int32_t initialCapacity);
|
||||
|
||||
|
@ -152,7 +170,7 @@ private:
|
|||
*
|
||||
* @author Alan Liu
|
||||
*/
|
||||
class UStack : public UVector {
|
||||
class U_COMMON_API UStack : public UVector {
|
||||
public:
|
||||
UStack(int32_t initialCapacity = 8);
|
||||
|
||||
|
@ -207,10 +225,10 @@ inline void* UVector::operator[](int32_t index) const {
|
|||
}
|
||||
|
||||
// Dummy implementation - disallowed method
|
||||
UVector::UVector(const UVector&) {}
|
||||
inline UVector::UVector(const UVector&) {}
|
||||
|
||||
// Dummy implementation - disallowed method
|
||||
UVector& UVector::operator=(const UVector&) {
|
||||
inline UVector& UVector::operator=(const UVector&) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -231,10 +249,10 @@ inline void* UStack::push(void* obj) {
|
|||
}
|
||||
|
||||
// Dummy implementation - disallowed method
|
||||
UStack::UStack(const UStack&) {}
|
||||
inline UStack::UStack(const UStack&) {}
|
||||
|
||||
// Dummy implementation - disallowed method
|
||||
UStack& UStack::operator=(const UStack&) {
|
||||
inline UStack& UStack::operator=(const UStack&) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue