00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef NS_CONTAINER_CPP
00014 #define NS_CONTAINER_CPP
00015
00016 #include "ace/Malloc_Base.h"
00017
00018 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00019 # pragma once
00020 #endif
00021
00022 #include "orbsvcs/Naming/Naming_Service_Container.h"
00023
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 ACE_ALLOC_HOOK_DEFINE(ACE_NS_Node)
00027
00028 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
00029 template <class T>
00030 ACE_NS_Node<T>::~ACE_NS_Node (void)
00031 {
00032 }
00033 # endif
00034
00035 template <class T>
00036 ACE_NS_Node<T>::ACE_NS_Node (const T &i, ACE_NS_Node<T> *n)
00037 : next_ (n),
00038 item_ (i)
00039 {
00040
00041 }
00042
00043 template <class T>
00044 ACE_NS_Node<T>::ACE_NS_Node (ACE_NS_Node<T> *n, int)
00045 : next_ (n)
00046 {
00047
00048 }
00049
00050 template <class T>
00051 ACE_NS_Node<T>::ACE_NS_Node (const ACE_NS_Node<T> &s)
00052 : next_ (s.next_),
00053 item_ (s.item_)
00054 {
00055
00056 }
00057
00058
00059 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_List)
00060
00061 template <class T> size_t
00062 ACE_Unbounded_List<T>::size (void) const
00063 {
00064
00065 return this->cur_size_;
00066 }
00067
00068 template <class T> int
00069 ACE_Unbounded_List<T>::insert_tail (const T &item)
00070 {
00071 ACE_NS_Node<T> *temp;
00072
00073
00074 this->head_->item_ = item;
00075
00076
00077 ACE_NEW_MALLOC_RETURN (temp,
00078 (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00079 ACE_NS_Node<T> (this->head_->next_),
00080 -1);
00081
00082 this->head_->next_ = temp;
00083
00084
00085 this->head_ = temp;
00086
00087 this->cur_size_++;
00088 return 0;
00089 }
00090
00091 template <class T> void
00092 ACE_Unbounded_List<T>::reset (void)
00093 {
00094 ACE_TRACE ("reset");
00095
00096 this->delete_nodes ();
00097 }
00098
00099 template <class T> void
00100 ACE_Unbounded_List<T>::dump (void) const
00101 {
00102 ACE_TRACE ("ACE_Unbounded_List<T>::dump");
00103
00104 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00105 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_ = %u"), this->head_));
00106 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
00107 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
00108
00109 T *item = 0;
00110 #if !defined (ACE_NLOGGING)
00111 size_t count = 1;
00112 #endif
00113
00114 for (ACE_Unbounded_List_Iterator<T> iter (*(ACE_Unbounded_List<T> *) this);
00115 iter.next (item) != 0;
00116 iter.advance ())
00117 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("count = %d\n"), count++));
00118
00119 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00120 }
00121
00122 template <class T> void
00123 ACE_Unbounded_List<T>::copy_nodes (const ACE_Unbounded_List<T> &us)
00124 {
00125 for (ACE_NS_Node<T> *curr = us.head_->next_;
00126 curr != us.head_;
00127 curr = curr->next_)
00128 this->insert_tail (curr->item_);
00129 }
00130
00131 template <class T> void
00132 ACE_Unbounded_List<T>::delete_nodes (void)
00133 {
00134 ACE_NS_Node<T> *curr = this->head_->next_;
00135
00136
00137
00138 while (curr != this->head_)
00139 {
00140 ACE_NS_Node<T> *temp = curr;
00141 curr = curr->next_;
00142 ACE_DES_FREE_TEMPLATE (temp,
00143 this->allocator_->free,
00144 ACE_NS_Node,
00145 <T>);
00146 this->cur_size_--;
00147 }
00148
00149
00150 this->head_->next_ = this->head_;
00151 }
00152
00153 template <class T>
00154 ACE_Unbounded_List<T>::~ACE_Unbounded_List (void)
00155 {
00156
00157
00158 this->delete_nodes ();
00159
00160
00161 ACE_DES_FREE_TEMPLATE (head_,
00162 this->allocator_->free,
00163 ACE_NS_Node,
00164 <T>);
00165 this->head_ = 0;
00166 }
00167
00168 template <class T>
00169 ACE_Unbounded_List<T>::ACE_Unbounded_List (ACE_Allocator *alloc)
00170 : head_ (0),
00171 cur_size_ (0),
00172 allocator_ (alloc)
00173 {
00174
00175
00176 if (this->allocator_ == 0)
00177 this->allocator_ = ACE_Allocator::instance ();
00178
00179 ACE_NEW_MALLOC (this->head_,
00180 (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00181 ACE_NS_Node<T>);
00182
00183 this->head_->next_ = this->head_;
00184 }
00185
00186 template <class T>
00187 ACE_Unbounded_List<T>::ACE_Unbounded_List (const ACE_Unbounded_List<T> &us)
00188 : head_ (0),
00189 cur_size_ (0),
00190 allocator_ (us.allocator_)
00191 {
00192 ACE_TRACE ("ACE_Unbounded_List<T>::ACE_Unbounded_List");
00193
00194 if (this->allocator_ == 0)
00195 this->allocator_ = ACE_Allocator::instance ();
00196
00197 ACE_NEW_MALLOC (this->head_,
00198 (ACE_NS_Node<T>*) this->allocator_->malloc (sizeof (ACE_NS_Node<T>)),
00199 ACE_NS_Node<T>);
00200 this->head_->next_ = this->head_;
00201 this->copy_nodes (us);
00202 }
00203
00204 template <class T> void
00205 ACE_Unbounded_List<T>::operator= (const ACE_Unbounded_List<T> &us)
00206 {
00207 ACE_TRACE ("ACE_Unbounded_List<T>::operator=");
00208
00209 if (this != &us)
00210 {
00211 this->delete_nodes ();
00212 this->copy_nodes (us);
00213 }
00214 }
00215
00216 template <class T> int
00217 ACE_Unbounded_List<T>::insert (const T &item)
00218 {
00219 ACE_TRACE ("ACE_Unbounded_List<T>::insert");
00220 return this->insert_tail (item);
00221 }
00222
00223 template <class T> int
00224 ACE_Unbounded_List<T>::remove (const T &item)
00225 {
00226
00227
00228
00229 this->head_->item_ = item;
00230
00231 ACE_NS_Node<T> *curr = this->head_;
00232
00233 while (!(curr->next_->item_ == item))
00234 curr = curr->next_;
00235
00236 if (curr->next_ == this->head_)
00237 return -1;
00238 else
00239 {
00240 ACE_NS_Node<T> *temp = curr->next_;
00241
00242 curr->next_ = temp->next_;
00243 this->cur_size_--;
00244 ACE_DES_FREE_TEMPLATE (temp,
00245 this->allocator_->free,
00246 ACE_NS_Node,
00247 <T>);
00248 return 0;
00249 }
00250 }
00251
00252 template <class T> ACE_Unbounded_List_Iterator<T>
00253 ACE_Unbounded_List<T>::begin (void)
00254 {
00255
00256 return ACE_Unbounded_List_Iterator<T> (*this);
00257 }
00258
00259 template <class T> ACE_Unbounded_List_Iterator<T>
00260 ACE_Unbounded_List<T>::end (void)
00261 {
00262
00263 return ACE_Unbounded_List_Iterator<T> (*this, 1);
00264 }
00265
00266
00267 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_List_Iterator)
00268
00269 template <class T> void
00270 ACE_Unbounded_List_Iterator<T>::dump (void) const
00271 {
00272
00273 }
00274
00275 template <class T>
00276 ACE_Unbounded_List_Iterator<T>::ACE_Unbounded_List_Iterator (ACE_Unbounded_List<T> &s, int end)
00277 : current_ (end == 0 ? s.head_->next_ : s.head_ ),
00278 set_ (&s)
00279 {
00280
00281 }
00282
00283 template <class T> int
00284 ACE_Unbounded_List_Iterator<T>::advance (void)
00285 {
00286
00287 this->current_ = this->current_->next_;
00288 return this->current_ != this->set_->head_;
00289 }
00290
00291 template <class T> int
00292 ACE_Unbounded_List_Iterator<T>::first (void)
00293 {
00294
00295 this->current_ = this->set_->head_->next_;
00296 return this->current_ != this->set_->head_;
00297 }
00298
00299 template <class T> int
00300 ACE_Unbounded_List_Iterator<T>::done (void) const
00301 {
00302 ACE_TRACE ("ACE_Unbounded_List_Iterator<T>::done");
00303
00304 return this->current_ == this->set_->head_;
00305 }
00306
00307 template <class T> int
00308 ACE_Unbounded_List_Iterator<T>::next (T *&item)
00309 {
00310
00311 if (this->current_ == this->set_->head_)
00312 return 0;
00313 else
00314 {
00315 item = &this->current_->item_;
00316 return 1;
00317 }
00318 }
00319
00320 template <class T> ACE_Unbounded_List_Iterator<T>
00321 ACE_Unbounded_List_Iterator<T>::operator++ (int)
00322 {
00323
00324 ACE_Unbounded_List_Iterator<T> retv (*this);
00325
00326
00327
00328 this->advance ();
00329 return retv;
00330 }
00331
00332 template <class T> ACE_Unbounded_List_Iterator<T>&
00333 ACE_Unbounded_List_Iterator<T>::operator++ (void)
00334 {
00335
00336
00337
00338
00339 this->advance ();
00340 return *this;
00341 }
00342
00343 template <class T> T&
00344 ACE_Unbounded_List_Iterator<T>::operator* (void)
00345 {
00346
00347 T *retv = 0;
00348
00349 int result = this->next (retv);
00350 ACE_ASSERT (result != 0);
00351 ACE_UNUSED_ARG (result);
00352
00353 return *retv;
00354 }
00355
00356 template <class T> bool
00357 ACE_Unbounded_List_Iterator<T>::operator== (const ACE_Unbounded_List_Iterator<T> &rhs) const
00358 {
00359
00360 return (this->set_ == rhs.set_ && this->current_ == rhs.current_);
00361 }
00362
00363 template <class T> bool
00364 ACE_Unbounded_List_Iterator<T>::operator!= (const ACE_Unbounded_List_Iterator<T> &rhs) const
00365 {
00366
00367 return (this->set_ != rhs.set_ || this->current_ != rhs.current_);
00368 }
00369
00370
00371
00372 template <class T> int
00373 ACE_Unbounded_List<T>::is_empty (void) const
00374 {
00375 ACE_TRACE ("ACE_Unbounded_List<T>::is_empty");
00376 return this->head_ == this->head_->next_;
00377 }
00378
00379 template <class T> int
00380 ACE_Unbounded_List<T>::is_full (void) const
00381 {
00382 ACE_TRACE ("ACE_Unbounded_List<T>::is_full");
00383 return 0;
00384 }
00385
00386 TAO_END_VERSIONED_NAMESPACE_DECL
00387
00388
00389 #endif