00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file Intrusive_List.h 00006 * 00007 * $Id: Intrusive_List.h,v 1.1.1.2 2003/02/21 18:36:32 chad Exp $ 00008 * 00009 * @author Carlos O'Ryan <coryan@uci.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_INTRUSIVE_LIST_H 00014 #define ACE_INTRUSIVE_LIST_H 00015 #include "ace/pre.h" 00016 00017 #include "ace/config-all.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 /** 00024 * @class ACE_Intrusive_List 00025 * 00026 * @brief Implement an intrusive double linked list 00027 * 00028 * Intrusive lists assume that the elements they contain the pointers 00029 * required to build the list. They are useful as light-weight 00030 * containers and free-lists. 00031 * 00032 * The template argument T must implement the following methods: 00033 * 00034 * - T* T::next () const; 00035 * - void T::next (T *); 00036 * - T* T::prev () const; 00037 * - void T::prev (T* ); 00038 * 00039 * A simple way to satisfy the Intrusive_List requirements would be to 00040 * implement a helper class: 00041 * 00042 * class My_Object : public ACE_Intrusive_List_Node<My_Object> {<BR> 00043 * ....<BR> 00044 * };<BR> 00045 * 00046 * typedef ACE_Intrusive_List<My_Object> My_Object_List; 00047 * 00048 * However, ACE is supported on platforms that would surely get 00049 * confused using such templates. 00050 * 00051 * @todo The ACE_Message_Queue is an example of an intrusive list (or 00052 * queue) but it is not implemented in terms of this class. 00053 * 00054 */ 00055 template <class T> 00056 class ACE_Intrusive_List 00057 { 00058 public: 00059 // = Initialization and termination methods. 00060 /// Constructor. Use user specified allocation strategy 00061 /// if specified. 00062 ACE_Intrusive_List (void); 00063 00064 /// Destructor. 00065 ~ACE_Intrusive_List (void); 00066 00067 // = Check boundary conditions. 00068 00069 /// Returns 1 if the container is empty, otherwise returns 0. 00070 int empty (void) const; 00071 00072 /// Insert an element at the beginning of the list 00073 void push_front (T *node); 00074 00075 /// Insert an element at the end of the list 00076 void push_back (T *node); 00077 00078 /// Remove the element at the beginning of the list 00079 T *pop_front (void); 00080 00081 /// Remove the element at the end of the list 00082 T *pop_back (void); 00083 00084 /// Get the element at the head of the queue 00085 T *head (void) const; 00086 00087 /// Get the element at the tail of the queue 00088 T *tail (void) const; 00089 00090 /// Remove a element from the list 00091 /** 00092 * Verify that the element is still in the list before removing it. 00093 */ 00094 void remove (T *node); 00095 00096 private: 00097 /// Remove a element from the list 00098 /** 00099 * No attempts are performed to check if T* really belongs to the 00100 * list. The effects of removing an invalid element are unspecified 00101 */ 00102 void remove_i (T *node); 00103 00104 /** @name Disallow copying 00105 * 00106 */ 00107 //@{ 00108 ACE_Intrusive_List (const ACE_Intrusive_List<T> &); 00109 ACE_Intrusive_List<T>& operator= (const ACE_Intrusive_List<T> &); 00110 //@} 00111 00112 private: 00113 /// Head of the list 00114 T *head_; 00115 00116 /// Tail of the list 00117 T *tail_; 00118 }; 00119 00120 #if defined (__ACE_INLINE__) 00121 #include "ace/Intrusive_List.inl" 00122 #endif /* __ACE_INLINE__ */ 00123 00124 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00125 #include "ace/Intrusive_List.cpp" 00126 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00127 00128 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00129 #pragma implementation ("Intrusive_List.cpp") 00130 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00131 00132 #include "ace/post.h" 00133 #endif /* ACE_INTRUSIVE_LIST_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002