home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / c / WLIB.ZIP / WOBJVEC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-06  |  3.3 KB  |  172 lines

  1. #include "VecLocal.h"
  2. #pragma hdrstop
  3.  
  4. // copyright (c) 1992, 1993 by Paul Wheaton
  5.  
  6. //.parse
  7.  
  8. void ObjVec::ExtraAlloc(long Quan)
  9.   {
  10.     ByteVector::ExtraAlloc(Quan*BlockSize);
  11.   }
  12.  
  13. //.parse
  14.  
  15. void ObjVec::CopyFrom(void* Source, long Quan)
  16.   {
  17.     ByteVector::CopyFrom(Source,Quan*ObjSize);
  18.   }
  19.  
  20. //.parse
  21.  
  22. void ObjVec::AppendOneObj(void* X)
  23.   {
  24.     memcpy(Ref(Size()),X,ObjSize);
  25.   }
  26.  
  27. //.parse
  28.  
  29. ObjVec ObjVec::PrependOneObj(void* X) const
  30.   {
  31.     ObjVec V(ObjSize,X);
  32.     V+=*this;
  33.     return V;
  34.   }
  35.  
  36. //.parse
  37.  
  38. void ObjVec::operator+=(const ObjVec& V)
  39.   {ByteVector::operator+=(*((ByteVector*)&V));}
  40.  
  41. //.parse
  42.  
  43. void* ObjVec::Ref(long Index)
  44.   {
  45.     ByteVector::Ref(((Index+1)*BlockSize)-1);
  46.     return PtrInc(P,Index*BlockSize);
  47.   }
  48.  
  49. //.parse
  50.  
  51. void ObjVec::Insert(const ObjVec& V,long Index)
  52.   { ByteVector::Insert(*((ByteVector*)&V),Index*BlockSize); }
  53.  
  54. //.parse
  55.  
  56. void ObjVec::Insert(void* X,long Index)
  57.   {
  58.     ObjVec V(ObjSize,X);
  59.     ByteVector::Insert(*((ByteVector*)&V),Index*BlockSize);
  60.   }
  61.  
  62. //.parse
  63.  
  64. void ObjVec::Delete(long Index,long Length)
  65.   { ByteVector::Delete(Index*BlockSize,Length*BlockSize); }
  66.  
  67. //.parse
  68.  
  69. void ObjVec::operator=(const ObjVec& V){Assign(*((ByteVector*)&V));}
  70.  
  71. //.parse
  72.  
  73. void ObjVec::CopyTo(void* Dest, long Quan) const
  74.   {
  75.     ByteVector::CopyTo(Dest,Quan*ObjSize);
  76.   }
  77.  
  78. //.parse
  79.  
  80. ObjVec ObjVec::Concat(void* X) const
  81.   {
  82.     ObjVec V(*this);
  83.     memcpy(V.Ref(Size()),X,ObjSize);
  84.     return V;
  85.   }
  86.  
  87. //.parse
  88.  
  89. ObjVec ObjVec::Concat(const ObjVec&V2) const
  90.   {
  91.     ObjVec V3(*this);
  92.     V3+=V2;
  93.     return V3;
  94.   }
  95.  
  96. //.parse
  97.  
  98. void ObjVec::CtorHelper(int ObjectSize)
  99.   {
  100.     ObjSize=ObjectSize;
  101.     BlockSize=ObjectSize;
  102.   }
  103.  
  104. ObjVec::ObjVec(int ObjectSize):ByteVector()
  105.   {CtorHelper(ObjectSize);}
  106.  
  107. ObjVec::ObjVec(int ObjectSize,void* X):ByteVector(X,ObjectSize)
  108.   {CtorHelper(ObjectSize);}
  109.  
  110. ObjVec::ObjVec(int ObjectSize,void* P, long Len):ByteVector(P,ObjectSize*Len)
  111.   {CtorHelper(ObjectSize);}
  112.  
  113. ObjVec::ObjVec(const ObjVec& V):ByteVector(*((ByteVector*)&V))
  114.   {CtorHelper(V.ObjSize);}
  115.  
  116. //.parse
  117.  
  118. void ObjVec::Empty(){ByteVector::Empty();}
  119. ObjVec::operator ConstVoidPointerType()const{return P;}
  120. long ObjVec::Capacity()const{return (Alloc/BlockSize);}
  121. long ObjVec::ByteCapacity()const{return Alloc;}
  122. long ObjVec::ReAlloc(long NewCap){return ByteVector::ReAlloc(NewCap*BlockSize);}
  123. long ObjVec::Size()const{return Len/BlockSize;}
  124.  
  125. //.parse
  126.  
  127. long ObjVec::Index(void* SearchObj, long StartIndex) const
  128.   {
  129.     if (StartIndex>=Size()) return(VecObjNotFound);
  130.     long I=StartIndex;
  131.     while ((I<Size()) && (memcmp(SearchObj,PtrInc(P,I*BlockSize),ObjSize)!=0)) I++;
  132.     if (I==Size()) return(VecObjNotFound);
  133.     else return(I);
  134.   }
  135.  
  136. //.parse
  137.  
  138. ObjVec ObjVec::After(long Index) const
  139.   {
  140.     return At(Index+1,Size()-Index-1);
  141.   }
  142.  
  143. //.parse
  144.  
  145. ObjVec ObjVec::From(long Index) const
  146.   {
  147.     return At(Index,Size()-Index);
  148.   }
  149.  
  150. //.parse
  151.  
  152. void* ObjVec::At(long I) const
  153.   {
  154.     if (I>=Size()) I=Size()-1;
  155.     return PtrInc(P,I*BlockSize);
  156.   }
  157.  
  158. //.parse
  159.  
  160. ObjVec ObjVec::At(long I,long L) const
  161.   {
  162.     long S=Size();
  163.     ObjVec V(ObjSize);
  164.     if (I<S)
  165.       {
  166.         if (I+L>=S) L=S-I;
  167.         *((ByteVector*)&V)=ByteVector::At(I*BlockSize,L*BlockSize);
  168.       }
  169.     return V;
  170.   }
  171.  
  172.