| 39 | Stack(Stack<Object, Capacity>&); // not implemented |
| 40 | |
| 41 | class Entry : public Vector<Object, Capacity> |
| 42 | { |
| 43 | private: |
| 44 | typedef Vector<Object, Capacity> inherited; |
| 45 | public: |
| 46 | Entry* next; |
| 47 | |
| 48 | Entry(Object e, Entry* stk) |
| 49 | : inherited(), next(stk) |
| 50 | { |
| 51 | this->add(e); |
| 52 | } |
| 53 | |
| 54 | Entry(Entry* stk) : inherited(), next(stk) { } |
| 55 | |
| 56 | ~Entry() |
| 57 | { |
| 58 | delete next; |
| 59 | } |
| 60 | |
| 61 | Entry* push(Object e, MemoryPool& p) |
| 62 | { |
| 63 | if (inherited::getCount() < this->getCapacity()) |
| 64 | { |
| 65 | this->add(e); |
| 66 | return this; |
| 67 | } |
| 68 | Entry* newEntry = FB_NEW_POOL(p) Entry(e, this); |
| 69 | return newEntry; |
| 70 | } |
| 71 | |
| 72 | Object pop() |
| 73 | { |
| 74 | fb_assert(inherited::getCount() > 0); |
| 75 | return this->data[--this->count]; |
| 76 | } |
| 77 | |
| 78 | Object getObject(FB_SIZE_T pos) const |
| 79 | { |
| 80 | return this->data[pos]; |
| 81 | } |
| 82 | |
| 83 | void split(FB_SIZE_T elem, Entry* target) |
| 84 | { |
| 85 | fb_assert(elem > 0 && elem < this->count); |
| 86 | fb_assert(target->count == 0); |
| 87 | target->count = this->count - elem; |
| 88 | memcpy(target->data, &this->data[elem], target->count * sizeof(Object)); |
| 89 | this->count = elem; |
| 90 | } |
| 91 | |
| 92 | Entry* dup(MemoryPool& p) |
| 93 | { |
| 94 | Entry* rc = FB_NEW_POOL(p) Entry(next ? next->dup(p) : 0); |
| 95 | rc->join(*this); |
| 96 | return rc; |
| 97 | } |
| 98 | |