Intrusive_List.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file Intrusive_List.h
00006  *
00007  *  Intrusive_List.h,v 4.5 2006/06/04 14:03:12 schmidt 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 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 private:
00103   /// Remove a element from the list
00104   /**
00105    * No attempts are performed to check if T* really belongs to the
00106    * list.  The effects of removing an invalid element are unspecified
00107    */
00108   void remove_i (T *node);
00109 
00110   /** @name Disallow copying
00111    *
00112    */
00113   //@{
00114   ACE_Intrusive_List (const ACE_Intrusive_List<T> &);
00115   ACE_Intrusive_List<T>& operator= (const ACE_Intrusive_List<T> &);
00116   //@}
00117 
00118 private:
00119   /// Head of the list
00120   T *head_;
00121 
00122   /// Tail of the list
00123   T *tail_;
00124 };
00125 
00126 ACE_END_VERSIONED_NAMESPACE_DECL
00127 
00128 #if defined (__ACE_INLINE__)
00129 #include "ace/Intrusive_List.inl"
00130 #endif /* __ACE_INLINE__ */
00131 
00132 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00133 #include "ace/Intrusive_List.cpp"
00134 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00135 
00136 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00137 #pragma implementation ("Intrusive_List.cpp")
00138 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00139 
00140 #include /**/ "ace/post.h"
00141 #endif /* ACE_INTRUSIVE_LIST_H */

Generated on Thu Nov 9 09:41:52 2006 for ACE by doxygen 1.3.6