]>
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.2 2002/01/16 13:39:50 GT
10 * Added checks for wxUSE_IOSTREAMH to determine which iostream(.h) to use
12 * Revision 1.1 1999/06/07 09:57:12 KB
13 * Formerly known as wxLayout.
15 * Revision 1.3 1998/11/19 20:34:50 KB
18 * Revision 1.8 1998/09/23 08:57:27 KB
19 * changed deletion behaviour
21 * Revision 1.7 1998/08/16 21:21:29 VZ
23 * 1) fixed config file bug: it was never created (attempt to create ~/.M/config
24 * always failed, must mkdir("~/.M") first)
25 * 2) "redesign" of "Folder properties" dialog and bug corrected, small change to
26 * MInputBox (it was too wide)
27 * 3) bug in ProvFC when it didn't reckognize the books as being in the correct
28 * format (=> messages "can't reopen book") corrected
29 * 4) I tried to enhance MDialog_About(), but it didn't really work... oh well,
30 * I've never said I was an artist
32 * Revision 1.6 1998/07/08 11:56:56 KB
33 * M compiles and runs on Solaris 2.5/gcc 2.8/c-client gso
35 * Revision 1.5 1998/06/27 20:07:18 KB
36 * several bug fixes for kbList
37 * started adding my layout stuff
39 * Revision 1.1.1.1 1998/06/13 21:51:12 karsten
42 * Revision 1.4 1998/05/24 14:48:00 KB
43 * lots of progress on Python, but cannot call functions yet
46 * Revision 1.3 1998/05/18 17:48:34 KB
47 * more list<>->kbList changes, fixes for wxXt, improved makefiles
49 * Revision 1.2 1998/05/14 16:39:31 VZ
51 * fixed SIGSEGV in ~kbList if the list is empty
53 * Revision 1.1 1998/05/13 19:02:11 KB
54 * added kbList, adapted MimeTypes for it, more python, new icons
56 *******************************************************************/
59 # pragma implementation "kbList.h"
65 kbListNode::kbListNode( void *ielement
,
78 kbListNode::~kbListNode()
87 kbList::iterator::iterator(kbListNode
*n
)
93 kbList::iterator::operator*()
99 kbList::iterator::operator++()
101 node
= node
? node
->next
: NULL
;
106 kbList::iterator::operator--()
108 node
= node
? node
->prev
: NULL
;
112 kbList::iterator::operator++(int /* foo */)
118 kbList::iterator::operator--(int /* bar */)
125 kbList::iterator::operator !=(kbList::iterator
const & i
) const
127 return node
!= i
.node
;
131 kbList::iterator::operator ==(kbList::iterator
const & i
) const
133 return node
== i
.node
;
136 kbList::kbList(bool ownsEntriesFlag
)
140 ownsEntries
= ownsEntriesFlag
;
144 kbList::push_back(void *element
)
146 if(! first
) // special case of empty list
148 first
= new kbListNode(element
);
153 last
= new kbListNode(element
, last
);
157 kbList::push_front(void *element
)
159 if(! first
) // special case of empty list
165 first
= new kbListNode(element
, NULL
, first
);
169 kbList::pop_back(void)
173 bool ownsFlagBak
= ownsEntries
;
178 ownsEntries
= ownsFlagBak
;
183 kbList::pop_front(void)
187 bool ownsFlagBak
= ownsEntries
;
193 ownsEntries
= ownsFlagBak
;
199 kbList::insert(kbList::iterator
& i
, void *element
)
203 else if(i
.Node() == first
)
209 i
= kbList::iterator(new kbListNode(element
, i
.Node()->prev
, i
.Node()));
213 kbList::doErase(kbList::iterator
& i
)
219 if(! node
) // illegal iterator
225 // correct first/last:
228 if(node
== last
) // don't put else here!
237 // delete this node and contents:
238 // now done separately
243 // change the iterator to next element:
244 i
= kbList::iterator(next
);
251 while ( first
!= NULL
)
255 delete first
->element
;
262 kbList::begin(void) const
264 return kbList::iterator(first
);
268 kbList::tail(void) const
270 return kbList::iterator(last
);
274 kbList::end(void) const
276 return kbList::iterator(NULL
); // the one after the last
280 kbList::size(void) const // inefficient
284 for(i
= begin(); i
!= end(); i
++, count
++)
298 #include <iostream.h>
303 KBLIST_DEFINE(kbListInt
,int);
314 for(n
= 0; n
< 10; n
++)
321 i
= l
.begin(); // first element
324 i
++; // 4th, insert here:
329 // this cannot work, because l.end() returns NULL:
330 i
= l
.end(); // behind last
331 i
--; // still behind last
332 l
.erase(i
); // doesn't do anything
335 i
= l
.tail(); // last element
338 l
.erase(i
); // erase 3rd last element (49)
340 for(i
= l
.begin(); i
!= l
.end(); i
++)
341 cout
<< *i
<< '\t' << *((int *)*i
) << endl
;