(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.4 and 1.13

version 1.4, 2001/07/10 06:43:21 version 1.13, 2002/05/28 22:13:48
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)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #if defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)  //#if defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)
   // 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 <Pegasus/Common/Memory.h>
   #include <Pegasus/Common/ArrayRep.h>
   
   #ifdef PEGASUS_HAS_EBCDIC
   #include <unistd.h>
   #endif
   
   PEGASUS_NAMESPACE_BEGIN
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
 template<class PEGASUS_ARRAY_T> template<class PEGASUS_ARRAY_T>
Line 35 
Line 51 
 #endif #endif
 Array<PEGASUS_ARRAY_T>::Array() Array<PEGASUS_ARRAY_T>::Array()
 { {
     _rep = Rep::getNullRep();      _rep = ArrayRep<PEGASUS_ARRAY_T>::create(0);
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 45 
Line 61 
 #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 = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(x._rep)->clone();
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 55 
Line 71 
 #endif #endif
 Array<PEGASUS_ARRAY_T>::Array(Uint32 size) Array<PEGASUS_ARRAY_T>::Array(Uint32 size)
 { {
     _rep = Rep::create(size);      _rep = ArrayRep<PEGASUS_ARRAY_T>::create(size);
     InitializeRaw(_rep->data(), size);      InitializeRaw(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data(), size);
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 66 
Line 82 
 #endif #endif
 Array<PEGASUS_ARRAY_T>::Array(Uint32 size, const PEGASUS_ARRAY_T& x) Array<PEGASUS_ARRAY_T>::Array(Uint32 size, const PEGASUS_ARRAY_T& x)
 { {
     _rep = Rep::create(size);      _rep = ArrayRep<PEGASUS_ARRAY_T>::create(size);
  
     PEGASUS_ARRAY_T* data = _rep->data();      PEGASUS_ARRAY_T* data = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data();
  
     while (size--)     while (size--)
         new(data++) PEGASUS_ARRAY_T(x);         new(data++) PEGASUS_ARRAY_T(x);
Line 81 
Line 97 
 #endif #endif
 Array<PEGASUS_ARRAY_T>::Array(const PEGASUS_ARRAY_T* items, Uint32 size) Array<PEGASUS_ARRAY_T>::Array(const PEGASUS_ARRAY_T* items, Uint32 size)
 { {
     _rep = Rep::create(size);      _rep = ArrayRep<PEGASUS_ARRAY_T>::create(size);
     CopyToRaw(_rep->data(), items, size);      CopyToRaw(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data(), items, size);
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 92 
Line 108 
 #endif #endif
 Array<PEGASUS_ARRAY_T>::~Array() Array<PEGASUS_ARRAY_T>::~Array()
 { {
     Rep::dec(_rep);      ArrayRep<PEGASUS_ARRAY_T>::destroy(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep));
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 103 
Line 119 
 Array<PEGASUS_ARRAY_T>& Array<PEGASUS_ARRAY_T>::operator=( Array<PEGASUS_ARRAY_T>& Array<PEGASUS_ARRAY_T>::operator=(
     const Array<PEGASUS_ARRAY_T>& x)     const Array<PEGASUS_ARRAY_T>& x)
 { {
     if (x._rep != _rep)      if (static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(x._rep) !=
           static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep))
     {     {
         Rep::dec(_rep);          ArrayRep<PEGASUS_ARRAY_T>::destroy(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep));
         Rep::inc(_rep = x._rep);          _rep = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(x._rep)->clone();
     }     }
     return *this;     return *this;
 } }
Line 118 
Line 135 
 #endif #endif
 void Array<PEGASUS_ARRAY_T>::clear() void Array<PEGASUS_ARRAY_T>::clear()
 { {
     Rep::dec(_rep);      ArrayRep<PEGASUS_ARRAY_T>::destroy(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep));
     _rep = Rep::getNullRep();      _rep = ArrayRep<PEGASUS_ARRAY_T>::create(0);
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 127 
Line 144 
 #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 > static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->capacity)
 { {
     Uint32 size = this->size();     Uint32 size = this->size();
     Rep* rep = Rep::create(capacity);          ArrayRep<PEGASUS_ARRAY_T>* rep = ArrayRep<PEGASUS_ARRAY_T>::create(capacity);
     rep->size = size;     rep->size = size;
     CopyToRaw(rep->data(), _rep->data(), size);          CopyToRaw(rep->data(), static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data(), size);
     Rep::dec(_rep);          ArrayRep<PEGASUS_ARRAY_T>::destroy(static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep));
     _rep = rep;     _rep = rep;
 } }
   }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
 template<class PEGASUS_ARRAY_T> template<class PEGASUS_ARRAY_T>
 #else #else
 PEGASUS_TEMPLATE_SPECIALIZATION PEGASUS_TEMPLATE_SPECIALIZATION
 #endif #endif
 void Array<PEGASUS_ARRAY_T>::_copyOnWriteAux()  void Array<PEGASUS_ARRAY_T>::grow(Uint32 size, const PEGASUS_ARRAY_T& x)
 { {
     if (_rep->ref != 1)      Uint32 oldSize = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size;
       reserve(oldSize + size);
   
       PEGASUS_ARRAY_T* p = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data() + oldSize;
       Uint32 n = size;
   
       while (n--)
           new(p++) PEGASUS_ARRAY_T(x);
   
       static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size += size;
   }
   
   #ifndef PEGASUS_ARRAY_T
   template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   void Array<PEGASUS_ARRAY_T>::swap(Array<PEGASUS_ARRAY_T>& x)
     {     {
         Rep* rep = _rep->clone();      ArrayRep<PEGASUS_ARRAY_T>* tmp = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep);
         Rep::dec(_rep);      _rep = static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(x._rep);
         _rep = rep;      x._rep = tmp;
     }     }
   
   #ifndef PEGASUS_ARRAY_T
   template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   Uint32 Array<PEGASUS_ARRAY_T>::size() const
   {
       return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size;
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 157 
Line 203 
 #else #else
 PEGASUS_TEMPLATE_SPECIALIZATION PEGASUS_TEMPLATE_SPECIALIZATION
 #endif #endif
 void Array<PEGASUS_ARRAY_T>::grow(Uint32 size, const PEGASUS_ARRAY_T& x)  Uint32 Array<PEGASUS_ARRAY_T>::getCapacity() const
 { {
     Uint32 oldSize = _rep->size;      return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->capacity;
     reserve(oldSize + size);  }
     _copyOnWrite();  
  
     PEGASUS_ARRAY_T* p = _rep->data() + oldSize;  #ifndef PEGASUS_ARRAY_T
     Uint32 n = size;  template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   const PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::getData() const
   {
       return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data();
   }
  
     while (n--)  #ifndef PEGASUS_ARRAY_T
         new(p++) PEGASUS_ARRAY_T(x);  template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   PEGASUS_ARRAY_T& Array<PEGASUS_ARRAY_T>::operator[](Uint32 pos)
   {
       if (pos >= size())
           ThrowOutOfBounds();
  
     _rep->size += size;      return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data()[pos];
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 177 
Line 236 
 #else #else
 PEGASUS_TEMPLATE_SPECIALIZATION PEGASUS_TEMPLATE_SPECIALIZATION
 #endif #endif
 void Array<PEGASUS_ARRAY_T>::swap(Array<PEGASUS_ARRAY_T>& x)  const PEGASUS_ARRAY_T& Array<PEGASUS_ARRAY_T>::operator[](Uint32 pos) const
 { {
     Rep* tmp = _rep;      if (pos >= size())
     _rep = x._rep;          ThrowOutOfBounds();
     x._rep = tmp;  
       return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data()[pos];
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 192 
Line 252 
 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++;      static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size++;
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 205 
Line 264 
 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();  
     CopyToRaw(_data() + this->size(), x, size);     CopyToRaw(_data() + this->size(), x, size);
     _rep->size += size;      static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size += size;
   }
   
   #ifndef PEGASUS_ARRAY_T
   template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   void Array<PEGASUS_ARRAY_T>::appendArray(const Array<PEGASUS_ARRAY_T>& x)
   {
       append(x.getData(), x.size());
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 217 
Line 285 
 #endif #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 232 
Line 296 
 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());
     CopyToRaw(_data(), x, size);     CopyToRaw(_data(), x, size);
     _rep->size += size;      static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size += size;
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 245 
Line 308 
 #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 267 
Line 318 
 #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 280 
Line 330 
             _data() + pos + size, _data() + pos, sizeof(PEGASUS_ARRAY_T) * n);             _data() + pos + size, _data() + pos, sizeof(PEGASUS_ARRAY_T) * n);
  
     CopyToRaw(_data() + pos, x, size);     CopyToRaw(_data() + pos, x, size);
     _rep->size += size;      static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size += size;
 } }
  
 #ifndef PEGASUS_ARRAY_T #ifndef PEGASUS_ARRAY_T
Line 290 
Line 340 
 #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();  
   
     Destroy(_data() + pos);  
   
     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 312 
Line 350 
 #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();  
   
     Destroy(_data() + pos, size);     Destroy(_data() + pos, size);
  
     Uint32 rem = this->size() - (pos + size);     Uint32 rem = this->size() - (pos + size);
Line 325 
Line 361 
         memmove(         memmove(
             _data() + pos, _data() + pos + size, sizeof(PEGASUS_ARRAY_T) * rem);             _data() + pos, _data() + pos + size, sizeof(PEGASUS_ARRAY_T) * rem);
  
     _rep->size -= size;      static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size -= size;
   }
   
   #ifdef PEGASUS_HAS_EBCDIC
   
   #ifndef PEGASUS_ARRAY_T
   template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   void Array<PEGASUS_ARRAY_T>::etoa()
   {
   #if PEGASUS_ARRAY_T == Sint8
       __etoa_l((char *)_data(),static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size);
   #endif
   }
   
   #ifndef PEGASUS_ARRAY_T
   template<class PEGASUS_ARRAY_T>
   #else
   PEGASUS_TEMPLATE_SPECIALIZATION
   #endif
   void Array<PEGASUS_ARRAY_T>::atoe()
   {
   #if PEGASUS_ARRAY_T == Sint8
       __atoe_l((char *)_data(),static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->size);
   #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 static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_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 static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_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
   PEGASUS_ARRAY_T* Array<PEGASUS_ARRAY_T>::_data() const
   {
       return static_cast<ArrayRep<PEGASUS_ARRAY_T>*>(_rep)->data();
 } }
  
 #endif /*defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)*/  #endif //!defined(Pegasus_ArrayImpl_h) || !defined(PEGASUS_ARRAY_T)
   //#endif /*defined(PEGASUS_EXPLICIT_INSTANTIATION) || !defined(PEGASUS_ARRAY_T)*/


Legend:
Removed from v.1.4  
changed lines
  Added in v.1.13

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2