//%///////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, // The Open Group, Tivoli Systems // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //============================================================================== // // Author: Mike Brasher (mbrasher@bmc.com) // // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) // //%///////////////////////////////////////////////////////////////////////////// // Only include if not included as general template or if explicit instantiation #if !defined(Pegasus_ArrayImpl_h) || defined(PEGASUS_ARRAY_T) #if !defined(PEGASUS_ARRAY_T) #define Pegasus_ArrayImpl_h #endif PEGASUS_NAMESPACE_END #include #include #include PEGASUS_NAMESPACE_BEGIN #ifndef PEGASUS_ARRAY_T template #endif Array::Array() { _rep = ArrayRep::create(0); } #ifndef PEGASUS_ARRAY_T template #endif Array::Array(const Array& x) { _rep = static_cast*>(x._rep)->clone(); } #ifndef PEGASUS_ARRAY_T template #endif Array::Array(Uint32 size) { _rep = ArrayRep::create(size); if (_rep == 0) { throw NullPointer(); } InitializeRaw(static_cast*>(_rep)->data(), size); } #ifndef PEGASUS_ARRAY_T template #endif Array::Array(Uint32 size, const PEGASUS_ARRAY_T& x) { _rep = ArrayRep::create(size); if (_rep == 0) { throw NullPointer(); } PEGASUS_ARRAY_T* data = static_cast*>(_rep)->data(); while (size--) new(data++) PEGASUS_ARRAY_T(x); } #ifndef PEGASUS_ARRAY_T template #endif Array::Array(const PEGASUS_ARRAY_T* items, Uint32 size) { _rep = ArrayRep::create(size); if (_rep == 0) { throw NullPointer(); } CopyToRaw(static_cast*>(_rep)->data(), items, size); } #ifndef PEGASUS_ARRAY_T template #endif Array::~Array() { ArrayRep::destroy(static_cast*>(_rep)); } #ifndef PEGASUS_ARRAY_T template #endif Array& Array::operator=( const Array& x) { if (static_cast*>(x._rep) != static_cast*>(_rep)) { ArrayRep::destroy(static_cast*>(_rep)); _rep = static_cast*>(x._rep)->clone(); } return *this; } #ifndef PEGASUS_ARRAY_T template #endif void Array::clear() { ArrayRep::destroy(static_cast*>(_rep)); _rep = ArrayRep::create(0); } #ifndef PEGASUS_ARRAY_T template #endif void Array::reserveCapacity(Uint32 capacity) { if (capacity > static_cast*>(_rep)->capacity) { Uint32 size = this->size(); ArrayRep* rep = ArrayRep::create(capacity); if (rep != 0) { rep->size = size; CopyToRaw( rep->data(), static_cast*>(_rep)->data(), size); ArrayRep::destroy( static_cast*>(_rep)); _rep = rep; } } } #ifndef PEGASUS_ARRAY_T template #endif void Array::grow(Uint32 size, const PEGASUS_ARRAY_T& x) { Uint32 oldSize = static_cast*>(_rep)->size; reserveCapacity(oldSize + size); PEGASUS_ARRAY_T* p = static_cast*>(_rep)->data() + oldSize; Uint32 n = size; while (n--) new(p++) PEGASUS_ARRAY_T(x); static_cast*>(_rep)->size += size; } #ifndef PEGASUS_ARRAY_T template #endif void Array::swap(Array& x) { ArrayRep* tmp = static_cast*>(_rep); _rep = static_cast*>(x._rep); x._rep = tmp; } #ifndef PEGASUS_ARRAY_T template #endif Uint32 Array::size() const { return static_cast*>(_rep)->size; } #ifndef PEGASUS_ARRAY_T template #endif Uint32 Array::getCapacity() const { return static_cast*>(_rep)->capacity; } #ifndef PEGASUS_ARRAY_T template #endif const PEGASUS_ARRAY_T* Array::getData() const { return static_cast*>(_rep)->data(); } #ifndef PEGASUS_ARRAY_T template #endif PEGASUS_ARRAY_T& Array::operator[](Uint32 index) { if (index >= size()) throw IndexOutOfBoundsException(); return static_cast*>(_rep)->data()[index]; } #ifndef PEGASUS_ARRAY_T template #endif const PEGASUS_ARRAY_T& Array::operator[](Uint32 index) const { if (index >= size()) throw IndexOutOfBoundsException(); return static_cast*>(_rep)->data()[index]; } #ifndef PEGASUS_ARRAY_T template #endif void Array::append(const PEGASUS_ARRAY_T& x) { reserveCapacity(size() + 1); new (_data() + size()) PEGASUS_ARRAY_T(x); static_cast*>(_rep)->size++; } #ifndef PEGASUS_ARRAY_T template #endif void Array::append(const PEGASUS_ARRAY_T* x, Uint32 size) { reserveCapacity(this->size() + size); CopyToRaw(_data() + this->size(), x, size); static_cast*>(_rep)->size += size; } #ifndef PEGASUS_ARRAY_T template #endif void Array::appendArray(const Array& x) { append(x.getData(), x.size()); } #ifndef PEGASUS_ARRAY_T template #endif void Array::prepend(const PEGASUS_ARRAY_T& x) { prepend(&x, 1); } #ifndef PEGASUS_ARRAY_T template #endif void Array::prepend(const PEGASUS_ARRAY_T* x, Uint32 size) { reserveCapacity(this->size() + size); memmove(_data() + size, _data(), sizeof(PEGASUS_ARRAY_T) * this->size()); CopyToRaw(_data(), x, size); static_cast*>(_rep)->size += size; } #ifndef PEGASUS_ARRAY_T template #endif void Array::insert(Uint32 index, const PEGASUS_ARRAY_T& x) { insert(index, &x, 1); } #ifndef PEGASUS_ARRAY_T template #endif void Array::insert(Uint32 index, const PEGASUS_ARRAY_T* x, Uint32 size) { if (index > this->size()) throw IndexOutOfBoundsException(); reserveCapacity(this->size() + size); Uint32 n = this->size() - index; if (n) memmove(_data() + index + size, _data() + index, sizeof(PEGASUS_ARRAY_T) * n); CopyToRaw(_data() + index, x, size); static_cast*>(_rep)->size += size; } #ifndef PEGASUS_ARRAY_T template #endif void Array::remove(Uint32 index) { remove(index, 1); } #ifndef PEGASUS_ARRAY_T template #endif void Array::remove(Uint32 index, Uint32 size) { if (index + size - 1 > this->size()) throw IndexOutOfBoundsException(); Destroy(_data() + index, size); Uint32 rem = this->size() - (index + size); if (rem) memmove(_data() + index, _data() + index + size, sizeof(PEGASUS_ARRAY_T) * rem); static_cast*>(_rep)->size -= size; } #ifndef PEGASUS_ARRAY_T template #endif PEGASUS_ARRAY_T* Array::_data() const { return static_cast*>(_rep)->data(); } #endif //!defined(Pegasus_ArrayImpl_h) || !defined(PEGASUS_ARRAY_T)