home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 3.3 KB | 147 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // Restricted Rights Legend
- // Use, duplication, or disclosure is subject to restrictions as set forth
- // in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer
- // Software clause at DFARS 252.227-7013.
- //
- // BCQue.cpp
- //
- // This file contains the definitions for the queue abstract base class
- // and its iterators.
-
- #include "BCQue.h"
-
- template<class Item>
- BC_TQueue<Item>::BC_TQueue() {}
-
- template<class Item>
- BC_TQueue<Item>::BC_TQueue(const BC_TQueue<Item>&) {}
-
- template<class Item>
- BC_TQueue<Item>::~BC_TQueue() {}
-
- template<class Item>
- BC_TQueue<Item>& BC_TQueue<Item>::operator=(const BC_TQueue<Item>& q)
- {
- if (this == &q)
- return *this;
- ((BC_TQueue<Item>&)q).Lock();
- Purge();
- BC_TQueueActiveIterator<Item> iter(q);
- while (!iter.IsDone()) {
- Add(*iter.CurrentItem());
- iter.Next();
- }
- ((BC_TQueue<Item>&)q).Unlock();
- return *this;
- }
-
- template<class Item>
- BC_Boolean BC_TQueue<Item>::operator==(const BC_TQueue<Item>& q) const
- {
- if (this == &q)
- return 1;
- ((BC_TQueue<Item>&)q).Lock();
- if (Cardinality() != q.Cardinality()) {
- ((BC_TQueue<Item>&)q).Unlock();
- return 0;
- }
- BC_TQueueActiveIterator<Item> iter_1(*this), iter_2(q);
- while (!iter_1.IsDone()) {
- if (*iter_1.CurrentItem() != *iter_2.CurrentItem()) {
- ((BC_TQueue<Item>&)q).Unlock();
- return 0;
- }
- iter_1.Next();
- iter_2.Next();
- }
- ((BC_TQueue<Item>&)q).Unlock();
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TQueue<Item>::operator!=(const BC_TQueue<Item>& q) const
- {
- return !operator==(q);
- }
-
- template<class Item>
- void BC_TQueue<Item>::Lock() {}
-
- template<class Item>
- void BC_TQueue<Item>::Unlock() {}
-
- template<class Item>
- BC_TQueueActiveIterator<Item>::BC_TQueueActiveIterator(const BC_TQueue<Item>& q)
- : fQueue(q),
- fIndex(q.Cardinality() ? 0 : -1) {}
-
- template<class Item>
- BC_TQueueActiveIterator<Item>::~BC_TQueueActiveIterator() {}
-
- template<class Item>
- void BC_TQueueActiveIterator<Item>::Reset()
- {
- fIndex = fQueue.Cardinality() ? 0 : -1;
- }
-
- template<class Item>
- BC_Boolean BC_TQueueActiveIterator<Item>::Next()
- {
- fIndex++;
- return !IsDone();
- }
-
- template<class Item>
- BC_Boolean BC_TQueueActiveIterator<Item>::IsDone() const
- {
- return ((fIndex < 0) || (fIndex >= fQueue.Cardinality()));
- }
-
- template<class Item>
- const Item* BC_TQueueActiveIterator<Item>::CurrentItem() const
- {
- return IsDone() ? 0 : &fQueue.ItemAt(fIndex);
- }
-
- template<class Item>
- Item* BC_TQueueActiveIterator<Item>::CurrentItem()
- {
- return IsDone() ? 0 : &((Item&)(fQueue.ItemAt(fIndex)));
- }
-
- template<class Item>
- BC_TQueuePassiveIterator<Item>::BC_TQueuePassiveIterator(const BC_TQueue<Item>& q)
- : fQueue(q) {}
-
- template<class Item>
- BC_TQueuePassiveIterator<Item>::~BC_TQueuePassiveIterator() {}
-
- template<class Item>
- BC_Boolean BC_TQueuePassiveIterator<Item>::Apply(BC_Boolean (*f)(const Item&))
- {
- BC_TQueueActiveIterator<Item> iter(fQueue);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TQueuePassiveIterator<Item>::Apply(BC_Boolean (*f)(Item&))
- {
- BC_TQueueActiveIterator<Item> iter(fQueue);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-