cgma
CGMAIterator.hpp
Go to the documentation of this file.
00001 
00012 /* (2006) kraftche@cae.wisc.edu */
00013 /* Renamed from TSTTGIterator to CGMAIterator - J.Kraftcheck - 2007/6/15 */
00014 
00015 #ifndef CGMA_ITERATOR_HPP
00016 #define CGMA_ITERATOR_HPP
00017 
00018 class RefEntity;
00019 
00020 #include <DLIList.hpp>
00021 #include <vector>
00022 #include <algorithm>
00023 
00024 class CGMAIterator
00025 {
00026 public:
00027 
00033   CGMAIterator( DLIList<RefEntity*>& list, int size ) 
00034     : mArray(list.size()),
00035       mIter(mArray.begin()),
00036       mSize(size)
00037   {
00038     list.copy_to( &mArray[0] );
00039   }
00040   
00042   void reset() { mIter = mArray.begin(); }
00043   
00054   bool next( RefEntity** array, int& array_size )
00055   {
00056     if (array_size <= 0) {
00057       array_size = 0;
00058     }
00059     else {
00060       std::vector<RefEntity*>::const_iterator end = mArray.end();
00061       if ((end - mIter) > array_size)
00062         end = mIter + array_size;
00063       RefEntity** ptr = std::copy( mIter, end, array );
00064       array_size = ptr - array;
00065       mIter += array_size;
00066     }
00067     return mIter == mArray.end();
00068   }
00069  
00080   int size() const { return mSize; }
00081   
00082   bool at_end() const
00083     { return mIter == mArray.end(); }
00084 
00085 private:
00086 
00087   std::vector<RefEntity*> mArray;
00088   std::vector<RefEntity*>::const_iterator mIter;
00089   int mSize;
00090 };
00091 
00092 #endif
00093 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines