00001 #ifndef LIST_CLASS
00002 #define LIST_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "node_dll.h"
00019
00020 namespace nodes {
00021
00022 class node;
00023
00025
00036 class NODES_CLASS_STYLE list
00037 {
00038 public:
00039 list();
00041
00042 ~list();
00044
00045 int elements() const;
00047
00049 bool empty() const;
00051
00053
00054
00058 class NODES_CLASS_STYLE iterator {
00059 public:
00060 iterator(const list *mgr, node *start) : _cursor(start), _manager(mgr) {}
00062
00065 void operator ++();
00066 void operator --();
00067 void operator ++(int) { ++(*this); }
00068 void operator --(int) { --(*this); }
00069
00070
00071 inline void next() { (*this)++; }
00072 inline void previous() { (*this)--; }
00073
00074 bool operator ==(const iterator &to_compare) const;
00076 bool operator !=(const iterator &tc) const { return !(*this == tc); }
00078
00079 bool is_head() const;
00081
00090 bool is_tail() const;
00092
00093 void jump_head();
00094 void jump_tail();
00095
00096 const node *observe();
00097
00105 node *access();
00106
00107 private:
00108 node *_cursor;
00109 friend class list;
00110 const list *_manager;
00111 };
00112
00113 iterator head() const { return iterator(this, _head); }
00115 iterator tail() const { return iterator(this, _tail); }
00117
00118 int index(const iterator &it) const { return items_from_head(it); }
00120
00122 bool set_index(iterator &to_set, int new_index);
00124
00125
00126
00127
00128
00129 void append(iterator &where, node *new_node);
00131
00135 void insert(iterator &where, node *new_node);
00137
00142 node *remove(iterator &where);
00144
00148 void zap(iterator &where);
00150
00153 void zap_all();
00155
00157
00158
00159
00160
00161 bool forward(iterator &where, int count);
00163
00166 bool backward(iterator &where, int count);
00168
00169 int items_from_head(const iterator &where) const;
00171
00172 int items_from_tail(const iterator &where) const;
00174
00176 private:
00177 friend class iterator;
00178 node *_head;
00179 node *_tail;
00180
00181 bool skip_or_ignore(iterator &where, int count);
00183
00184
00185 list(const list &);
00186 list &operator =(const list &);
00187 };
00188
00189 }
00190
00191 #endif
00192