#ifndef __UNBOUNDED_HPP #define __UNBOUNDED_HPP #include class Unmanaged { Unmanaged(); void operator=(Unmanaged &); public: static void *alloc(size_t s) { return ::operator new(s); } static void free(void *p, size_t) { ::operator delete(p); } }; template class Node { public: Node *prev, *next; Item item; Node(const Item& i,Node *p, Node *n) : prev(p), next(n), item(i) { if(prev) prev->next=this; if(next) next->prev=this; } ~Node() { if(prev) prev->next=next; if(next) next->prev=prev; } static void *operator new(size_t s) { return StorageManager::alloc(s); } static void operator delete(void *p, size_t s) { StorageManager::free(p,s); } }; template class Unbounded { public: Unbounded(); Unbounded(const Unbounded&); virtual ~Unbounded(); Unbounded operator=(const Unbounded&); void clear(); void insert(const Item &); void insert(const Item &, unsigned before); void append(const Item &); void append(const Item &, unsigned after); void remove(unsigned at); void replace(unsigned at, const Item &); int isEmpty() const; unsigned length() const; const Item& first() const; const Item& last() const; const Item& itemAt(unsigned at) const; Item& itemAt(unsigned at); const Item& operator[](unsigned at) const { return itemAt(at); } Item& operator[](unsigned at) { return itemAt(at); } private: Node *left, *right; unsigned size; Node *cache; unsigned cacheIndex; Node* seek(unsigned index) const; Node* seek(unsigned index); }; #include "unbounded.cpp" #endif