]>
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.5 2005/09/23 12:52:18 MR
10 * Nuke #pragma implementation/interface's
12 * Revision 1.4 2005/05/31 09:19:38 JS
13 * Typo correction patch [ 1208110 ] Lots of typo corrections
16 * Revision 1.3 2004/08/06 17:27:18 ABX
17 * Deleting void is undefined.
19 * Revision 1.2 2002/01/16 13:39:50 GT
20 * Added checks for wxUSE_IOSTREAMH to determine which iostream(.h) to use
22 * Revision 1.1 1999/06/07 09:57:12 KB
23 * Formerly known as wxLayout.
25 * Revision 1.3 1998/11/19 20:34:50 KB
28 * Revision 1.8 1998/09/23 08:57:27 KB
29 * changed deletion behaviour
31 * Revision 1.7 1998/08/16 21:21:29 VZ
33 * 1) fixed config file bug: it was never created (attempt to create ~/.M/config
34 * always failed, must mkdir("~/.M") first)
35 * 2) "redesign" of "Folder properties" dialog and bug corrected, small change to
36 * MInputBox (it was too wide)
37 * 3) bug in ProvFC when it didn't recognize the books as being in the correct
38 * format (=> messages "can't reopen book") corrected
39 * 4) I tried to enhance MDialog_About(), but it didn't really work... oh well,
40 * I've never said I was an artist
42 * Revision 1.6 1998/07/08 11:56:56 KB
43 * M compiles and runs on Solaris 2.5/gcc 2.8/c-client gso
45 * Revision 1.5 1998/06/27 20:07:18 KB
46 * several bug fixes for kbList
47 * started adding my layout stuff
49 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
52 * Revision 1.4 1998/05/24 14:48:00 KB
53 * lots of progress on Python, but cannot call functions yet
56 * Revision 1.3 1998/05/18 17:48:34 KB
57 * more list<>->kbList changes, fixes for wxXt, improved makefiles
59 * Revision 1.2 1998/05/14 16:39:31 VZ
61 * fixed SIGSEGV in ~kbList if the list is empty
63 * Revision 1.1 1998/05/13 19:02:11 KB
64 * added kbList, adapted MimeTypes for it, more python, new icons
66 *******************************************************************/
68 #include "wx/wxprec.h"
79 kbListNode::kbListNode( void *ielement
,
92 kbListNode::~kbListNode()
101 kbList::iterator::iterator(kbListNode
*n
)
107 kbList::iterator::operator*()
109 return node
->element
;
113 kbList::iterator::operator++()
115 node
= node
? node
->next
: NULL
;
120 kbList::iterator::operator--()
122 node
= node
? node
->prev
: NULL
;
126 kbList::iterator::operator++(int /* foo */)
132 kbList::iterator::operator--(int /* bar */)
139 kbList::iterator::operator !=(kbList::iterator
const & i
) const
141 return node
!= i
.node
;
145 kbList::iterator::operator ==(kbList::iterator
const & i
) const
147 return node
== i
.node
;
150 kbList::kbList(bool ownsEntriesFlag
)
154 ownsEntries
= ownsEntriesFlag
;
158 kbList::push_back(void *element
)
160 if(! first
) // special case of empty list
162 first
= new kbListNode(element
);
167 last
= new kbListNode(element
, last
);
171 kbList::push_front(void *element
)
173 if(! first
) // special case of empty list
179 first
= new kbListNode(element
, NULL
, first
);
183 kbList::pop_back(void)
187 bool ownsFlagBak
= ownsEntries
;
192 ownsEntries
= ownsFlagBak
;
197 kbList::pop_front(void)
201 bool ownsFlagBak
= ownsEntries
;
207 ownsEntries
= ownsFlagBak
;
213 kbList::insert(kbList::iterator
& i
, void *element
)
217 else if(i
.Node() == first
)
223 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
227 kbList::doErase(kbList::iterator
& i
)
233 if(! node
) // illegal iterator
239 // correct first/last:
242 if(node
== last
) // don't put else here!
251 // delete this node and contents:
252 // now done separately
257 // change the iterator to next element:
258 i
= kbList::iterator(next
);
265 while ( first
!= NULL
)
271 delete first
->element
;
273 wxLogError(wxT("Deleting `void*' is undefined."));
274 wxLogError(wxT("Entries of kbList should be deleted by destructors of derived classes."));
283 kbList::begin(void) const
285 return kbList::iterator(first
);
289 kbList::tail(void) const
291 return kbList::iterator(last
);
295 kbList::end(void) const
297 return kbList::iterator(NULL
); // the one after the last
301 kbList::size(void) const // inefficient
305 for(i
= begin(); i
!= end(); i
++, count
++)
319 #include <iostream.h>
324 KBLIST_DEFINE(kbListInt
,int);
335 for(n
= 0; n
< 10; n
++)
342 i
= l
.begin(); // first element
345 i
++; // 4th, insert here:
350 // this cannot work, because l.end() returns NULL:
351 i
= l
.end(); // behind last
352 i
--; // still behind last
353 l
.erase(i
); // doesn't do anything
356 i
= l
.tail(); // last element
359 l
.erase(i
); // erase 3rd last element (49)
361 for(i
= l
.begin(); i
!= l
.end(); i
++)
362 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;