diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-04-16 23:04:35 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-04-16 23:04:35 +0000 |
commit | 44057a75ef001bfd1919e2169ec3f7f355d14c20 (patch) | |
tree | 61cc7fe3ea5d54a24197a33bd7ec87edc5d8233b /src/list.h | |
parent | 900bf84c403caf83e18928b066544f402aae1122 (diff) | |
download | libbu++-44057a75ef001bfd1919e2169ec3f7f355d14c20.tar.gz libbu++-44057a75ef001bfd1919e2169ec3f7f355d14c20.tar.bz2 libbu++-44057a75ef001bfd1919e2169ec3f7f355d14c20.tar.xz libbu++-44057a75ef001bfd1919e2169ec3f7f355d14c20.zip |
Hey, the list code is better, also, I fixed some stuff in socket (the
isBlocking function was backward), and fastcgi is actually working now!
Also added comparison functions to FString.
Diffstat (limited to 'src/list.h')
-rw-r--r-- | src/list.h | 90 |
1 files changed, 65 insertions, 25 deletions
@@ -45,6 +45,9 @@ namespace Bu | |||
45 | typedef class List<value, cmpfunc, valuealloc, linkalloc> MyType; | 45 | typedef class List<value, cmpfunc, valuealloc, linkalloc> MyType; |
46 | 46 | ||
47 | public: | 47 | public: |
48 | struct const_iterator; | ||
49 | struct iterator; | ||
50 | |||
48 | List() : | 51 | List() : |
49 | pFirst( NULL ), | 52 | pFirst( NULL ), |
50 | pLast( NULL ), | 53 | pLast( NULL ), |
@@ -201,6 +204,32 @@ namespace Bu | |||
201 | } | 204 | } |
202 | } | 205 | } |
203 | 206 | ||
207 | void insert( MyType::iterator &i, const value &v ) | ||
208 | { | ||
209 | Link *pAfter = i.pLink; | ||
210 | if( pAfter == NULL ) | ||
211 | { | ||
212 | append( v ); | ||
213 | return; | ||
214 | } | ||
215 | Link *pPrev = pAfter->pPrev; | ||
216 | if( pPrev == NULL ) | ||
217 | { | ||
218 | prepend( v ); | ||
219 | return; | ||
220 | } | ||
221 | |||
222 | Link *pNew = la.allocate( 1 ); | ||
223 | pNew->pValue = va.allocate( 1 ); | ||
224 | va.construct( pNew->pValue, v ); | ||
225 | nSize++; | ||
226 | |||
227 | pNew->pNext = pAfter; | ||
228 | pNew->pPrev = pPrev; | ||
229 | pAfter->pPrev = pNew; | ||
230 | pPrev->pNext = pNew; | ||
231 | } | ||
232 | |||
204 | /** | 233 | /** |
205 | * Insert a new item in sort order by searching for the first item that | 234 | * Insert a new item in sort order by searching for the first item that |
206 | * is larger and inserting this before it, or at the end if none are | 235 | * is larger and inserting this before it, or at the end if none are |
@@ -250,7 +279,6 @@ namespace Bu | |||
250 | } | 279 | } |
251 | } | 280 | } |
252 | 281 | ||
253 | struct const_iterator; | ||
254 | /** | 282 | /** |
255 | * An iterator to iterate through your list. | 283 | * An iterator to iterate through your list. |
256 | */ | 284 | */ |
@@ -260,24 +288,30 @@ namespace Bu | |||
260 | friend class List<value, cmpfunc, valuealloc, linkalloc>; | 288 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
261 | private: | 289 | private: |
262 | Link *pLink; | 290 | Link *pLink; |
263 | MyType &rList; | 291 | MyType *pList; |
264 | bool bOffFront; | 292 | bool bOffFront; |
265 | iterator( MyType &rList ) : | 293 | iterator( MyType *pList ) : |
266 | pLink( NULL ), | 294 | pLink( NULL ), |
267 | rList( rList ) | 295 | pList( pList ) |
268 | { | 296 | { |
269 | } | 297 | } |
270 | 298 | ||
271 | iterator( Link *pLink, MyType &rList ) : | 299 | iterator( Link *pLink, MyType *pList ) : |
272 | pLink( pLink ), | 300 | pLink( pLink ), |
273 | rList( rList ) | 301 | pList( pList ) |
274 | { | 302 | { |
275 | } | 303 | } |
276 | 304 | ||
277 | public: | 305 | public: |
306 | iterator() : | ||
307 | pLink( NULL ), | ||
308 | pList( NULL ) | ||
309 | { | ||
310 | } | ||
311 | |||
278 | iterator( const iterator &i ) : | 312 | iterator( const iterator &i ) : |
279 | pLink( i.pLink ), | 313 | pLink( i.pLink ), |
280 | rList( i.rList ) | 314 | pList( i.pList ) |
281 | { | 315 | { |
282 | } | 316 | } |
283 | 317 | ||
@@ -342,7 +376,7 @@ namespace Bu | |||
342 | iterator &operator++() | 376 | iterator &operator++() |
343 | { | 377 | { |
344 | if( pLink == NULL ) | 378 | if( pLink == NULL ) |
345 | pLink = (bOffFront)?(rList.pFirst):(NULL); | 379 | pLink = (bOffFront)?(pList->pFirst):(NULL); |
346 | else | 380 | else |
347 | pLink = pLink->pNext; | 381 | pLink = pLink->pNext; |
348 | bOffFront = false; | 382 | bOffFront = false; |
@@ -352,7 +386,7 @@ namespace Bu | |||
352 | iterator &operator--() | 386 | iterator &operator--() |
353 | { | 387 | { |
354 | if( pLink == NULL ) | 388 | if( pLink == NULL ) |
355 | pLink = (bOffFront)?(NULL):(rList.pLast); | 389 | pLink = (bOffFront)?(NULL):(pList->pLast); |
356 | else | 390 | else |
357 | pLink = pLink->pPrev; | 391 | pLink = pLink->pPrev; |
358 | bOffFront = true; | 392 | bOffFront = true; |
@@ -362,7 +396,7 @@ namespace Bu | |||
362 | iterator &operator++( int ) | 396 | iterator &operator++( int ) |
363 | { | 397 | { |
364 | if( pLink == NULL ) | 398 | if( pLink == NULL ) |
365 | pLink = (bOffFront)?(rList.pFirst):(NULL); | 399 | pLink = (bOffFront)?(pList->pFirst):(NULL); |
366 | else | 400 | else |
367 | pLink = pLink->pNext; | 401 | pLink = pLink->pNext; |
368 | bOffFront = false; | 402 | bOffFront = false; |
@@ -372,7 +406,7 @@ namespace Bu | |||
372 | iterator &operator--( int ) | 406 | iterator &operator--( int ) |
373 | { | 407 | { |
374 | if( pLink == NULL ) | 408 | if( pLink == NULL ) |
375 | pLink = (bOffFront)?(NULL):(rList.pLast); | 409 | pLink = (bOffFront)?(NULL):(pList->pLast); |
376 | else | 410 | else |
377 | pLink = pLink->pPrev; | 411 | pLink = pLink->pPrev; |
378 | bOffFront = true; | 412 | bOffFront = true; |
@@ -409,24 +443,30 @@ namespace Bu | |||
409 | friend class List<value, cmpfunc, valuealloc, linkalloc>; | 443 | friend class List<value, cmpfunc, valuealloc, linkalloc>; |
410 | private: | 444 | private: |
411 | Link *pLink; | 445 | Link *pLink; |
412 | const MyType &rList; | 446 | const MyType *pList; |
413 | bool bOffFront; | 447 | bool bOffFront; |
414 | const_iterator( const MyType &rList ) : | 448 | const_iterator( const MyType *pList ) : |
415 | pLink( NULL ), | 449 | pLink( NULL ), |
416 | rList( rList ) | 450 | pList( pList ) |
417 | { | 451 | { |
418 | } | 452 | } |
419 | 453 | ||
420 | const_iterator( Link *pLink, const MyType &rList ) : | 454 | const_iterator( Link *pLink, const MyType *pList ) : |
421 | pLink( pLink ), | 455 | pLink( pLink ), |
422 | rList( rList ) | 456 | pList( pList ) |
423 | { | 457 | { |
424 | } | 458 | } |
425 | 459 | ||
426 | public: | 460 | public: |
461 | const_iterator() : | ||
462 | pLink( NULL ), | ||
463 | pList( NULL ) | ||
464 | { | ||
465 | } | ||
466 | |||
427 | const_iterator( const iterator &i ) : | 467 | const_iterator( const iterator &i ) : |
428 | pLink( i.pLink ), | 468 | pLink( i.pLink ), |
429 | rList( i.rList ) | 469 | pList( i.pList ) |
430 | { | 470 | { |
431 | } | 471 | } |
432 | 472 | ||
@@ -463,7 +503,7 @@ namespace Bu | |||
463 | const_iterator &operator++() | 503 | const_iterator &operator++() |
464 | { | 504 | { |
465 | if( pLink == NULL ) | 505 | if( pLink == NULL ) |
466 | pLink = (bOffFront)?(rList.pFirst):(NULL); | 506 | pLink = (bOffFront)?(pList->pFirst):(NULL); |
467 | else | 507 | else |
468 | pLink = pLink->pNext; | 508 | pLink = pLink->pNext; |
469 | bOffFront = false; | 509 | bOffFront = false; |
@@ -473,7 +513,7 @@ namespace Bu | |||
473 | const_iterator &operator--() | 513 | const_iterator &operator--() |
474 | { | 514 | { |
475 | if( pLink == NULL ) | 515 | if( pLink == NULL ) |
476 | pLink = (bOffFront)?(NULL):(rList.pLast); | 516 | pLink = (bOffFront)?(NULL):(pList->pLast); |
477 | else | 517 | else |
478 | pLink = pLink->pPrev; | 518 | pLink = pLink->pPrev; |
479 | bOffFront = true; | 519 | bOffFront = true; |
@@ -483,7 +523,7 @@ namespace Bu | |||
483 | const_iterator &operator++( int ) | 523 | const_iterator &operator++( int ) |
484 | { | 524 | { |
485 | if( pLink == NULL ) | 525 | if( pLink == NULL ) |
486 | pLink = (bOffFront)?(rList.pFirst):(NULL); | 526 | pLink = (bOffFront)?(pList->pFirst):(NULL); |
487 | else | 527 | else |
488 | pLink = pLink->pNext; | 528 | pLink = pLink->pNext; |
489 | bOffFront = false; | 529 | bOffFront = false; |
@@ -493,7 +533,7 @@ namespace Bu | |||
493 | const_iterator &operator--( int ) | 533 | const_iterator &operator--( int ) |
494 | { | 534 | { |
495 | if( pLink == NULL ) | 535 | if( pLink == NULL ) |
496 | pLink = (bOffFront)?(NULL):(rList.pLast); | 536 | pLink = (bOffFront)?(NULL):(pList->pLast); |
497 | else | 537 | else |
498 | pLink = pLink->pPrev; | 538 | pLink = pLink->pPrev; |
499 | bOffFront = true; | 539 | bOffFront = true; |
@@ -529,7 +569,7 @@ namespace Bu | |||
529 | */ | 569 | */ |
530 | iterator begin() | 570 | iterator begin() |
531 | { | 571 | { |
532 | return iterator( pFirst, *this ); | 572 | return iterator( pFirst, this ); |
533 | } | 573 | } |
534 | 574 | ||
535 | /** | 575 | /** |
@@ -538,7 +578,7 @@ namespace Bu | |||
538 | */ | 578 | */ |
539 | const_iterator begin() const | 579 | const_iterator begin() const |
540 | { | 580 | { |
541 | return const_iterator( pFirst, *this ); | 581 | return const_iterator( pFirst, this ); |
542 | } | 582 | } |
543 | 583 | ||
544 | /** | 584 | /** |
@@ -548,7 +588,7 @@ namespace Bu | |||
548 | */ | 588 | */ |
549 | const iterator end() | 589 | const iterator end() |
550 | { | 590 | { |
551 | return iterator( NULL, *this ); | 591 | return iterator( NULL, this ); |
552 | } | 592 | } |
553 | 593 | ||
554 | /** | 594 | /** |
@@ -558,7 +598,7 @@ namespace Bu | |||
558 | */ | 598 | */ |
559 | const const_iterator end() const | 599 | const const_iterator end() const |
560 | { | 600 | { |
561 | return const_iterator( NULL, *this ); | 601 | return const_iterator( NULL, this ); |
562 | } | 602 | } |
563 | 603 | ||
564 | /** | 604 | /** |