00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Naming_Service_Container.h 00006 * 00007 * $Id: Naming_Service_Container.h 71541 2006-03-15 07:52:22Z jtc $ 00008 * 00009 * @author Bruce Trask <trask_b@ociweb.com> 00010 */ 00011 //============================================================================= 00012 00013 00014 00015 #ifndef NS_CONTAINER_H 00016 #define NS_CONTAINER_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include "ace/ACE.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 00026 #include "tao/orbconf.h" 00027 00028 // Need by ACE_DLList_Node. 00029 #include "ace/Containers.h" 00030 00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00032 class ACE_Allocator; 00033 ACE_END_VERSIONED_NAMESPACE_DECL 00034 00035 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00036 00037 template <class T> class ACE_Unbounded_List; 00038 template <class T> class ACE_Unbounded_List_Iterator; 00039 00040 /** 00041 * @class ACE_NS_Node 00042 * 00043 * @brief Implementation element in a Queue, List, and Stack. 00044 */ 00045 template<class T> 00046 class ACE_NS_Node 00047 { 00048 public: 00049 friend class ACE_Unbounded_List<T>; 00050 friend class ACE_Unbounded_List_Iterator<T>; 00051 00052 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS) 00053 /// This isn't necessary, but it keeps some compilers happy. 00054 ~ACE_NS_Node (void); 00055 # endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */ 00056 00057 private: 00058 // = Initialization methods 00059 ACE_NS_Node (const T &i, ACE_NS_Node<T> *n); 00060 ACE_NS_Node (ACE_NS_Node<T> *n = 0, int = 0); 00061 ACE_NS_Node (const ACE_NS_Node<T> &n); 00062 00063 /// Pointer to next element in the list of <ACE_NS_Node>s. 00064 ACE_NS_Node<T> *next_; 00065 00066 /// Current value of the item in this node. 00067 T item_; 00068 }; 00069 00070 /** 00071 * @class ACE_Unbounded_List_Iterator 00072 * 00073 * @brief Implement an iterator over an unbounded List. 00074 */ 00075 template <class T> 00076 class ACE_Unbounded_List_Iterator 00077 { 00078 public: 00079 // = Initialization method. 00080 ACE_Unbounded_List_Iterator (ACE_Unbounded_List<T> &s, int end = 0); 00081 00082 // = Iteration methods. 00083 00084 /// Pass back the <next_item> that hasn't been seen in the List. 00085 /// Returns 0 when all items have been seen, else 1. 00086 int next (T *&next_item); 00087 00088 /// Move forward by one element in the List. Returns 0 when all the 00089 /// items in the List have been seen, else 1. 00090 int advance (void); 00091 00092 /// Move to the first element in the List. Returns 0 if the 00093 /// List is empty, else 1. 00094 int first (void); 00095 00096 /// Returns 1 when all items have been seen, else 0. 00097 int done (void) const; 00098 00099 /// Dump the state of an object. 00100 void dump (void) const; 00101 00102 // = STL styled iteration, compare, and reference functions. 00103 00104 /// Postfix advance. 00105 ACE_Unbounded_List_Iterator<T> operator++ (int); 00106 00107 /// Prefix advance. 00108 ACE_Unbounded_List_Iterator<T>& operator++ (void); 00109 00110 /// Returns a reference to the interal element <this> is pointing to. 00111 T& operator* (void); 00112 00113 /// Check if two iterators point to the same position 00114 bool operator== (const ACE_Unbounded_List_Iterator<T> &) const; 00115 bool operator!= (const ACE_Unbounded_List_Iterator<T> &) const; 00116 00117 /// Declare the dynamic allocation hooks. 00118 ACE_ALLOC_HOOK_DECLARE; 00119 00120 private: 00121 00122 /// Pointer to the current node in the iteration. 00123 ACE_NS_Node<T> *current_; 00124 00125 /// Pointer to the set we're iterating over. 00126 ACE_Unbounded_List<T> *set_; 00127 }; 00128 00129 /** 00130 * @class ACE_Unbounded_List 00131 * 00132 * @brief Implement a simple unordered set of <T> of unbounded size. 00133 * 00134 * This implementation of an unordered set uses a circular 00135 * linked list with a dummy node. This implementation does not 00136 * allow duplicates, but it maintains FIFO ordering of insertions. 00137 */ 00138 template <class T> 00139 class ACE_Unbounded_List 00140 { 00141 public: 00142 friend class ACE_Unbounded_List_Iterator<T>; 00143 00144 // Trait definition. 00145 typedef ACE_Unbounded_List_Iterator<T> ITERATOR; 00146 typedef ACE_Unbounded_List_Iterator<T> iterator; 00147 00148 // = Initialization and termination methods. 00149 /// Constructor. Use user specified allocation strategy 00150 /// if specified. 00151 ACE_Unbounded_List (ACE_Allocator *alloc = 0); 00152 00153 /// Copy constructor. 00154 ACE_Unbounded_List (const ACE_Unbounded_List<T> &); 00155 00156 /// Assignment operator. 00157 void operator= (const ACE_Unbounded_List<T> &); 00158 00159 /// Destructor. 00160 ~ACE_Unbounded_List (void); 00161 00162 // = Check boundary conditions. 00163 00164 /// Returns 1 if the container is empty, otherwise returns 0. 00165 int is_empty (void) const; 00166 00167 /// Returns 1 if the container is full, otherwise returns 0. 00168 int is_full (void) const; 00169 00170 // = Classic unordered set operations. 00171 00172 /** 00173 * Insert <new_item> into the set (doesn't allow duplicates). 00174 * Returns -1 if failures occur, 1 if item is already present, else 00175 * 0. 00176 */ 00177 int insert (const T &new_item); 00178 00179 /** 00180 * Remove first occurrence of <item> from the set. Returns 0 if 00181 * it removes the item, -1 if it can't find the item, and -1 if a 00182 * failure occurs. 00183 */ 00184 int remove (const T &item); 00185 00186 /// Size of the set. 00187 size_t size (void) const; 00188 00189 /// Dump the state of an object. 00190 void dump (void) const; 00191 00192 /// Reset the <ACE_Unbounded_List> to be empty. 00193 void reset (void); 00194 00195 // = STL-styled unidirectional iterator factory. 00196 ACE_Unbounded_List_Iterator<T> begin (void); 00197 ACE_Unbounded_List_Iterator<T> end (void); 00198 00199 /// Declare the dynamic allocation hooks. 00200 ACE_ALLOC_HOOK_DECLARE; 00201 00202 private: 00203 /// Insert <item> at the tail of the set (doesn't check for 00204 /// duplicates). 00205 int insert_tail (const T &item); 00206 00207 /// Delete all the nodes in the List. 00208 void delete_nodes (void); 00209 00210 /// Copy nodes into this set. 00211 void copy_nodes (const ACE_Unbounded_List<T> &); 00212 00213 /// Head of the linked list of NS_Nodes. 00214 ACE_NS_Node<T> *head_; 00215 00216 /// Current size of the set. 00217 size_t cur_size_; 00218 00219 /// Allocation strategy of the set. 00220 ACE_Allocator *allocator_; 00221 }; 00222 00223 TAO_END_VERSIONED_NAMESPACE_DECL 00224 00225 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00226 #include "orbsvcs/Naming/Naming_Service_Container.cpp" 00227 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00228 00229 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00230 #pragma implementation ("Naming_Service_Container.cpp") 00231 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00232 00233 #include /**/ "ace/post.h" 00234 #endif /* NS_CONTAINERS_T_H */