22 #ifndef ELM_GENSTRUCT_SLLIST_H
23 #define ELM_GENSTRUCT_SLLIST_H
25 #include <elm/assert.h>
26 #include <elm/PreIterator.h>
27 #include <elm/util/Equiv.h>
28 #include <elm/inhstruct/SLList.h>
30 namespace elm {
namespace genstruct {
33 template <
class T,
class E = Equiv<T> >
40 inline Node(
const T
value): val(value) { }
41 inline Node *next(
void)
const {
return nextNode(); }
42 inline Node *nextNode(
void)
const {
return static_cast<Node *
>(SLNode::next()); }
43 inline void removeNext(
void) { Node *n = nextNode(); SLNode::removeNext();
delete n; }
53 clear(); Iterator item(list);
if(!item)
return;
addFirst(*item); Node *cur = firstNode();
54 for(item++; item; item++) { cur->insertAfter(
new Node(*item)); cur = cur->next(); }
62 {
for(Iterator iter(*
this); iter; iter++)
if(E::equals(item, iter))
return true;
return false; }
64 inline operator bool(
void)
const {
return !
isEmpty(); }
74 inline bool ended(
void)
const {
return !node; }
75 inline const T&
item(
void)
const { ASSERT(node);
return node->val; }
77 { ASSERT(node); prev = node; node = node->next(); }
91 inline bool ended(
void)
const {
return !node; }
92 inline T&
item(
void)
const { ASSERT(node);
return node->val; }
94 { ASSERT(node); prev = node; node = node->next(); }
102 {
while(!_list.
isEmpty()) { Node *node = firstNode(); _list.
removeFirst();
delete node; } }
104 template <
class C>
inline void addAll(
const C& items)
105 {
for(
typename C::Iterator iter(items); iter; iter++)
add(iter); }
106 template <
class C>
inline void removeAll(
const C& items)
107 {
for(
typename C::Iterator iter(items); iter; iter++)
remove(iter); }
111 for(Node *prev = firstNode(), *cur = prev->nextNode(); cur; prev = cur, cur = cur->nextNode())
112 if(E::equals(cur->val,
value)) { prev->removeNext();
return; }
115 inline void remove(Iterator &iter) {
remove(iter.prev, iter.node); }
116 inline void remove(MutableIterator &iter) {
remove(iter.prev, iter.node); }
119 inline T&
first(
void) {
return firstNode()->val; }
120 inline const T&
first(
void)
const {
return firstNode()->val; }
121 inline T&
last(
void) {
return lastNode()->val; }
122 inline const T&
last(
void)
const {
return lastNode()->val; }
123 Iterator
find(
const T& item)
const
124 { Iterator iter(*
this);
for(; iter; iter++)
if(E::equals(item, iter))
break;
return iter; }
125 Iterator
find(
const T& item,
const Iterator& pos)
const
126 { Iterator iter(pos);
for(iter++; iter; iter++)
if(E::equals(item, iter))
break;
return iter; }
132 { ASSERT(pos.node); pos.node->insertAfter(
new Node(value)); }
134 {
if(!pos.prev)
addFirst(value);
else pos.prev->insertAfter(
new Node(value)); }
137 inline void set(
const Iterator &pos,
const T &item) { ASSERT(pos.node); pos.node->val = item; }
140 inline const T&
top(
void)
const {
return first(); }
152 inline Node *firstNode(
void)
const {
return static_cast<Node *
>(_list.
first()); }
153 inline Node *lastNode(
void)
const {
return static_cast<Node *
>(_list.
last()); }
154 void remove(Node* prev, Node*& cur) {
157 else { prev->removeNext(); cur = prev->next(); }
161 template <
class T,
class E> SLList<T, E> SLList<T, E>::null;
165 #endif // ELM_GENSTRUCT_SLLIST_H
void addAfter(const Iterator &pos, const T &value)
Definition: SLList.h:131
void addAll(const C &items)
Definition: SLList.h:104
Iterator & operator=(const Iterator &i)
Definition: SLList.h:72
void removeFirst(void)
Definition: SLList.h:67
void removeAll(const C &items)
Definition: SLList.h:106
void add(const T &value)
Definition: SLList.h:103
Definition: PreIterator.h:29
void reset(void)
Definition: SLList.h:143
T pop(void)
Definition: SLList.h:141
SLNode * last(void) const
Definition: inhstruct_SLList.cpp:59
const T & first(void) const
Definition: SLList.h:120
int count(void) const
Definition: inhstruct_SLList.cpp:74
Iterator find(const T &item, const Iterator &pos) const
Definition: SLList.h:125
bool ended(void) const
Definition: SLList.h:74
void next(void)
Definition: SLList.h:76
void removeFirst(void)
Definition: SLList.h:135
void addFirst(SLNode *node)
Definition: SLList.h:63
SLNode * first(void) const
Definition: SLList.h:60
Iterator(void)
Definition: SLList.h:69
SLList< T > & operator+=(const SLList< T > &l)
Definition: SLList.h:147
T & last(void)
Definition: SLList.h:121
void removeLast(void)
Definition: inhstruct_SLList.cpp:102
value_t value(CString name, int value)
Definition: rtti.h:40
void removeLast(void)
Definition: SLList.h:136
int count(void) const
Definition: SLList.h:60
const T & top(void) const
Definition: SLList.h:140
void addBefore(const Iterator &pos, const T &value)
Definition: SLList.h:133
SLList(void)
Definition: SLList.h:47
MutableIterator(SLList &_list)
Definition: SLList.h:87
Iterator(const SLList &_list)
Definition: SLList.h:70
SLList(const SLList &list)
Definition: SLList.h:48
~SLList(void)
Definition: SLList.h:50
bool isEmpty(void) const
Definition: SLList.h:63
bool ended(void) const
Definition: SLList.h:91
T & first(void)
Definition: SLList.h:119
bool contains(const T &item) const
Definition: SLList.h:61
MutableIterator & operator=(const MutableIterator &i)
Definition: SLList.h:89
SLList & operator=(const SLList &list)
Definition: SLList.h:49
T & item(void) const
Definition: SLList.h:92
Iterator(const Iterator &source)
Definition: SLList.h:71
Iterator find(const T &item) const
Definition: SLList.h:123
static SLList< T, E > null
Definition: SLList.h:57
const T & last(void) const
Definition: SLList.h:122
void addLast(SLNode *node)
Definition: inhstruct_SLList.cpp:90
void next(void)
Definition: SLList.h:93
MutableIterator(const MutableIterator &source)
Definition: SLList.h:88
void set(const Iterator &pos, const T &item)
Definition: SLList.h:137
void addFirst(const T &value)
Definition: SLList.h:129
void clear(void)
Definition: SLList.h:101
void addLast(const T &value)
Definition: SLList.h:130
const T & item(void) const
Definition: SLList.h:75
void copy(const SLList< T > &list)
Definition: SLList.h:52
SLList< T > & operator+=(const T &h)
Definition: SLList.h:146
void push(const T &i)
Definition: SLList.h:142
bool isEmpty(void) const
Definition: SLList.h:70
MutableIterator(void)
Definition: SLList.h:86