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