]>
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.1 1998/06/29 12:44:36 KB
10 * Added my wxWindows based layout engine to the repository.
11 * It arranges text and graphics for display on a wxDC.
12 * This code is licensed under the LGPL.
14 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
17 * Revision 1.4 1998/05/24 14:48:00 KB
18 * lots of progress on Python, but cannot call functions yet
21 * Revision 1.3 1998/05/18 17:48:34 KB
22 * more list<>->kbList changes, fixes for wxXt, improved makefiles
24 * Revision 1.2 1998/05/14 16:39:31 VZ
26 * fixed SIGSEGV in ~kbList if the list is empty
28 * Revision 1.1 1998/05/13 19:02:11 KB
29 * added kbList, adapted MimeTypes for it, more python, new icons
31 *******************************************************************/
34 # pragma implementation "kbList.h"
40 kbListNode::kbListNode( void *ielement
,
53 kbListNode::~kbListNode()
62 kbList::iterator::iterator(kbListNode
*n
)
68 kbList::iterator::operator*()
74 kbList::iterator::operator++()
76 node
= node
? node
->next
: NULL
;
81 kbList::iterator::operator--()
83 node
= node
? node
->prev
: NULL
;
87 kbList::iterator::operator++(int foo
)
93 kbList::iterator::operator--(int bar
)
100 kbList::iterator::operator !=(kbList::iterator
const & i
) const
102 return node
!= i
.node
;
106 kbList::iterator::operator ==(kbList::iterator
const & i
) const
108 return node
== i
.node
;
111 kbList::kbList(bool ownsEntriesFlag
)
115 ownsEntries
= ownsEntriesFlag
;
119 kbList::push_back(void *element
)
121 if(! first
) // special case of empty list
123 first
= new kbListNode(element
);
128 last
= new kbListNode(element
, last
);
132 kbList::push_front(void *element
)
134 if(! first
) // special case of empty list
140 first
= new kbListNode(element
, NULL
, first
);
144 kbList::pop_back(void)
148 bool ownsFlagBak
= ownsEntries
;
153 ownsEntries
= ownsFlagBak
;
158 kbList::pop_front(void)
162 bool ownsFlagBak
= ownsEntries
;
168 ownsEntries
= ownsFlagBak
;
174 kbList::insert(kbList::iterator
& i
, void *element
)
178 else if(i
.Node() == first
)
183 else if(i
.Node() == last
)
188 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
192 kbList::erase(kbList::iterator
& i
)
198 if(! node
) // illegal iterator
204 // correct first/last:
207 if(node
== last
) // don't put else here!
216 // delete this node and contents:
221 // change the iterator to next element:
222 i
= kbList::iterator(next
);
229 while ( first
!= NULL
)
233 delete first
->element
;
240 kbList::begin(void) const
242 return kbList::iterator(first
);
246 kbList::tail(void) const
248 return kbList::iterator(last
);
252 kbList::end(void) const
254 return kbList::iterator(NULL
); // the one after the last
258 kbList::size(void) const // inefficient
262 for(i
= begin(); i
!= end(); i
++, count
++)
275 #include <iostream.h>
277 KBLIST_DEFINE(kbListInt
,int);
288 for(n
= 0; n
< 10; n
++)
295 i
= l
.begin(); // first element
298 i
++; // 4th, insert here:
303 // this cannot work, because l.end() returns NULL:
304 i
= l
.end(); // behind last
305 i
--; // still behind last
306 l
.erase(i
); // doesn't do anything
309 i
= l
.tail(); // last element
312 l
.erase(i
); // erase 3rd last element (49)
314 for(i
= l
.begin(); i
!= l
.end(); i
++)
315 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;