Advertisement
Tyler_Elric

Iterable.cpp

Feb 9th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "Iterable.h"
  2.  
  3. //Iterable::UnneededAllocation.
  4. void Iterable::Allocate(unsigned int l){}
  5.  
  6. Iterable::UnneededAllocation::UnneededAllocation(unsigned int size):mNumRemaining(size){
  7.     throw *this;
  8. }
  9.  
  10. unsigned int Iterable::UnneededAllocation::remaining(){ return mNumRemaining; }
  11.  
  12. //Iterable::Slice.
  13. Iterable::Slice::Slice(signed long int aStart,signed long int aEnd):mStart(aStart),mEnd(aEnd){}
  14.  
  15. Iterable::Slice::Slice(const Iterable::Slice& sl):mStart(sl.mStart),mEnd(sl.mEnd){}
  16.  
  17. unsigned int Iterable::Slice::start(unsigned int len) const
  18. {
  19.     unsigned int ret = ( mStart < 0 ) ? mStart + len: mStart;
  20.     if( ret < 0 || ret > len ) throw std::range_error("Slice::mStart indice out of given bounds.");
  21.     return ret;
  22. }
  23.  
  24. unsigned int Iterable::Slice::end(unsigned int len) const
  25. {
  26.     unsigned int ret = ( mEnd < 0 ) ? mEnd + len: mEnd;
  27.     if( ret < 0 || ret > len ) throw std::range_error("Slice::mEnd indice out of given bounds.");
  28.     return ret;
  29. }
  30.  
  31. //Iterable.
  32. unsigned int Iterable::gBufferSize = 1;
  33.  
  34. Iterable::Iterable(): mUsed(0),mAlloc(0)
  35. {
  36.     return;
  37. }
  38.  
  39. unsigned int Iterable::newSize(unsigned int len)
  40. {
  41.     if ( len + mUsed <= mAlloc ) UnneededAllocation(mAlloc - mUsed - len);
  42.     unsigned int nLen = mAlloc;
  43.     while ( nLen < mUsed + len ) nLen += gBufferSize;
  44.     return nLen;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement