]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/kbList.cpp
1 /*-*- c++ -*-********************************************************
2 * kbList.cc : a double linked list *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
9 * Revision 1.3 2004/08/06 17:27:18 ABX
10 * Deleting void is undefined.
12 * Revision 1.2 2002/01/16 13:39:50 GT
13 * Added checks for wxUSE_IOSTREAMH to determine which iostream(.h) to use
15 * Revision 1.1 1999/06/07 09:57:12 KB
16 * Formerly known as wxLayout.
18 * Revision 1.3 1998/11/19 20:34:50 KB
21 * Revision 1.8 1998/09/23 08:57:27 KB
22 * changed deletion behaviour
24 * Revision 1.7 1998/08/16 21:21:29 VZ
26 * 1) fixed config file bug: it was never created (attempt to create ~/.M/config
27 * always failed, must mkdir("~/.M") first)
28 * 2) "redesign" of "Folder properties" dialog and bug corrected, small change to
29 * MInputBox (it was too wide)
30 * 3) bug in ProvFC when it didn't reckognize the books as being in the correct
31 * format (=> messages "can't reopen book") corrected
32 * 4) I tried to enhance MDialog_About(), but it didn't really work... oh well,
33 * I've never said I was an artist
35 * Revision 1.6 1998/07/08 11:56:56 KB
36 * M compiles and runs on Solaris 2.5/gcc 2.8/c-client gso
38 * Revision 1.5 1998/06/27 20:07:18 KB
39 * several bug fixes for kbList
40 * started adding my layout stuff
42 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
45 * Revision 1.4 1998/05/24 14:48:00 KB
46 * lots of progress on Python, but cannot call functions yet
49 * Revision 1.3 1998/05/18 17:48:34 KB
50 * more list<>->kbList changes, fixes for wxXt, improved makefiles
52 * Revision 1.2 1998/05/14 16:39:31 VZ
54 * fixed SIGSEGV in ~kbList if the list is empty
56 * Revision 1.1 1998/05/13 19:02:11 KB
57 * added kbList, adapted MimeTypes for it, more python, new icons
59 *******************************************************************/
62 # pragma implementation "kbList.h"
65 #include "wx/wxprec.h"
76 kbListNode::kbListNode( void *ielement
,
89 kbListNode::~kbListNode()
98 kbList::iterator::iterator(kbListNode
*n
)
104 kbList::iterator::operator*()
106 return node
->element
;
110 kbList::iterator::operator++()
112 node
= node
? node
->next
: NULL
;
117 kbList::iterator::operator--()
119 node
= node
? node
->prev
: NULL
;
123 kbList::iterator::operator++(int /* foo */)
129 kbList::iterator::operator--(int /* bar */)
136 kbList::iterator::operator !=(kbList::iterator
const & i
) const
138 return node
!= i
.node
;
142 kbList::iterator::operator ==(kbList::iterator
const & i
) const
144 return node
== i
.node
;
147 kbList::kbList(bool ownsEntriesFlag
)
151 ownsEntries
= ownsEntriesFlag
;
155 kbList::push_back(void *element
)
157 if(! first
) // special case of empty list
159 first
= new kbListNode(element
);
164 last
= new kbListNode(element
, last
);
168 kbList::push_front(void *element
)
170 if(! first
) // special case of empty list
176 first
= new kbListNode(element
, NULL
, first
);
180 kbList::pop_back(void)
184 bool ownsFlagBak
= ownsEntries
;
189 ownsEntries
= ownsFlagBak
;
194 kbList::pop_front(void)
198 bool ownsFlagBak
= ownsEntries
;
204 ownsEntries
= ownsFlagBak
;
210 kbList::insert(kbList::iterator
& i
, void *element
)
214 else if(i
.Node() == first
)
220 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
224 kbList::doErase(kbList::iterator
& i
)
230 if(! node
) // illegal iterator
236 // correct first/last:
239 if(node
== last
) // don't put else here!
248 // delete this node and contents:
249 // now done separately
254 // change the iterator to next element:
255 i
= kbList::iterator(next
);
262 while ( first
!= NULL
)
268 delete first
->element
;
270 wxLogError(wxT("Deleting `void*' is undefined."));
271 wxLogError(wxT("Entries of kbList should be deleted by destructors of derived classes."));
280 kbList::begin(void) const
282 return kbList::iterator(first
);
286 kbList::tail(void) const
288 return kbList::iterator(last
);
292 kbList::end(void) const
294 return kbList::iterator(NULL
); // the one after the last
298 kbList::size(void) const // inefficient
302 for(i
= begin(); i
!= end(); i
++, count
++)
316 #include <iostream.h>
321 KBLIST_DEFINE(kbListInt
,int);
332 for(n
= 0; n
< 10; n
++)
339 i
= l
.begin(); // first element
342 i
++; // 4th, insert here:
347 // this cannot work, because l.end() returns NULL:
348 i
= l
.end(); // behind last
349 i
--; // still behind last
350 l
.erase(i
); // doesn't do anything
353 i
= l
.tail(); // last element
356 l
.erase(i
); // erase 3rd last element (49)
358 for(i
= l
.begin(); i
!= l
.end(); i
++)
359 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;