25 #ifndef ODLINKEDARRAY_H_INCLUDED
26 #define ODLINKEDARRAY_H_INCLUDED
30 template <
class T,
class A = OdObjectsAllocator<T> >
57 A::destroy(items(),
_size);
66 return *(items(
index));
71 return *(items(
index));
85 A::move(items(i+1), items(i), moved);
86 A::construct(items(i),
value);
102 A::destroy(items(0),
_size - newSize);
111 A::copy(items(
_size), src->items(), start);
115 A::move(src->items(), src->items(start), src->
_size);
119 A::destroy(items(i), 1);
122 A::move(items(i), items(i+1),
_size - i);
126 A::destroy(items(
_size--), 1);
182 _first->
_prev = page;
183 page->_next = _first;
196 prev->_next->_prev = page;
197 page->_next = prev->_next;
225 , _pageSize(pageSize)
239 PAGE *next, *curr = _first;
254 PAGE *curr = _last->_next;
272 T
data = _last->at(_last->_size - 1);
278 PAGE* p = _last->_prev;
307 operator const T*()
const {
359 return (!(*
this == it));
421 return this->_page->at(this->_ind);
425 return &(this->_page->at(this->_ind));
473 return iterator(_first, 0);
477 return const_iterator(_first, 0);
481 return iterator(_last, (_last ? _last->_size : 0));
483 const_iterator
end()
const
485 return const_iterator(_last, (_last ? _last->_size : 0));
492 iterator it =
begin(),
494 while (it != endIt && *it != val)
500 const_iterator
find(
const T& val)
const
502 const_iterator it =
begin(),
504 while (it != endIt && *it != val)
513 const_iterator it =
find(val);
524 int d = newSize -
size();
530 if(_last->_size < _pageSize) {
531 d0 =
odmin(d, (
int)(_pageSize - _last->_size));
532 _last->resize(_last->_size + d0);
536 while (d && _last->_next) {
537 _last = _last->_next;
539 d0 =
odmin(d, (
int)_pageSize);
545 while (d>=(
int)_pageSize)
547 addPage()->
resize(_pageSize);
562 PAGE* pToRemove = _last;
563 _last = _last->_prev;
568 pToRemove->release();
579 iterator
insert(iterator before,
const T& val = T())
590 PAGE* curPage = before._page;
593 if (curPage->_size < _pageSize)
595 curPage->insertAt(curInd, val);
599 PAGE* prevPage = curPage->_prev;
600 if (!prevPage || (prevPage->_size + curInd) >= _pageSize)
602 prevPage = insertPage(prevPage);
606 prevPage->moveFrom(curPage, curInd);
609 prevPage->append(val);
610 before = iterator(prevPage, prevPage->_size-1);
621 PAGE* curPage = at._page;
622 if (curPage == _last && curInd == (_last->_size - 1))
624 T
data = curPage->at(curInd);
625 if (curPage->_size == 1)
628 curPage->_prev->_next = curPage->_next;
630 this->_first = curPage->_next;
632 curPage->_next->_prev = curPage->_prev;
638 curPage->remove(curInd);
646 if (_last && _last->_size < _pageSize)
648 _last->append(
value);
692 itemNums += page->_size;
702 #endif // ODLINKEDARRAY_H_INCLUDED