24#ifndef ODLINKEDARRAY_H_INCLUDED
25#define ODLINKEDARRAY_H_INCLUDED
38template <
class T,
class A = OdObjectsAllocator<T> >
54 PAGE* page = (PAGE*)
::odrxAlloc(
sizeof(PAGE) + pageSize *
sizeof(T));
64 A::destroyRange(items(), _size);
72 return *(items(
index));
77 return *(items(
index));
83 A::copyConstruct(items(_size),
value);
90 A::copyAssignRange(items(i+1), items(i), moved);
91 A::copyConstruct(items(i),
value);
97 A::copyConstructFill(items(_size), newSize-_size,
value);
103 A::defaultConstructFill(items(_size), newSize-_size);
107 A::destroyRange(items(0), _size - newSize);
111 void moveFrom(PAGE* src,
size_type start)
115 A::copyAssignRangeDisjoint(items(_size), src->items(), start);
118 A::copyAssignRange(src->items(), src->items(start), src->_size);
122 A::destroyRange(items(i), 1);
125 A::copyAssignRange(items(i), items(i+1), _size - i);
129 A::destroyRange(items(_size--), 1);
134 return (T*)((
OdUInt8*)
this +
sizeof(PAGE)) + i;
150 PAGE* page = PAGE::allocate(_pageSize);
169 PAGE* page = PAGE::allocate(_pageSize);
179 _first->_prev = page;
180 page->_next = _first;
193 prev->_next->_prev = page;
194 page->_next = prev->_next;
223 , _pageSize(pageSize)
248 PAGE *next, *curr = _first;
270 T
data = _last->at(_last->_size - 1);
276 PAGE* p = _last->_prev;
287 class const_iterator :
public std::iterator<std::bidirectional_iterator_tag, T, void>
297 operator const T*()
const {
340 return (!(*
this == it));
393 return this->_page->at(this->_ind);
396 return &(this->_page->at(this->_ind));
456 return iterator(_last, (_last ? _last->_size : 0));
475 while (it != endIt && *it != val)
491 while (it != endIt && *it != val)
512 int d = newSize -
size();
518 if(_last->_size < _pageSize) {
519 d0 =
odmin(d, (
int)(_pageSize - _last->_size));
520 _last->resize(_last->_size + d0);
524 while (d && _last->_next) {
525 _last = _last->_next;
527 d0 =
odmin(d, (
int)_pageSize);
533 while (d>=(
int)_pageSize)
535 addPage()->resize(_pageSize);
541 addPage()->resize(d);
549 PAGE* pToRemove = _last;
550 _last = _last->_prev;
551 pToRemove->release();
584 PAGE* curPage = before._page;
586 if (curPage->_size < _pageSize)
588 curPage->insertAt(curInd, val);
592 PAGE* prevPage = curPage->_prev;
593 if (!prevPage || (prevPage->_size + curInd) >= _pageSize)
595 prevPage = insertPage(prevPage);
599 prevPage->moveFrom(curPage, curInd);
602 prevPage->append(val);
603 before =
iterator(prevPage, prevPage->_size-1);
616 PAGE* curPage = at._page;
617 if (curPage == _last && curInd == (_last->_size - 1))
619 T
data = curPage->at(curInd);
620 if (curPage->_size == 1)
623 curPage->_prev->_next = curPage->_next;
625 this->_first = curPage->_next;
627 curPage->_next->_prev = curPage->_prev;
633 curPage->remove(curInd);
643 if (_last && _last->_size < _pageSize)
645 _last->append(
value);
649 addPage()->append(
value);
702 itemNums += page->_size;
715 PAGE *curr = _last->_next;
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
ALLOCDLL_EXPORT void odrxFree(void *pMemBlock)
bool operator==(const const_iterator &it) const
const_iterator & operator++()
const_iterator operator-=(int n)
bool operator!=(const const_iterator &it) const
OD_TYPENAME2 OD_LINKEDARRAY_SCOPE PAGE * _page
const_iterator(OD_TYPENAME2 OD_LINKEDARRAY_SCOPE PAGE *page, unsigned ind=0)
const_iterator operator++(int)
const_iterator & operator--()
const T * operator->() const
const_iterator operator--(int)
const_iterator operator+=(int n)
const T & operator*() const
iterator operator-=(int n)
iterator operator+=(int n)
iterator find(const T &val)
void append(const T &value)
const_iterator find(const T &val) const
iterator insert(iterator before, const T &val=T())
bool contains(const T &val) const
void resize(size_type newSize)
const_iterator begin() const
const_iterator end() const
OdLinkedArray(OdUInt32 pageSize=0x10)
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
GLsizei const GLfloat * value