]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/kbList.cpp
1 /*-*- c++ -*-********************************************************
2 * kbList.cc : a double linked list *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
9 * Revision 1.2 1998/08/12 08:33:23 KB
10 * Cursor and insert/delete work much better now, code streamlined, still
11 * a minor problem left.
13 * Revision 1.6 1998/07/08 11:56:56 KB
14 * M compiles and runs on Solaris 2.5/gcc 2.8/c-client gso
16 * Revision 1.5 1998/06/27 20:07:18 KB
17 * several bug fixes for kbList
18 * started adding my layout stuff
20 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
23 * Revision 1.4 1998/05/24 14:48:00 KB
24 * lots of progress on Python, but cannot call functions yet
27 * Revision 1.3 1998/05/18 17:48:34 KB
28 * more list<>->kbList changes, fixes for wxXt, improved makefiles
30 * Revision 1.2 1998/05/14 16:39:31 VZ
32 * fixed SIGSEGV in ~kbList if the list is empty
34 * Revision 1.1 1998/05/13 19:02:11 KB
35 * added kbList, adapted MimeTypes for it, more python, new icons
37 *******************************************************************/
40 # pragma implementation "kbList.h"
49 kbListNode::kbListNode( void *ielement
,
62 kbListNode::~kbListNode()
71 kbList::iterator::iterator(kbListNode
*n
)
77 kbList::iterator::operator*()
83 kbList::iterator::operator++()
85 node
= node
? node
->next
: NULL
;
90 kbList::iterator::operator--()
92 node
= node
? node
->prev
: NULL
;
96 kbList::iterator::operator++(int foo
)
102 kbList::iterator::operator--(int bar
)
109 kbList::iterator::operator !=(kbList::iterator
const & i
) const
111 return node
!= i
.node
;
115 kbList::iterator::operator ==(kbList::iterator
const & i
) const
117 return node
== i
.node
;
120 kbList::kbList(bool ownsEntriesFlag
)
124 ownsEntries
= ownsEntriesFlag
;
128 kbList::push_back(void *element
)
130 if(! first
) // special case of empty list
132 first
= new kbListNode(element
);
137 last
= new kbListNode(element
, last
);
141 kbList::push_front(void *element
)
143 if(! first
) // special case of empty list
149 first
= new kbListNode(element
, NULL
, first
);
153 kbList::pop_back(void)
157 bool ownsFlagBak
= ownsEntries
;
162 ownsEntries
= ownsFlagBak
;
167 kbList::pop_front(void)
171 bool ownsFlagBak
= ownsEntries
;
177 ownsEntries
= ownsFlagBak
;
183 kbList::insert(kbList::iterator
& i
, void *element
)
187 else if(i
.Node() == first
)
193 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
197 kbList::erase(kbList::iterator
& i
)
203 if(! node
) // illegal iterator
209 // correct first/last:
212 if(node
== last
) // don't put else here!
221 // delete this node and contents:
226 // change the iterator to next element:
227 i
= kbList::iterator(next
);
234 while ( first
!= NULL
)
238 delete first
->element
;
245 kbList::begin(void) const
247 return kbList::iterator(first
);
251 kbList::tail(void) const
253 return kbList::iterator(last
);
257 kbList::end(void) const
259 return kbList::iterator(NULL
); // the one after the last
263 kbList::size(void) const // inefficient
267 for(i
= begin(); i
!= end(); i
++, count
++)
280 #include <iostream.h>
282 KBLIST_DEFINE(kbListInt
,int);
293 for(n
= 0; n
< 10; n
++)
300 i
= l
.begin(); // first element
303 i
++; // 4th, insert here:
308 // this cannot work, because l.end() returns NULL:
309 i
= l
.end(); // behind last
310 i
--; // still behind last
311 l
.erase(i
); // doesn't do anything
314 i
= l
.tail(); // last element
317 l
.erase(i
); // erase 3rd last element (49)
319 for(i
= l
.begin(); i
!= l
.end(); i
++)
320 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;