(file) Return to ArrayImpl.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/ArrayImpl.h between version 1.9 and 1.12

version 1.9, 2002/05/13 23:07:52 version 1.12, 2002/05/17 22:33:30
Line 22 
Line 22 
 // //
 // 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)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 35 
Line 35 
 #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
Line 45 
Line 45 
 #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
Line 100 
Line 100 
 #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
Line 113 
Line 113 
 { {
     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;
 } }
Line 126 
Line 126 
 #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
Line 135 
Line 135 
 #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);
Line 145 
Line 147 
 #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;
     }     }
 } }
Line 173 
Line 161 
 { {
     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;
Line 201 
Line 188 
 #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++;
 } }
Line 217 
Line 233 
 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
Line 231 
Line 246 
 #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
Line 248 
Line 269 
 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);
Line 265 
Line 285 
 #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
Line 287 
Line 295 
 #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;
  
Line 314 
Line 321 
 #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
Line 340 
Line 331 
 #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
Line 370 
Line 359 
 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
 } }
Line 383 
Line 371 
 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)*/


Legend:
Removed from v.1.9  
changed lines
  Added in v.1.12

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2