00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file Intrusive_List.h 00006 * 00007 * $Id: Intrusive_List.h 77330 2007-02-22 13:45:54Z coryan $ 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 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00024 00025 /** 00026 * @class ACE_Intrusive_List 00027 * 00028 * @brief Implement an intrusive double linked list 00029 * 00030 * Intrusive lists assume that the elements they contain the pointers 00031 * required to build the list. They are useful as light-weight 00032 * containers and free-lists. 00033 * 00034 * The template argument T must implement the following methods: 00035 * 00036 * - T* T::next () const; 00037 * - void T::next (T *); 00038 * - T* T::prev () const; 00039 * - void T::prev (T* ); 00040 * 00041 * A simple way to satisfy the Intrusive_List requirements would be to 00042 * implement a helper class: 00043 * 00044 * class My_Object : public ACE_Intrusive_List_Node<My_Object> {<BR> 00045 * ....<BR> 00046 * };<BR> 00047 * 00048 * typedef ACE_Intrusive_List<My_Object> My_Object_List; 00049 * 00050 * However, ACE is supported on platforms that would surely get 00051 * confused using such templates. 00052 * 00053 * @todo The ACE_Message_Queue is an example of an intrusive list (or 00054 * queue) but it is not implemented in terms of this class. 00055 * 00056 */ 00057 template <class T> 00058 class ACE_Intrusive_List 00059 { 00060 public: 00061 // = Initialization and termination methods. 00062 /// Constructor. Use user specified allocation strategy 00063 /// if specified. 00064 ACE_Intrusive_List (void); 00065 00066 /// Destructor. 00067 ~ACE_Intrusive_List (void); 00068 00069 // = Check boundary conditions. 00070 00071 /// Returns 1 if the container is empty, otherwise returns 0. 00072 int is_empty (void) const; 00073 00074 /// Returns 1 if the container is empty, otherwise returns 0. 00075 /// @deprecated Use is_empty() instead. 00076 int empty (void) const; 00077 00078 /// Insert an element at the beginning of the list 00079 void push_front (T *node); 00080 00081 /// Insert an element at the end of the list 00082 void push_back (T *node); 00083 00084 /// Remove the element at the beginning of the list 00085 T *pop_front (void); 00086 00087 /// Remove the element at the end of the list 00088 T *pop_back (void); 00089 00090 /// Get the element at the head of the queue 00091 T *head (void) const; 00092 00093 /// Get the element at the tail of the queue 00094 T *tail (void) const; 00095 00096 /// Remove a element from the list 00097 /** 00098 * Verify that the element is still in the list before removing it. 00099 */ 00100 void remove (T *node); 00101 00102 /// Swap two lists 00103 void swap(ACE_Intrusive_List<T> & rhs); 00104 00105 /// Remove a element from the list without checking 00106 /** 00107 * No attempts are performed to check if T* really belongs to the 00108 * list. The effects of removing an invalid element are unspecified 00109 */ 00110 void unsafe_remove (T *node); 00111 00112 private: 00113 /** @name Disallow copying 00114 * 00115 */ 00116 //@{ 00117 ACE_Intrusive_List (const ACE_Intrusive_List<T> &); 00118 ACE_Intrusive_List<T>& operator= (const ACE_Intrusive_List<T> &); 00119 //@} 00120 00121 private: 00122 /// Head of the list 00123 T *head_; 00124 00125 /// Tail of the list 00126 T *tail_; 00127 }; 00128 00129 ACE_END_VERSIONED_NAMESPACE_DECL 00130 00131 #if defined (__ACE_INLINE__) 00132 #include "ace/Intrusive_List.inl" 00133 #endif /* __ACE_INLINE__ */ 00134 00135 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00136 #include "ace/Intrusive_List.cpp" 00137 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00138 00139 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00140 #pragma implementation ("Intrusive_List.cpp") 00141 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00142 00143 #include /**/ "ace/post.h" 00144 #endif /* ACE_INTRUSIVE_LIST_H */