version 1.9, 2002/05/13 23:07:52
|
version 1.12, 2002/05/17 22:33:30
|
|
|
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) | // Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// Modified By: |
// Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#endif | #endif |
Array<PEGASUS_ARRAY_T>::Array() | Array<PEGASUS_ARRAY_T>::Array() |
{ | { |
_rep = Rep::getNullRep(); |
_rep = Rep::create(0); |
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
#endif | #endif |
Array<PEGASUS_ARRAY_T>::Array(const Array<PEGASUS_ARRAY_T>& x) | Array<PEGASUS_ARRAY_T>::Array(const Array<PEGASUS_ARRAY_T>& x) |
{ | { |
Rep::inc(_rep = x._rep); |
_rep = x._rep->clone(); |
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
#endif | #endif |
Array<PEGASUS_ARRAY_T>::~Array() | Array<PEGASUS_ARRAY_T>::~Array() |
{ | { |
Rep::dec(_rep); |
Rep::destroy(_rep); |
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
{ | { |
if (x._rep != _rep) | if (x._rep != _rep) |
{ | { |
Rep::dec(_rep); |
Rep::destroy(_rep); |
Rep::inc(_rep = x._rep); |
_rep = x._rep->clone(); |
} | } |
return *this; | return *this; |
} | } |
|
|
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::clear() | void Array<PEGASUS_ARRAY_T>::clear() |
{ | { |
Rep::dec(_rep); |
Rep::destroy(_rep); |
_rep = Rep::getNullRep(); |
_rep = Rep::create(0); |
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
#else | #else |
PEGASUS_TEMPLATE_SPECIALIZATION | PEGASUS_TEMPLATE_SPECIALIZATION |
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::_reserveAux(Uint32 capacity) |
void Array<PEGASUS_ARRAY_T>::reserve(Uint32 capacity) |
|
{ |
|
if (capacity > _rep->capacity) |
{ | { |
Uint32 size = this->size(); | Uint32 size = this->size(); |
Rep* rep = Rep::create(capacity); | Rep* rep = Rep::create(capacity); |
|
|
#else | #else |
CopyToRaw(rep->data(), _rep->data(), size); | CopyToRaw(rep->data(), _rep->data(), size); |
#endif | #endif |
Rep::dec(_rep); |
Rep::destroy(_rep); |
_rep = rep; |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
void Array<PEGASUS_ARRAY_T>::_copyOnWrite() |
|
{ |
|
if (_rep->ref != 1) |
|
{ |
|
Rep* rep = _rep->clone(); |
|
Rep::dec(_rep); |
|
_rep = rep; | _rep = rep; |
} | } |
} | } |
|
|
{ | { |
Uint32 oldSize = _rep->size; | Uint32 oldSize = _rep->size; |
reserve(oldSize + size); | reserve(oldSize + size); |
_copyOnWrite(); |
|
| |
PEGASUS_ARRAY_T* p = _rep->data() + oldSize; | PEGASUS_ARRAY_T* p = _rep->data() + oldSize; |
Uint32 n = size; | Uint32 n = size; |
|
|
#else | #else |
PEGASUS_TEMPLATE_SPECIALIZATION | PEGASUS_TEMPLATE_SPECIALIZATION |
#endif | #endif |
|
Uint32 Array<PEGASUS_ARRAY_T>::size() const |
|
{ |
|
return _rep->size; |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
Uint32 Array<PEGASUS_ARRAY_T>::getCapacity() const |
|
{ |
|
return _rep->capacity; |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
const PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::getData() const |
|
{ |
|
return _rep->data(); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
void Array<PEGASUS_ARRAY_T>::append(const PEGASUS_ARRAY_T& x) | void Array<PEGASUS_ARRAY_T>::append(const PEGASUS_ARRAY_T& x) |
{ | { |
reserve(size() + 1); | reserve(size() + 1); |
_copyOnWrite(); |
|
new (_data() + size()) PEGASUS_ARRAY_T(x); | new (_data() + size()) PEGASUS_ARRAY_T(x); |
_rep->size++; | _rep->size++; |
} | } |
|
|
void Array<PEGASUS_ARRAY_T>::append(const PEGASUS_ARRAY_T* x, Uint32 size) | void Array<PEGASUS_ARRAY_T>::append(const PEGASUS_ARRAY_T* x, Uint32 size) |
{ | { |
reserve(this->size() + size); | reserve(this->size() + size); |
_copyOnWrite(); |
|
#if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) | #if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
CopyToRaw<PEGASUS_ARRAY_T>(_data() + this->size(), x, size); | CopyToRaw<PEGASUS_ARRAY_T>(_data() + this->size(), x, size); |
#else | #else |
|
|
#else | #else |
PEGASUS_TEMPLATE_SPECIALIZATION | PEGASUS_TEMPLATE_SPECIALIZATION |
#endif | #endif |
|
void Array<PEGASUS_ARRAY_T>::appendArray(const Array<PEGASUS_ARRAY_T>& x) |
|
{ |
|
append(x.getData(), x.size()); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
void Array<PEGASUS_ARRAY_T>::prepend(const PEGASUS_ARRAY_T& x) | void Array<PEGASUS_ARRAY_T>::prepend(const PEGASUS_ARRAY_T& x) |
{ | { |
reserve(size() + 1); |
prepend(&x, 1); |
_copyOnWrite(); |
|
memmove(_data() + 1, _data(), sizeof(PEGASUS_ARRAY_T) * size()); |
|
new(_data()) PEGASUS_ARRAY_T(x); |
|
_rep->size++; |
|
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
void Array<PEGASUS_ARRAY_T>::prepend(const PEGASUS_ARRAY_T* x, Uint32 size) | void Array<PEGASUS_ARRAY_T>::prepend(const PEGASUS_ARRAY_T* x, Uint32 size) |
{ | { |
reserve(this->size() + size); | reserve(this->size() + size); |
_copyOnWrite(); |
|
memmove(_data() + size, _data(), sizeof(PEGASUS_ARRAY_T) * this->size()); | memmove(_data() + size, _data(), sizeof(PEGASUS_ARRAY_T) * this->size()); |
#if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) | #if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
CopyToRaw<PEGASUS_ARRAY_T>(_data(), x, size); | CopyToRaw<PEGASUS_ARRAY_T>(_data(), x, size); |
|
|
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::insert(Uint32 pos, const PEGASUS_ARRAY_T& x) | void Array<PEGASUS_ARRAY_T>::insert(Uint32 pos, const PEGASUS_ARRAY_T& x) |
{ | { |
if (pos > size()) |
insert(pos, &x, 1); |
ThrowOutOfBounds(); |
|
|
|
reserve(size() + 1); |
|
_copyOnWrite(); |
|
|
|
Uint32 n = size() - pos; |
|
|
|
if (n) |
|
memmove(_data() + pos + 1, _data() + pos, sizeof(PEGASUS_ARRAY_T) * n); |
|
|
|
new(_data() + pos) PEGASUS_ARRAY_T(x); |
|
_rep->size++; |
|
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::insert(Uint32 pos, const PEGASUS_ARRAY_T* x, Uint32 size) | void Array<PEGASUS_ARRAY_T>::insert(Uint32 pos, const PEGASUS_ARRAY_T* x, Uint32 size) |
{ | { |
if (pos + size > this->size()) |
if (pos > this->size()) |
ThrowOutOfBounds(); | ThrowOutOfBounds(); |
| |
reserve(this->size() + size); | reserve(this->size() + size); |
_copyOnWrite(); |
|
| |
Uint32 n = this->size() - pos; | Uint32 n = this->size() - pos; |
| |
|
|
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::remove(Uint32 pos) | void Array<PEGASUS_ARRAY_T>::remove(Uint32 pos) |
{ | { |
if (pos >= this->size()) |
remove(pos, 1); |
ThrowOutOfBounds(); |
|
|
|
_copyOnWrite(); |
|
|
|
#if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
|
Destroy<PEGASUS_ARRAY_T>(_data() + pos); |
|
#else |
|
Destroy(_data() + pos); |
|
#endif |
|
|
|
Uint32 rem = this->size() - pos - 1; |
|
|
|
if (rem) |
|
memmove(_data() + pos, _data() + pos + 1, sizeof(PEGASUS_ARRAY_T) * rem); |
|
|
|
_rep->size--; |
|
} | } |
| |
#ifndef PEGASUS_ARRAY_T | #ifndef PEGASUS_ARRAY_T |
|
|
#endif | #endif |
void Array<PEGASUS_ARRAY_T>::remove(Uint32 pos, Uint32 size) | void Array<PEGASUS_ARRAY_T>::remove(Uint32 pos, Uint32 size) |
{ | { |
if (pos + size > this->size()) |
if (pos + size - 1 > this->size()) |
ThrowOutOfBounds(); | ThrowOutOfBounds(); |
| |
_copyOnWrite(); |
|
|
|
#if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) | #if defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) |
Destroy<PEGASUS_ARRAY_T>(_data() + pos, size); | Destroy<PEGASUS_ARRAY_T>(_data() + pos, size); |
#else | #else |
|
|
void Array<PEGASUS_ARRAY_T>::etoa() | void Array<PEGASUS_ARRAY_T>::etoa() |
{ | { |
#if PEGASUS_ARRAY_T == Sint8 | #if PEGASUS_ARRAY_T == Sint8 |
_copyOnWrite(); |
|
__etoa_l((char *)_data(),_rep->size); | __etoa_l((char *)_data(),_rep->size); |
#endif | #endif |
} | } |
|
|
void Array<PEGASUS_ARRAY_T>::atoe() | void Array<PEGASUS_ARRAY_T>::atoe() |
{ | { |
#if PEGASUS_ARRAY_T == Sint8 | #if PEGASUS_ARRAY_T == Sint8 |
_copyOnWrite(); |
|
__atoe_l((char *)_data(),_rep->size); | __atoe_l((char *)_data(),_rep->size); |
#endif | #endif |
} | } |
| |
#endif | #endif |
| |
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::begin() |
|
{ |
|
return _rep->data(); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::end() |
|
{ |
|
return _rep->data() + size(); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
const PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::begin() const |
|
{ |
|
return getData(); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
const PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::end() const |
|
{ |
|
return getData() + size(); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
void Array<PEGASUS_ARRAY_T>::set(ArrayRep<PEGASUS_ARRAY_T>* rep) |
|
{ |
|
if (_rep != rep) |
|
{ |
|
Rep::destroy(_rep); |
|
_rep = rep->clone(); |
|
} |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::_data() const |
|
{ |
|
return _rep->data(); |
|
} |
|
|
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
Boolean operator==( |
|
const Array<PEGASUS_ARRAY_T>& x, |
|
const Array<PEGASUS_ARRAY_T>& y) |
|
{ |
|
return Equal(x, y); |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
PEGASUS_ARRAY_T& Array<PEGASUS_ARRAY_T>::operator[](Uint32 pos) |
|
{ |
|
if (pos >= size()) |
|
ThrowOutOfBounds(); |
|
|
|
return _rep->data()[pos]; |
|
} |
|
|
|
#ifndef PEGASUS_ARRAY_T |
|
template<class PEGASUS_ARRAY_T> |
|
#else |
|
PEGASUS_TEMPLATE_SPECIALIZATION |
|
#endif |
|
const PEGASUS_ARRAY_T& Array<PEGASUS_ARRAY_T>::operator[]( |
|
Uint32 pos) const |
|
{ |
|
if (pos >= size()) |
|
ThrowOutOfBounds(); |
|
|
|
return _rep->data()[pos]; |
|
} |
|
|
#endif /*defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)*/ | #endif /*defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)*/ |