]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/kbList.cpp
8d6d0327495b001dbdbc6ac41145495ffa2ee28d
1 /*-*- c++ -*-********************************************************
2 * kbList.cc : a double linked list *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
9 * Revision 1.4 2005/05/31 09:19:38 JS
10 * Typo correction patch [ 1208110 ] Lots of typo corrections
13 * Revision 1.3 2004/08/06 17:27:18 ABX
14 * Deleting void is undefined.
16 * Revision 1.2 2002/01/16 13:39:50 GT
17 * Added checks for wxUSE_IOSTREAMH to determine which iostream(.h) to use
19 * Revision 1.1 1999/06/07 09:57:12 KB
20 * Formerly known as wxLayout.
22 * Revision 1.3 1998/11/19 20:34:50 KB
25 * Revision 1.8 1998/09/23 08:57:27 KB
26 * changed deletion behaviour
28 * Revision 1.7 1998/08/16 21:21:29 VZ
30 * 1) fixed config file bug: it was never created (attempt to create ~/.M/config
31 * always failed, must mkdir("~/.M") first)
32 * 2) "redesign" of "Folder properties" dialog and bug corrected, small change to
33 * MInputBox (it was too wide)
34 * 3) bug in ProvFC when it didn't recognize the books as being in the correct
35 * format (=> messages "can't reopen book") corrected
36 * 4) I tried to enhance MDialog_About(), but it didn't really work... oh well,
37 * I've never said I was an artist
39 * Revision 1.6 1998/07/08 11:56:56 KB
40 * M compiles and runs on Solaris 2.5/gcc 2.8/c-client gso
42 * Revision 1.5 1998/06/27 20:07:18 KB
43 * several bug fixes for kbList
44 * started adding my layout stuff
46 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
49 * Revision 1.4 1998/05/24 14:48:00 KB
50 * lots of progress on Python, but cannot call functions yet
53 * Revision 1.3 1998/05/18 17:48:34 KB
54 * more list<>->kbList changes, fixes for wxXt, improved makefiles
56 * Revision 1.2 1998/05/14 16:39:31 VZ
58 * fixed SIGSEGV in ~kbList if the list is empty
60 * Revision 1.1 1998/05/13 19:02:11 KB
61 * added kbList, adapted MimeTypes for it, more python, new icons
63 *******************************************************************/
66 # pragma implementation "kbList.h"
69 #include "wx/wxprec.h"
80 kbListNode::kbListNode( void *ielement
,
93 kbListNode::~kbListNode()
102 kbList::iterator::iterator(kbListNode
*n
)
108 kbList::iterator::operator*()
110 return node
->element
;
114 kbList::iterator::operator++()
116 node
= node
? node
->next
: NULL
;
121 kbList::iterator::operator--()
123 node
= node
? node
->prev
: NULL
;
127 kbList::iterator::operator++(int /* foo */)
133 kbList::iterator::operator--(int /* bar */)
140 kbList::iterator::operator !=(kbList::iterator
const & i
) const
142 return node
!= i
.node
;
146 kbList::iterator::operator ==(kbList::iterator
const & i
) const
148 return node
== i
.node
;
151 kbList::kbList(bool ownsEntriesFlag
)
155 ownsEntries
= ownsEntriesFlag
;
159 kbList::push_back(void *element
)
161 if(! first
) // special case of empty list
163 first
= new kbListNode(element
);
168 last
= new kbListNode(element
, last
);
172 kbList::push_front(void *element
)
174 if(! first
) // special case of empty list
180 first
= new kbListNode(element
, NULL
, first
);
184 kbList::pop_back(void)
188 bool ownsFlagBak
= ownsEntries
;
193 ownsEntries
= ownsFlagBak
;
198 kbList::pop_front(void)
202 bool ownsFlagBak
= ownsEntries
;
208 ownsEntries
= ownsFlagBak
;
214 kbList::insert(kbList::iterator
& i
, void *element
)
218 else if(i
.Node() == first
)
224 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
228 kbList::doErase(kbList::iterator
& i
)
234 if(! node
) // illegal iterator
240 // correct first/last:
243 if(node
== last
) // don't put else here!
252 // delete this node and contents:
253 // now done separately
258 // change the iterator to next element:
259 i
= kbList::iterator(next
);
266 while ( first
!= NULL
)
272 delete first
->element
;
274 wxLogError(wxT("Deleting `void*' is undefined."));
275 wxLogError(wxT("Entries of kbList should be deleted by destructors of derived classes."));
284 kbList::begin(void) const
286 return kbList::iterator(first
);
290 kbList::tail(void) const
292 return kbList::iterator(last
);
296 kbList::end(void) const
298 return kbList::iterator(NULL
); // the one after the last
302 kbList::size(void) const // inefficient
306 for(i
= begin(); i
!= end(); i
++, count
++)
320 #include <iostream.h>
325 KBLIST_DEFINE(kbListInt
,int);
336 for(n
= 0; n
< 10; n
++)
343 i
= l
.begin(); // first element
346 i
++; // 4th, insert here:
351 // this cannot work, because l.end() returns NULL:
352 i
= l
.end(); // behind last
353 i
--; // still behind last
354 l
.erase(i
); // doesn't do anything
357 i
= l
.tail(); // last element
360 l
.erase(i
); // erase 3rd last element (49)
362 for(i
= l
.begin(); i
!= l
.end(); i
++)
363 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;