Restore build on FreeBSD.
[getmangos.git] / dep / ACE_wrappers / ace / Unbounded_Set_Ex.cpp
blobc5cd9e27b213ab74b584ff4c236dbd058c5e4591
1 // $Id: Unbounded_Set_Ex.cpp 81702 2008-05-15 10:18:07Z johnnyw $
3 #ifndef ACE_UNBOUNDED_SET_EX_CPP
4 #define ACE_UNBOUNDED_SET_EX_CPP
6 #include "ace/Unbounded_Set.h"
7 #include "ace/Malloc_Base.h"
8 #include "ace/Log_Msg.h"
10 #if !defined (ACE_LACKS_PRAGMA_ONCE)
11 # pragma once
12 #endif /* ACE_LACKS_PRAGMA_ONCE */
14 #if !defined (__ACE_INLINE__)
15 #include "ace/Unbounded_Set_Ex.inl"
16 #endif /* __ACE_INLINE__ */
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Ex)
22 template <class T, class C> size_t
23 ACE_Unbounded_Set_Ex<T, C>::size (void) const
25 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::size");
26 return this->cur_size_;
29 template <class T, class C> int
30 ACE_Unbounded_Set_Ex<T, C>::insert_tail (const T &item)
32 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::insert_tail");
33 NODE *temp = 0;
35 // Insert <item> into the old dummy node location.
36 this->head_->item_ = item;
38 // Create a new dummy node.
39 ACE_NEW_MALLOC_RETURN (temp,
40 static_cast<NODE*> (this->allocator_->malloc (sizeof (NODE))),
41 NODE (this->head_->next_),
42 -1);
43 // Link this pointer into the list.
44 this->head_->next_ = temp;
46 // Point the head to the new dummy node.
47 this->head_ = temp;
49 ++this->cur_size_;
50 return 0;
53 template <class T, class C> void
54 ACE_Unbounded_Set_Ex<T, C>::reset (void)
56 ACE_TRACE ("reset");
58 this->delete_nodes ();
61 template <class T, class C> void
62 ACE_Unbounded_Set_Ex<T, C>::dump (void) const
64 #if defined (ACE_HAS_DUMP)
65 ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::dump");
67 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
68 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_ = %u"), this->head_));
69 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhead_->next_ = %u"), this->head_->next_));
70 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ncur_size_ = %d\n"), this->cur_size_));
72 T *item = 0;
73 #if !defined (ACE_NLOGGING)
74 size_t count = 1;
75 #endif /* ! ACE_NLOGGING */
77 const_iterator const the_end = this->end ();
78 for (const_iterator i (this->begin ());
79 i != end;
80 ++i)
81 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("count = %u\n"), count++));
83 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
84 #endif /* ACE_HAS_DUMP */
87 template <class T, class C> void
88 ACE_Unbounded_Set_Ex<T, C>::copy_nodes (const ACE_Unbounded_Set_Ex<T, C> &us)
90 for (NODE *curr = us.head_->next_;
91 curr != us.head_;
92 curr = curr->next_)
93 this->insert_tail (curr->item_);
96 template <class T, class C> void
97 ACE_Unbounded_Set_Ex<T, C>::delete_nodes (void)
99 NODE *curr = this->head_->next_;
101 // Keep looking until we've hit the dummy node.
103 while (curr != this->head_)
105 NODE *temp = curr;
106 curr = curr->next_;
107 ACE_DES_FREE_TEMPLATE2 (temp,
108 this->allocator_->free,
109 ACE_Node,
110 T, C);
111 --this->cur_size_;
114 // Reset the list to be a circular list with just a dummy node.
115 this->head_->next_ = this->head_;
118 template <class T, class C>
119 ACE_Unbounded_Set_Ex<T, C>::~ACE_Unbounded_Set_Ex (void)
121 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::~ACE_Unbounded_Set_Ex");
123 this->delete_nodes ();
125 // Delete the dummy node.
126 ACE_DES_FREE_TEMPLATE2 (head_,
127 this->allocator_->free,
128 ACE_Node,
129 T, C);
130 this->head_ = 0;
133 template <class T, class C>
134 ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex (ACE_Allocator *alloc)
135 : head_ (0),
136 cur_size_ (0),
137 allocator_ (alloc)
139 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex");
141 if (this->allocator_ == 0)
142 this->allocator_ = ACE_Allocator::instance ();
144 ACE_NEW_MALLOC (this->head_,
145 (NODE*) this->allocator_->malloc (sizeof (NODE)),
146 NODE);
147 // Make the list circular by pointing it back to itself.
148 this->head_->next_ = this->head_;
151 template <class T, class C>
152 ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex (const C &comp,
153 ACE_Allocator *alloc)
154 : head_ (0),
155 cur_size_ (0),
156 allocator_ (alloc),
157 comp_ (comp)
159 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex");
161 if (this->allocator_ == 0)
162 this->allocator_ = ACE_Allocator::instance ();
164 ACE_NEW_MALLOC (this->head_,
165 (NODE*) this->allocator_->malloc (sizeof (NODE)),
166 NODE);
167 // Make the list circular by pointing it back to itself.
168 this->head_->next_ = this->head_;
171 template <class T, class C>
172 ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex (const ACE_Unbounded_Set_Ex<T, C> &us)
173 : head_ (0),
174 cur_size_ (0),
175 allocator_ (us.allocator_),
176 comp_ (us.comp_)
178 ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::ACE_Unbounded_Set_Ex");
180 if (this->allocator_ == 0)
181 this->allocator_ = ACE_Allocator::instance ();
183 ACE_NEW_MALLOC (this->head_,
184 (NODE*) this->allocator_->malloc (sizeof (NODE)),
185 NODE);
186 this->head_->next_ = this->head_;
187 this->copy_nodes (us);
190 template <class T, class C> ACE_Unbounded_Set_Ex<T, C> &
191 ACE_Unbounded_Set_Ex<T, C>::operator= (const ACE_Unbounded_Set_Ex<T, C> &us)
193 ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::operator=");
195 if (this != &us)
197 this->delete_nodes ();
198 this->copy_nodes (us);
201 return *this;
204 template <class T, class C> int
205 ACE_Unbounded_Set_Ex<T, C>::find (const T &item) const
207 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::find");
208 const_iterator const the_end = this->end ();
209 for (const_iterator i = this->begin (); i != the_end; ++i)
210 if (this->comp_(*i, item))
211 return 0;
213 return -1;
216 template <class T, class C> int
217 ACE_Unbounded_Set_Ex<T, C>::insert (const T &item)
219 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::insert");
220 if (this->find (item) == 0)
221 return 1;
222 else
223 return this->insert_tail (item);
226 template <class T, class C> int
227 ACE_Unbounded_Set_Ex<T, C>::remove (const T &item)
229 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::remove");
231 // Insert the item to be founded into the dummy node.
232 this->head_->item_ = item;
234 NODE *curr = this->head_;
236 while (!(this->comp_ (curr->next_->item_, item)))
237 curr = curr->next_;
239 if (curr->next_ == this->head_)
240 return -1; // Item was not found.
241 else
243 NODE *temp = curr->next_;
244 // Skip over the node that we're deleting.
245 curr->next_ = temp->next_;
246 --this->cur_size_;
247 ACE_DES_FREE_TEMPLATE2 (temp,
248 this->allocator_->free,
249 ACE_Node,
250 T, C);
251 return 0;
255 template <class T, class C> typename ACE_Unbounded_Set_Ex<T, C>::iterator
256 ACE_Unbounded_Set_Ex<T, C>::begin (void)
258 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::begin");
259 return iterator (*this);
262 template <class T, class C> typename ACE_Unbounded_Set_Ex<T, C>::iterator
263 ACE_Unbounded_Set_Ex<T, C>::end (void)
265 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::end");
266 return iterator (*this, 1);
269 template <class T, class C> typename ACE_Unbounded_Set_Ex<T, C>::const_iterator
270 ACE_Unbounded_Set_Ex<T, C>::begin (void) const
272 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::begin");
273 return const_iterator (*this);
276 template <class T, class C> typename ACE_Unbounded_Set_Ex<T, C>::const_iterator
277 ACE_Unbounded_Set_Ex<T, C>::end (void) const
279 // ACE_TRACE ("ACE_Unbounded_Set_Ex<T, C>::end");
280 return const_iterator (*this, 1);
283 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Ex_Iterator)
285 template <class T, class C> void
286 ACE_Unbounded_Set_Ex_Iterator<T, C>::dump (void) const
288 #if defined (ACE_HAS_DUMP)
289 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::dump");
290 #endif /* ACE_HAS_DUMP */
293 template <class T, class C>
294 ACE_Unbounded_Set_Ex_Iterator<T, C>::ACE_Unbounded_Set_Ex_Iterator (
295 ACE_Unbounded_Set_Ex<T, C> &s,
296 bool end)
297 : current_ (!end ? s.head_->next_ : s.head_ ),
298 set_ (&s)
300 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::ACE_Unbounded_Set_Ex_Iterator");
303 template <class T, class C> int
304 ACE_Unbounded_Set_Ex_Iterator<T, C>::advance (void)
306 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::advance");
307 this->current_ = this->current_->next_;
308 return this->current_ != this->set_->head_;
311 template <class T, class C> int
312 ACE_Unbounded_Set_Ex_Iterator<T, C>::first (void)
314 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::first");
315 this->current_ = this->set_->head_->next_;
316 return this->current_ != this->set_->head_;
319 template <class T, class C> int
320 ACE_Unbounded_Set_Ex_Iterator<T, C>::done (void) const
322 ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::done");
324 return this->current_ == this->set_->head_;
327 template <class T, class C> int
328 ACE_Unbounded_Set_Ex_Iterator<T, C>::next (T *&item)
330 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::next");
331 if (this->current_ == this->set_->head_)
332 return 0;
333 else
335 item = &this->current_->item_;
336 return 1;
340 template <class T, class C> ACE_Unbounded_Set_Ex_Iterator<T, C>
341 ACE_Unbounded_Set_Ex_Iterator<T, C>::operator++ (int)
343 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::operator++ (int)");
344 ACE_Unbounded_Set_Ex_Iterator<T, C> retv (*this);
346 // postfix operator
348 this->advance ();
349 return retv;
352 template <class T, class C> ACE_Unbounded_Set_Ex_Iterator<T, C>&
353 ACE_Unbounded_Set_Ex_Iterator<T, C>::operator++ (void)
355 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::operator++ (void)");
357 // prefix operator
359 this->advance ();
360 return *this;
363 template <class T, class C> T&
364 ACE_Unbounded_Set_Ex_Iterator<T, C>::operator* (void)
366 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::operator*");
367 T *retv = 0;
369 int result = this->next (retv);
370 ACE_ASSERT (result != 0);
371 ACE_UNUSED_ARG (result);
373 return *retv;
376 template <class T, class C> bool
377 ACE_Unbounded_Set_Ex_Iterator<T, C>::operator== (const ACE_Unbounded_Set_Ex_Iterator<T, C> &rhs) const
379 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::operator==");
380 return (this->set_ == rhs.set_ && this->current_ == rhs.current_);
383 template <class T, class C> bool
384 ACE_Unbounded_Set_Ex_Iterator<T, C>::operator!= (const ACE_Unbounded_Set_Ex_Iterator<T, C> &rhs) const
386 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Iterator<T, C>::operator!=");
387 return (this->set_ != rhs.set_ || this->current_ != rhs.current_);
390 ACE_ALLOC_HOOK_DEFINE(ACE_Unbounded_Set_Ex_Const_Iterator)
392 template <class T, class C> void
393 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::dump (void) const
395 #if defined (ACE_HAS_DUMP)
396 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::dump");
397 #endif /* ACE_HAS_DUMP */
400 template <class T, class C>
401 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::ACE_Unbounded_Set_Ex_Const_Iterator (
402 const ACE_Unbounded_Set_Ex<T, C> &s,
403 bool end)
404 : current_ (!end ? s.head_->next_ : s.head_ ),
405 set_ (&s)
407 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::ACE_Unbounded_Set_Ex_Const_Iterator");
410 template <class T, class C> int
411 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::advance (void)
413 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::advance");
414 this->current_ = this->current_->next_;
415 return this->current_ != this->set_->head_;
418 template <class T, class C> int
419 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::first (void)
421 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::first");
422 this->current_ = this->set_->head_->next_;
423 return this->current_ != this->set_->head_;
426 template <class T, class C> int
427 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::done (void) const
429 ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::done");
431 return this->current_ == this->set_->head_;
434 template <class T, class C> int
435 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::next (T *&item)
437 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::next");
438 if (this->current_ == this->set_->head_)
439 return 0;
440 else
442 item = &this->current_->item_;
443 return 1;
447 template <class T, class C> ACE_Unbounded_Set_Ex_Const_Iterator<T, C>
448 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator++ (int)
450 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator++ (int)");
451 ACE_Unbounded_Set_Ex_Const_Iterator<T, C> retv (*this);
453 // postfix operator
455 this->advance ();
456 return retv;
459 template <class T, class C> ACE_Unbounded_Set_Ex_Const_Iterator<T, C>&
460 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator++ (void)
462 // ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator++ (void)");
464 // prefix operator
466 this->advance ();
467 return *this;
470 template <class T, class C> T&
471 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator* (void)
473 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator*");
474 T *retv = 0;
476 int const result = this->next (retv);
477 ACE_ASSERT (result != 0);
478 ACE_UNUSED_ARG (result);
480 return *retv;
483 template <class T, class C> bool
484 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator== (const ACE_Unbounded_Set_Ex_Const_Iterator<T, C> &rhs) const
486 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator==");
487 return (this->set_ == rhs.set_ && this->current_ == rhs.current_);
490 template <class T, class C> bool
491 ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator!= (const ACE_Unbounded_Set_Ex_Const_Iterator<T, C> &rhs) const
493 //ACE_TRACE ("ACE_Unbounded_Set_Ex_Const_Iterator<T, C>::operator!=");
494 return (this->set_ != rhs.set_ || this->current_ != rhs.current_);
497 ACE_END_VERSIONED_NAMESPACE_DECL
499 #endif /* ACE_UNBOUNDED_SET_EX_CPP */