#ifndef _COMMON_BLOCK_HPP_ #define _COMMON_BLOCK_HPP_ #ifndef _COMMON_EXCEPTION_HPP_ #include #endif #ifndef _COMMON_WINDOWS_HPP_ #include #endif #ifndef _COMMON_ARRAY_HPP_ #include #endif #ifndef _MSC_VER #ifdef _EXPAND_BLOCK_TEMPLATES_ #pragma option -Jgd #endif #endif template class Block; template class Container { friend class Block; public: Container *next(); void next(Container *nextItem); Container *prev(); void prev(Container *prevItem); private: Container *mNext; Container *mPrev; T *mItem; Container(void); virtual ~Container(); }; template class Block { public: class BlockBoundary{}; typedef LONG Index; Block(void); Block(const Block &someBlock); virtual ~Block(void); LONG size(void)const; void insert(const T& item); void insert(const T *item); bool insertAfter(Index itemIndex,const T *item); void insert(Block &newBlock); void remove(void); void remove(const T *item); void remove(Block &removeBlock); void remove(Index itemIndex); void toArray(Array &array); Block &operator=(const Block &someBlock); WORD operator==(const Block &someBlock)const; T &operator[](LONG itemIndex); Block &operator+=(const Block &someBlock); private: T &find(LONG itemIndex); LONG mSize; LONG mLastIndexReferenced; Container *mLastObjectReferenced; Container *mLastObjectInserted; Container *mContainer; }; template inline Block::Block(void) : mContainer(0), mSize(0), mLastIndexReferenced(-1), mLastObjectReferenced(0), mLastObjectInserted(0) { } template inline Block::Block(const Block &someBlock) : mContainer(0), mSize(0), mLastIndexReferenced(-1), mLastObjectReferenced(0), mLastObjectInserted(0) { *this=someBlock; } template inline Block::~Block() { remove(); } template inline LONG Block::size(void)const { return mSize; } template inline T & Block::operator [](LONG itemIndex) { if(itemIndex>=mSize)throw(BoundaryError()); if(!mContainer)return *((T*)0); else if(itemIndex==mLastIndexReferenced&&-1!=mLastIndexReferenced&&mLastObjectReferenced)return *mLastObjectReferenced->mItem; else if(itemIndex==mLastIndexReferenced+1&&-1!=mLastIndexReferenced) { mLastIndexReferenced++; mLastObjectReferenced=mLastObjectReferenced->next(); return *mLastObjectReferenced->mItem; } return find(itemIndex); } template inline void Block::toArray(Array &array) { array.size(size()); for(int index=0;index inline Container::Container() : mNext(0), mPrev(0), mItem(0) { } template inline Container::~Container() { if(mItem)delete mItem; } template inline Container *Container::next(void) { return mNext; } template inline void Container::next(Container *nextItem) { mNext=nextItem; } template inline Container *Container::prev(void) { return mPrev; } template inline void Container::prev(Container *prevItem) { mPrev=prevItem; } #if defined(_MSC_VER) #include #endif #endif