sipxmedialib  Version 3.3
TLinkedList.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _TLinkedList_h
13 #define _TLinkedList_h
14 
15 #include "rtcp/RtcpConfig.h"
16 #include "os/OsTask.h"
17 
18 // Includes
19 #include "BaseClass.h"
20 #include "TLink.h"
21 
22 
23 /*|><|************************************************************************
24 *
25 * Class Name: CTLinkedList
26 *
27 * Inheritance:
28 *
29 * Methods:
30 *
31 * Attributes:
32 *
33 * Description: CTLinkedList is a general purpose class template used to manage
34 * doubly link lists of entries. This linked list class shall
35 * implement a customized allocator which shall retrieve memory
36 * for a fixed number of items and shall reuse this memory through
37 * maintaining a free list. The services provided shall allow
38 * links to be added, removed, and released.
39 *
40 *
41 *
42 ************************************************************************|<>|*/
43 template <class TENTRY>
45 {
46 
47  public: // Public Member Functions
48 
49 
50 /*|><|************************************************************************
51 *
52 * Method Name: CTLinkedList - Constructor
53 *
54 *
55 * Inputs: None
56 *
57 * Outputs: None
58 *
59 * Returns: None
60 *
61 * Description: The constructor shall handle any initialization which is
62 * not subject to failure.
63 *
64 * Usage Notes:
65 *
66 *
67 ************************************************************************|<>|*/
68  CTLinkedList(void);
69 
70 
71 /*|><|************************************************************************
72 *
73 * Method Name: CTLinkedList - Destructor
74 *
75 *
76 * Inputs: None
77 *
78 * Outputs: None
79 *
80 * Returns: None
81 *
82 * Description: The linked list destructor shall remove all entries from
83 * the linked list returning the associated memory to
84 * memory pool.
85 *
86 * Usage Notes:
87 *
88 *
89 ************************************************************************|<>|*/
90  virtual ~CTLinkedList(void);
91 
92 
93 
94 /*|><|************************************************************************
95 *
96 * Method Name: GetCount
97 *
98 *
99 * Inputs: None
100 *
101 * Outputs: None
102 *
103 * Returns: unsigned long
104 *
105 * Description: Returns the number of entries currently on the list.
106 *
107 * Usage Notes:
108 *
109 *
110 ************************************************************************|<>|*/
111  virtual unsigned long GetCount(void);
112 
113 /*|><|************************************************************************
114 *
115 * Method Name: TakeLock
116 *
117 *
118 * Inputs: None
119 *
120 * Outputs: None
121 *
122 * Returns: None
123 *
124 * Description: Take the list's synchronization lock.
125 *
126 * Usage Notes: Call TakeLock before calling GetFirstEntry or RemoveFirstEntry
127 * AND KEEP THAT LOCK until done with GetNextEntry or
128 * RemoveNextEntry.
129 *
130 ************************************************************************|<>|*/
131  virtual void TakeLock(void);
132 
133 
134 /*|><|************************************************************************
135 *
136 * Method Name: ReleaseLock
137 *
138 *
139 * Inputs: None
140 *
141 * Outputs: None
142 *
143 * Returns: None
144 *
145 * Description: Release the list's synchronization lock.
146 *
147 * Usage Notes: Call TakeLock before calling GetFirstEntry or RemoveFirstEntry
148 * AND KEEP THAT LOCK until done with GetNextEntry or
149 * RemoveNextEntry.
150 *
151 ************************************************************************|<>|*/
152  virtual void ReleaseLock(void);
153 
154 
155 /*|><|************************************************************************
156 *
157 * Method Name: AddEntry
158 *
159 *
160 * Inputs: TENTRY tEntry
161 *
162 * Outputs: None
163 *
164 * Returns: bool
165 *
166 * Description: Add an entry to the linked list. The type of entry is
167 * generated at compile time in response to the template
168 * type provided.
169 *
170 * Usage Notes:
171 *
172 *
173 ************************************************************************|<>|*/
174  virtual bool AddEntry(TENTRY tEntry);
175 
176 
177 /*|><|************************************************************************
178 *
179 * Method Name: GetFirstEntry
180 *
181 *
182 * Inputs: None
183 *
184 * Outputs: None
185 *
186 * Returns: TENTRY
187 *
188 * Description: Returns the first entry on the FIFO linked list. A NULL entry
189 * shall be returned if their are no entries on the list. Entries
190 * are not removed from the linked list as the result of this call.
191 *
192 * Usage Notes: GetFirstEntry() and GetNextEntry() provide the user with the
193 * ability to iterate through a linked list. GetFirstEntry()
194 * shall always reset the iterator to the head of the list while
195 * successive calls to GetNextEntry() will cause the iterator to
196 * move down the list.
197 *
198 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
199 * SHARE A SINGLE ITERATOR!
200 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
201 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
202 *
203 ************************************************************************|<>|*/
204  virtual TENTRY GetFirstEntry(void);
205 
206 /*|><|************************************************************************
207 *
208 * Method Name: GetNextEntry
209 *
210 *
211 * Inputs: None
212 *
213 * Outputs: None
214 *
215 * Returns: TENTRY
216 *
217 * Description: Returns the next entry on the FIFO linked list. A NULL entry
218 * shall be returned if the end of the list has been encountered.
219 * Entries are not removed from the linked list as the result of
220 * this call.
221 *
222 * Usage Notes: GetFirstEntry() and GetNextEntry() provide the user with the
223 * ability to iterate through a linked list. GetFirstEntry()
224 * shall always reset the iterator to the head of the list while
225 * successive calls to GetNextEntry() will cause the iterator to
226 * move down the list.
227 *
228 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
229 * SHARE A SINGLE ITERATOR!
230 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
231 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
232 *
233 ************************************************************************|<>|*/
234  virtual TENTRY GetNextEntry(void);
235 
236 /*|><|************************************************************************
237 *
238 * Method Name: RemoveFirstEntry
239 *
240 *
241 * Inputs: None
242 *
243 * Outputs: None
244 *
245 * Returns: TENTRY
246 *
247 * Description: Removes the first entry on the FIFO linked list. A NULL entry
248 * shall be returned if their are no entries on the list.
249 *
250 * Usage Notes: RemoveFirstEntry() and RemoveNextEntry() provide the user with
251 * the ability to iterate through a linked list.
252 * RemoveFirstEntry() shall always reset the iterator to the head
253 * of the list while successive calls to RemoveNextEntry() will
254 * cause the iterator to move down the list.
255 *
256 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
257 * SHARE A SINGLE ITERATOR!
258 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
259 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
260 *
261 ************************************************************************|<>|*/
262  virtual TENTRY RemoveFirstEntry(void);
263 
264 /*|><|************************************************************************
265 *
266 * Method Name: RemoveNextEntry
267 *
268 *
269 * Inputs: None
270 *
271 * Outputs: None
272 *
273 * Returns: TENTRY
274 *
275 * Description: Removes the next entry on the FIFO linked list. A NULL entry
276 * shall be returned if the end of the list has been encountered.
277 *
278 * Usage Notes: RemoveFirstEntry() and RemoveNextEntry() provide the user with
279 * the ability to iterate through a linked list.
280 * RemoveFirstEntry() shall always reset the iterator to the head
281 * of the list while successive calls to RemoveNextEntry() will
282 * cause the iterator to move down the list.
283 *
284 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
285 * SHARE A SINGLE ITERATOR!
286 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
287 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
288 *
289 ************************************************************************|<>|*/
290  virtual TENTRY RemoveNextEntry(void);
291 
292 
293 /*|><|************************************************************************
294 *
295 * Method Name: GetEntry
296 *
297 *
298 * Inputs: TENTRY tEntry
299 *
300 * Outputs: None
301 *
302 * Returns: TENTRY
303 *
304 * Description: Find an entry on the linked list matching the address passed.
305 * If the entry is found, the address of the entry shall be
306 * returned; otherwise, a NULL entry shall be returned.
307 *
308 * Usage Notes:
309 *
310 *
311 ************************************************************************|<>|*/
312  virtual TENTRY GetEntry(TENTRY tEntry);
313 
314 /*|><|************************************************************************
315 *
316 * Method Name: GetEntry
317 *
318 *
319 * Inputs: bool (*Comparitor)(TENTRY, void *),
320 * void *
321 *
322 * Outputs: None
323 *
324 * Returns: TENTRY
325 *
326 * Description: Get an entry on the linked list with a primary lookup key
327 * matching that passed. If the entry is found, the address of
328 * the entry shall be returned; otherwise, a NULL entry shall
329 * be returned.
330 *
331 * Usage Notes:
332 *
333 *
334 ************************************************************************|<>|*/
335  virtual TENTRY GetEntry(bool (*Comparitor)(TENTRY, void *),void *);
336 
337 /*|><|************************************************************************
338 *
339 * Method Name: RemoveEntry
340 *
341 *
342 * Inputs: TENTRY tEntry
343 *
344 * Outputs: None
345 *
346 * Returns: TENTRY tEntry
347 *
348 * Description: Remove an entry from the linked list matching the address
349 * passed. If the entry is found, the address of the entry
350 * shall be returned; otherwise, a NULL entry shall be returned.
351 *
352 * Usage Notes: The memory associated with the removed Entry shall not be
353 * deallocated as a result of this call.
354 *
355 *
356 ************************************************************************|<>|*/
357  virtual TENTRY RemoveEntry(TENTRY tEntry);
358 
359 
360 /*|><|************************************************************************
361 *
362 * Method Name: RemoveEntry
363 *
364 *
365 * Inputs: bool (*Comparitor)(TENTRY, void *),void *
366 *
367 * Outputs: None
368 *
369 * Returns: TENTRY tEntry
370 *
371 * Description: Remove an entry from the linked list with a primary lookup key
372 * matching that passed. If the entry is found, the address of
373 * the entry shall be returned; otherwise, a NULL entry shall be
374 * returned.
375 *
376 * Usage Notes: The memory associated with the removed Entry shall not be
377 * deallocated as a result of this call.
378 *
379 *
380 ************************************************************************|<>|*/
381  virtual TENTRY RemoveEntry(bool (*Comparitor)(TENTRY, void *),void *);
382 
383 #if 0
384 /*|><|************************************************************************
385 *
386 * Method Name: RemoveAllEntries
387 *
388 *
389 * Inputs: TENTRY tEntry
390 *
391 * Outputs: None
392 *
393 * Returns: void
394 *
395 * Description: Remove all entries from a linked list matching the address
396 * passed.
397 *
398 * Usage Notes: The memory associated with the removed Entry shall not be
399 * deallocated as a result of this call.
400 *
401 *
402 ************************************************************************|<>|*/
403  virtual void RemoveAllEntries();
404 #endif
405 
406 
407 /*|><|************************************************************************
408 *
409 * Method Name: RemoveAllEntries
410 *
411 *
412 * Inputs: bool (*Comparitor)(TENTRY, void *),void *
413 *
414 * Outputs: None
415 *
416 * Returns: void
417 *
418 * Description: Remove all entries from the linked list with a primary lookup
419 * key matching that passed. If the entry is found, the address
420 * of the entry shall be returned; otherwise, a NULL entry shall
421 * be returned.
422 *
423 * Usage Notes: The memory associated with the removed Entry shall not be
424 * deallocated as a result of this call.
425 *
426 *
427 ************************************************************************|<>|*/
428  virtual void RemoveAllEntries(bool (*Comparitor)(TENTRY, void *),void *);
429 
430 
431  private: // Private Member Functions
432 
433 /*|><|************************************************************************
434 *
435 * Method Name: AddLink
436 *
437 *
438 * Inputs: CTLink<TENTRY> *ptLink
439 *
440 * Outputs: None
441 *
442 * Returns: None
443 *
444 * Description: Add a link to the linked list adjusting the forward and back
445 * pointers of adjoining link as well as those of the head, tail,
446 * and iterator.
447 *
448 * Usage Notes:
449 *
450 *
451 *
452 ************************************************************************|<>|*/
453  void AddLink(CTLink<TENTRY> *ptLink);
454 
455 /*|><|************************************************************************
456 *
457 * Method Name: RemoveLink
458 *
459 *
460 * Inputs: CTLink<TENTRY> *ptLink
461 *
462 * Outputs: None
463 *
464 * Returns: TENTRY tEntry
465 *
466 * Description: Remove a link from the linked list adjusting the forward and
467 * back pointers of adjoining link as well as those of the head,
468 * tail, and iterator.
469 *
470 * Usage Notes: The memory associated with the removed link shall be
471 * deallocated. The entry contained within the deallocated link
472 * shall remain intact with its pointer returned to the caller.
473 *
474 *
475 *
476 ************************************************************************|<>|*/
477  TENTRY RemoveLink(CTLink<TENTRY> *ptLink);
478 
479 /*|><|************************************************************************
480 *
481 * Method Name: ResetIterator
482 *
483 *
484 * Inputs: None
485 *
486 * Outputs: None
487 *
488 * Returns: CTLink<TENTRY> *
489 *
490 * Description: A private member which resets the internal iterator to the
491 * first position within the FIFO
492 *
493 * Usage Notes:
494 *
495 ************************************************************************|<>|*/
497 
498 
499 /*|><|************************************************************************
500 *
501 * Method Name: AdvanceIterator
502 *
503 *
504 * Inputs: None
505 *
506 * Outputs: None
507 *
508 * Returns: CTLink<TENTRY> *
509 *
510 * Description: A private member which advances the internal iterator to the
511 * next position within the FIFO
512 *
513 * Usage Notes:
514 *
515 ************************************************************************|<>|*/
517 
518 
519 
520  private: // Private Data Members
521 
522 /*|><|************************************************************************
523 *
524 * Attribute Name: m_dwCount
525 *
526 * Type: unsigned long
527 *
528 * Description: A count of the number of entries currently on the list.
529 *
530 ************************************************************************|<>|*/
531  unsigned long m_dwCount;
532 
533 /*|><|************************************************************************
534 *
535 * Attribute Name: m_ptHead
536 *
537 * Type: CTLink<TENTRY> *
538 *
539 * Description: This is a pointer to the head of the list. The head shall
540 * be set to NULL when the list is empty or shall point to the
541 * first entry on the list.
542 *
543 ************************************************************************|<>|*/
545 
546 /*|><|************************************************************************
547 *
548 * Attribute Name: m_ptTail
549 *
550 * Type: CTLink<TENTRY> *
551 *
552 * Description: This is a pointer to the tail of the list. The tail shall
553 * be set to NULL when the list is empty or shall point to
554 * the last entry on the list.
555 *
556 ************************************************************************|<>|*/
558 
559 
560 /*|><|************************************************************************
561 *
562 * Attribute Name: m_ptIterator
563 *
564 * Type: CTLink<TENTRY> *
565 *
566 * Description: This is a pointer to the iterator of the list. The iterator
567 * shall be set to NULL when the list is empty. It shall
568 * point to the head of the list at list creation or following
569 * a call to GetFirstEntry(). It shall be advanced to the
570 * next entry within the list upon each call to GetNextEntry.
571 *
572 ************************************************************************|<>|*/
574 
575 /*|><|************************************************************************
576 *
577 * Attribute Name: m_csSynchronized
578 *
579 * Type: CRITICAL_SECTION
580 *
581 * Description: This is a critical section used to synchronize thread
582 * access to this class. This shall prevent several
583 * contending threads from executing interleaving linked
584 * list operations.
585 *
586 ************************************************************************|<>|*/
587  CRITICAL_SECTION m_csSynchronized;
588 };
589 
590 
591 
592 /*|><|************************************************************************
593 *
594 * Method Name: CTLinkedList - Constructor
595 *
596 *
597 * Inputs: None
598 *
599 * Outputs: None
600 *
601 * Returns: None
602 *
603 * Logic Notes:
604 *
605 * Caveats:
606 *
607 ************************************************************************|<>|*/
608 template <class TENTRY>
610  : m_dwCount(0), m_ptHead(NULL), m_ptTail(NULL), m_ptIterator(NULL)
611 #ifndef WIN32
612  , m_csSynchronized(NULL)
613 #endif
614 {
615 
616 // Initialize Critical Section
618 
619 }
620 
621 
622 /*|><|************************************************************************
623 *
624 * Method Name: CTLinkedList - Destructor
625 *
626 *
627 * Inputs: None
628 *
629 * Outputs: None
630 *
631 * Returns: None
632 *
633 * Logic Notes: Traverses a doubly linked list from the bottom up deleting
634 * all list elements which remain at the time of destruction.
635 *
636 * Caveats:
637 *
638 *
639 ************************************************************************|<>|*/
640 template <class TENTRY>
642 {
643 
644 // Declarations
645  CTLink<TENTRY> *ptLink;
646  TENTRY tEntry;
647 
648 // Enter Synchronized Area
650 
651 // Reset List Pointer
652  ptLink = ResetIterator();
653 
654 // While Links remain
655  while (ptLink)
656  {
657 // Delete Link
658  tEntry = ptLink->GetEntry();
659  delete ptLink;
660 
661 // Advance to next link
662  ptLink = AdvanceIterator();
663  }
664 
665 // Leave Synchronized Area
667 
668 // Delete the Critical Section
670 
671 }
672 
673 
674 /*|><|************************************************************************
675 *
676 * Method Name: GetCount
677 *
678 *
679 * Inputs: None
680 *
681 * Outputs: None
682 *
683 * Returns: unsigned long
684 *
685 * Logic Notes:
686 *
687 * Caveats:
688 *
689 ************************************************************************|<>|*/
690 template <class TENTRY>
692 {
693 
694  return(m_dwCount);
695 
696 }
697 
698 /*|><|************************************************************************
699 *
700 * Method Name: TakeLock
701 *
702 *
703 * Inputs: None
704 *
705 * Outputs: None
706 *
707 * Returns: None
708 *
709 * Description: Take the list's synchronization lock.
710 *
711 * Usage Notes:
712 *
713 *
714 ************************************************************************|<>|*/
715 template <class TENTRY>
717 {
719 }
720 
721 
722 /*|><|************************************************************************
723 *
724 * Method Name: ReleaseLock
725 *
726 *
727 * Inputs: None
728 *
729 * Outputs: None
730 *
731 * Returns: None
732 *
733 * Description: Release the list's synchronization lock.
734 *
735 * Usage Notes:
736 *
737 *
738 ************************************************************************|<>|*/
739 template <class TENTRY>
741 {
743 }
744 
745 
746 /*|><|************************************************************************
747 *
748 * Method Name: AddEntry
749 *
750 *
751 * Inputs: TENTRY tEntry
752 *
753 * Outputs: None
754 *
755 * Returns: bool
756 *
757 * Logic Notes:
758 *
759 * Caveats:
760 *
761 ************************************************************************|<>|*/
762 template <class TENTRY>
764 {
765 
766 // Declarations
767  CTLink<TENTRY> *ptLink;
768 
769 // Enter Synchronized Area
771 
772 // Create new Link object. If a failure occurs, return FALSE
773  if(!(ptLink = new CTLink<TENTRY>(tEntry)))
774  {
775 // Leave Synchronized Area
777 
778  return(FALSE);
779  }
780 
781  AddLink(ptLink);
782 
783 // Leave Synchronized Area
785 
786  return(TRUE);
787 
788 
789 }
790 
791 
792 /*|><|************************************************************************
793 *
794 * Method Name: GetFirstEntry
795 *
796 *
797 * Inputs: None
798 *
799 * Outputs: None
800 *
801 * Returns: TENTRY
802 *
803 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
804 * SHARE A SINGLE ITERATOR!
805 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
806 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
807 *
808 ************************************************************************|<>|*/
809 template <class TENTRY>
811 {
812 
813 // Declarations
814  CTLink<TENTRY> *ptLink;
815  TENTRY retVal = NULL;
816 
817 // Reset the list iterator to the tail where the first entry in resides.
818  ptLink = ResetIterator();
819 
820 // If the Iterator is equal to NULL, then the list is empty
821  if(ptLink) {
822  retVal = ptLink->GetEntry();
823  }
824 
825 // Return entry
826  return retVal;
827 }
828 
829 /*|><|************************************************************************
830 *
831 * Method Name: GetNextEntry
832 *
833 *
834 * Inputs: None
835 *
836 * Outputs: None
837 *
838 * Returns: TENTRY
839 *
840 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
841 * SHARE A SINGLE ITERATOR!
842 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
843 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
844 *
845 ************************************************************************|<>|*/
846 template <class TENTRY>
848 {
849 
850 // Declarations
851  CTLink<TENTRY> *ptLink;
852  TENTRY retVal = NULL;
853 
854 // Advance List Iterator
855  ptLink = AdvanceIterator();
856 
857 // If the Iterator is equal to NULL, then the list is empty or the iterator
858 // has reached the end of the list
859  if(ptLink) {
860  retVal = (ptLink->GetEntry());
861  }
862 
863  return retVal;
864 }
865 
866 /*|><|************************************************************************
867 *
868 * Method Name: RemoveFirstEntry
869 *
870 *
871 * Inputs: None
872 *
873 * Outputs: None
874 *
875 * Returns: TENTRY
876 *
877 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
878 * SHARE A SINGLE ITERATOR!
879 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
880 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
881 *
882 ************************************************************************|<>|*/
883 template <class TENTRY>
885 {
886 
887 // Declarations
888  CTLink<TENTRY> *ptLink;
889  TENTRY retVal = NULL;
890 
891 // Reset the list iterator to the tail where the first entry in resides.
892  ptLink = ResetIterator();
893 
894 // If the Iterator is equal to NULL, then the list is empty
895  if(!ptLink)
896  {
897  // Remove entry
898  retVal = RemoveLink(ptLink);
899  }
900  return retVal;
901 }
902 
903 /*|><|************************************************************************
904 *
905 * Method Name: RemoveNextEntry
906 *
907 *
908 * Inputs: None
909 *
910 * Outputs: None
911 *
912 * Returns: TENTRY
913 *
914 * Caveats: GetFirstEntry, GetNextEntry, RemoveFirstEntry, and RemoveNextEntry
915 * SHARE A SINGLE ITERATOR!
916 * THE NEW USAGE PARADIGM IS: Call TakeLock before calling xxxFirstEntry, and
917 * KEEP THAT LOCK until you are done with xxxNextEntry, then call ReleaseLock.
918 *
919 ************************************************************************|<>|*/
920 template <class TENTRY>
922 {
923 
924 // Declarations
925  CTLink<TENTRY> *ptLink;
926  TENTRY retVal = NULL;
927 
928 // Advance List Iterator
929  ptLink = AdvanceIterator();
930 
931 // If the Iterator is equal to NULL, then the list is empty or the iterator
932 // has reached the end of the list
933  if(ptLink)
934  {
935  // Remove entry
936  retVal = RemoveLink(ptLink);
937  }
938 
939  return retVal;
940 }
941 
942 
943 /*|><|************************************************************************
944 *
945 * Method Name: GetEntry
946 *
947 *
948 * Inputs: TENTRY tEntry
949 *
950 * Outputs: None
951 *
952 * Returns: TENTRY
953 *
954 * Logic Notes:
955 *
956 * Caveats:
957 *
958 ************************************************************************|<>|*/
959 template <class TENTRY>
960 TENTRY CTLinkedList<TENTRY>::GetEntry(TENTRY tEntry)
961 {
962 // Enter Synchronized Area
964 
965 // Initialize link pointer
966  CTLink<TENTRY> *ptLink = m_ptTail;
967 
968 // Iterate through the list looking for the matching entry
969  while(ptLink)
970  {
971 // Check for matching entry address
972  if(tEntry == ptLink->GetEntry())
973  {
974 // Leave Synchronized Area
976 
977  return(tEntry);
978  }
979 
980 // Advance the pointer and try again
981  ptLink = ptLink->GetPrevious();
982  }
983 
984 // Leave Synchronized Area
986 
987  return(NULL);
988 
989 }
990 
991 /*|><|************************************************************************
992 *
993 * Method Name: GetEntry
994 *
995 *
996 * Inputs: bool (*Comparitor)(TENTRY, void *),void *
997 *
998 * Outputs: None
999 *
1000 * Returns: TENTRY
1001 *
1002 * Logic Notes:
1003 *
1004 * Caveats:
1005 *
1006 ************************************************************************|<>|*/
1007 template <class TENTRY>
1009  bool (*Comparitor)(TENTRY, void *),void *pvLookupKey)
1010 {
1011 // Enter Synchronized Area
1013 
1014 // Initialize link pointer
1015  CTLink<TENTRY> *ptLink = m_ptTail;
1016  TENTRY tEntry;
1017 
1018 // Iterate through the list looking for the matching entry
1019  while(ptLink)
1020  {
1021 // Get entry from link
1022  tEntry = ptLink->GetEntry();
1023 
1024 // Check for matching entry address
1025  if((*Comparitor)(tEntry, pvLookupKey))
1026  {
1027 // Leave Synchronized Area
1029 
1030  return(tEntry);
1031  }
1032 
1033 // Advance the pointer and try again
1034  ptLink = ptLink->GetPrevious();
1035  }
1036 
1037 // Leave Synchronized Area
1039 
1040  return(NULL);
1041 
1042 }
1043 
1044 /*|><|************************************************************************
1045 *
1046 * Method Name: RemoveEntry
1047 *
1048 *
1049 * Inputs: TENTRY tEntry
1050 *
1051 * Outputs: None
1052 *
1053 * Returns: bool
1054 *
1055 * Logic Notes:
1056 *
1057 * Caveats:
1058 *
1059 ************************************************************************|<>|*/
1060 template <class TENTRY>
1062 {
1063 // Enter Synchronized Area
1065 
1066 // Initialize link pointer
1067  CTLink<TENTRY> *ptLink = m_ptTail;
1068 
1069 // Iterate through the list looking for the matching entry
1070  while(ptLink)
1071  {
1072 // Check for matching entry address
1073  if(tEntry == ptLink->GetEntry())
1074  {
1075  tEntry = RemoveLink(ptLink);
1076 
1077 // Leave Synchronized Area
1079 
1080  return(tEntry);
1081  }
1082 
1083 
1084 // Advance the pointer and try again
1085  ptLink = ptLink->GetPrevious();
1086  }
1087 
1088 // Leave Synchronized Area
1090 
1091  return(NULL);
1092 
1093 }
1094 
1095 
1096 /*|><|************************************************************************
1097 *
1098 * Method Name: RemoveEntry
1099 *
1100 *
1101 * Inputs: bool (*Comparitor)(TENTRY, void *),
1102 * void *pvLookupKey
1103 *
1104 * Outputs: None
1105 *
1106 * Returns: TENTRY
1107 *
1108 * Logic Notes:
1109 *
1110 * Caveats:
1111 *
1112 ************************************************************************|<>|*/
1113 template <class TENTRY>
1115  bool (*Comparitor)(TENTRY, void *),void *pvLookupKey)
1116 {
1117 // Enter Synchronized Area
1119 
1120 // Initialize link pointer
1121  CTLink<TENTRY> *ptLink = m_ptTail;
1122  TENTRY tEntry;
1123 
1124 // Iterate through the list looking for the matching entry
1125  while(ptLink)
1126  {
1127 // Get entry from link
1128  tEntry = ptLink->GetEntry();
1129 
1130 // Check for matching entry address
1131  if((*Comparitor)(tEntry, pvLookupKey))
1132  {
1133  tEntry = RemoveLink(ptLink);
1134 
1135 // Leave Synchronized Area
1137 
1138  return(tEntry);
1139  }
1140 
1141 // Advance the pointer and try again
1142  ptLink = ptLink->GetPrevious();
1143  }
1144 
1145 // Leave Synchronized Area
1147 
1148  return(NULL);
1149 
1150 }
1151 
1152 /*|><|************************************************************************
1153 *
1154 * Method Name: RemoveAllEntries
1155 *
1156 *
1157 * Inputs: bool (*Comparitor)(TENTRY, void *),
1158 * void *pvLookupKey
1159 *
1160 * Outputs: None
1161 *
1162 * Returns: TENTRY
1163 *
1164 * Logic Notes:
1165 *
1166 * Caveats:
1167 *
1168 ************************************************************************|<>|*/
1169 template <class TENTRY>
1171  bool (*Comparitor)(TENTRY, void *),void *pvLookupKey)
1172 {
1173 // Enter Synchronized Area
1175 
1176 // Initialize link pointer
1177  CTLink<TENTRY> *ptLink = m_ptTail;
1178  TENTRY tEntry;
1179 
1180 // Iterate through the list looking for the matching entry
1181  while(ptLink)
1182  {
1183 // Get entry from link
1184  tEntry = ptLink->GetEntry();
1185 
1186 // Check for matching entry address
1187  if((*Comparitor)(tEntry, pvLookupKey))
1188  {
1189  CTLink<TENTRY> *ptNextLink = ptLink->GetPrevious();
1190  RemoveLink(ptLink);
1191  ptLink = ptNextLink;
1192  continue;
1193  }
1194 
1195 // Advance the pointer and try again
1196  ptLink = ptLink->GetPrevious();
1197  }
1198 
1199 // Leave Synchronized Area
1201 
1202  return;
1203 
1204 }
1205 
1206 
1207 /*|><|************************************************************************
1208 *
1209 * Method Name: AddLink
1210 *
1211 *
1212 * Inputs: CTLink<TENTRY> *ptLink
1213 *
1214 * Outputs: None
1215 *
1216 * Returns: None
1217 *
1218 * Logic Notes:
1219 *
1220 * Caveats:
1221 *
1222 ************************************************************************|<>|*/
1223 template <class TENTRY>
1225 {
1226 
1227 // Add to the head of the Linked List
1228  ptLink->SetPrevious(NULL);
1229  ptLink->SetNext(m_ptHead);
1230 
1231 // If the head points to an entry, set that entry's back pointer
1232 // to the newly added entry
1233  if(m_ptHead)
1234  m_ptHead->SetPrevious(ptLink);
1235 
1236 // Assign the link to the head pointer
1237  m_ptHead = ptLink;
1238 
1239 // If the tail doesn't point to an entry, assign the tail with
1240 // the pointer of the new entry
1241  if(!m_ptTail)
1242  m_ptTail = ptLink;
1243 
1244 // Increment Count
1245  m_dwCount++;
1246 
1247 }
1248 
1249 /*|><|************************************************************************
1250 *
1251 * Method Name: RemoveLink
1252 *
1253 *
1254 * Inputs: CTLink<TENTRY> *ptLink
1255 *
1256 * Outputs: None
1257 *
1258 * Returns: TENTRY
1259 *
1260 * Logic Notes:
1261 *
1262 * Caveats:
1263 *
1264 ************************************************************************|<>|*/
1265 template <class TENTRY>
1267 {
1268 // Declarations
1269  TENTRY tEntry;
1270 
1271 // Check if the Link passed is valid
1272  if(!ptLink)
1273  return(NULL);
1274 
1275 // Check if the entry is assigned to the head. If so, adjust the head
1276  if(ptLink == m_ptHead)
1277  m_ptHead = ptLink->GetNext();
1278 
1279 // Check if the entry is assigned to the tail. If so, adjust the tail
1280  if(ptLink == m_ptTail)
1281  m_ptTail = ptLink->GetPrevious();
1282 
1283 // Check if the entry is assigned to the iterator. If so, adjust the iterator
1284  if(ptLink == m_ptIterator)
1285  m_ptIterator = ptLink->GetPrevious();
1286 
1287 // Decrement count
1288  m_dwCount--;
1289 
1290 // Get Entry
1291  tEntry = ptLink->GetEntry();
1292 
1293 // Delete Link
1294  delete ptLink;
1295 
1296  return(tEntry);
1297 
1298 }
1299 
1300 /*|><|************************************************************************
1301 *
1302 * Method Name: ResetIterator
1303 *
1304 *
1305 * Inputs: None
1306 *
1307 * Outputs: None
1308 *
1309 * Returns: CTLink<TENTRY> *
1310 *
1311 * Logic Notes:
1312 *
1313 * Caveats:
1314 *
1315 ************************************************************************|<>|*/
1316 template <class TENTRY>
1318 {
1319 
1320 // Reset Iterator
1322 
1323 // Advance iterator in anticipation of the next call while
1324 // returning the link currently pointed to.
1325  return(AdvanceIterator());
1326 
1327 }
1328 
1329 
1330 /*|><|************************************************************************
1331 *
1332 * Method Name: AdvanceIterator
1333 *
1334 *
1335 * Inputs: None
1336 *
1337 * Outputs: None
1338 *
1339 * Returns: CTLink<TENTRY> *
1340 *
1341 * Logic Notes:
1342 *
1343 * Caveats:
1344 *
1345 ************************************************************************|<>|*/
1346 template <class TENTRY>
1348 {
1349 
1350 // Declarations
1351  CTLink<TENTRY> *ptListPtr = m_ptIterator;
1352 
1353 // Check whether link is still valid. If so, assign the
1354 // adjacent link to be the new position of the iterator
1355  if(ptListPtr)
1356  m_ptIterator = ptListPtr->GetPrevious();
1357 
1358  return ptListPtr;
1359 
1360 }
1361 
1362 
1363 
1364 
1365 #endif
1366 
1367 
CRITICAL_SECTION m_csSynchronized
Definition: TLinkedList.h:587
CTLinkedList(void)
Definition: TLinkedList.h:609
virtual TENTRY RemoveEntry(TENTRY tEntry)
Definition: TLinkedList.h:1061
virtual void TakeLock(void)
Definition: TLinkedList.h:716
CTLink< TENTRY > * m_ptHead
Definition: TLinkedList.h:544
virtual bool AddEntry(TENTRY tEntry)
Definition: TLinkedList.h:763
virtual TENTRY GetNextEntry(void)
Definition: TLinkedList.h:847
virtual void RemoveAllEntries(bool(*Comparitor)(TENTRY, void *), void *)
Definition: TLinkedList.h:1170
virtual unsigned long GetCount(void)
Definition: TLinkedList.h:691
virtual TENTRY GetFirstEntry(void)
Definition: TLinkedList.h:810
void EnterCriticalSection(CRITICAL_SECTION *csSynchronized)
void DeleteCriticalSection(CRITICAL_SECTION *csSynchronized)
void LeaveCriticalSection(CRITICAL_SECTION *csSynchronized)
TENTRY RemoveLink(CTLink< TENTRY > *ptLink)
Definition: TLinkedList.h:1266
virtual TENTRY GetEntry(TENTRY tEntry)
Definition: TLinkedList.h:960
CTLink< TENTRY > * ResetIterator(void)
Definition: TLinkedList.h:1317
CTLink< TENTRY > * m_ptIterator
Definition: TLinkedList.h:573
CTLink< TENTRY > * AdvanceIterator(void)
Definition: TLinkedList.h:1347
virtual ~CTLinkedList(void)
Definition: TLinkedList.h:641
virtual TENTRY RemoveFirstEntry(void)
Definition: TLinkedList.h:884
void InitializeCriticalSection(CRITICAL_SECTION *csSynchronized)
unsigned long m_dwCount
Definition: TLinkedList.h:531
CTLink< TENTRY > * m_ptTail
Definition: TLinkedList.h:557
#define TRUE
Definition: PlgDefsV1.h:41
#define FALSE
Definition: PlgDefsV1.h:37
Definition: TLinkedList.h:44
void AddLink(CTLink< TENTRY > *ptLink)
Definition: TLinkedList.h:1224
virtual void ReleaseLock(void)
Definition: TLinkedList.h:740
virtual TENTRY RemoveNextEntry(void)
Definition: TLinkedList.h:921