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.
- //
- // BCStac.cpp
- //
- // This file contains the definitions for the stack abstract base class
- // and its iterators.
-
- #include "BCStac.h"
-
- template<class Item>
- BC_TStack<Item>::BC_TStack() {}
-
- template<class Item>
- BC_TStack<Item>::BC_TStack(const BC_TStack<Item>&) {}
-
- template<class Item>
- BC_TStack<Item>::~BC_TStack() {}
-
- template<class Item>
- BC_TStack<Item>& BC_TStack<Item>::operator=(const BC_TStack<Item>& s)
- {
- if (this == &s)
- return *this;
- ((BC_TStack<Item>&)s).Lock();
- Purge();
- BC_TStackActiveIterator<Item> iter(s);
- while (!iter.IsDone()) {
- Add(*iter.CurrentItem());
- iter.Next();
- }
- ((BC_TStack<Item>&)s).Unlock();
- return *this;
- }
-
- template<class Item>
- BC_Boolean BC_TStack<Item>::operator==(const BC_TStack<Item>& s) const
- {
- if (this == &s)
- return 1;
- ((BC_TStack<Item>&)s).Lock();
- if (Cardinality() != s.Cardinality()) {
- ((BC_TStack<Item>&)s).Unlock();
- return 0;
- }
- BC_TStackActiveIterator<Item> iter_1(*this), iter_2(s);
- while (!iter_1.IsDone()) {
- if (*iter_1.CurrentItem() != *iter_2.CurrentItem()) {
- ((BC_TStack<Item>&)s).Unlock();
- return 0;
- }
- iter_1.Next();
- iter_2.Next();
- }
- ((BC_TStack<Item>&)s).Unlock();
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TStack<Item>::operator!=(const BC_TStack<Item>& s) const
- {
- return !operator==(s);
- }
-
- template<class Item>
- void BC_TStack<Item>::Lock() {}
-
- template<class Item>
- void BC_TStack<Item>::Unlock() {}
-
- template<class Item>
- BC_TStackActiveIterator<Item>::BC_TStackActiveIterator(const BC_TStack<Item>& s)
- : fStack(s),
- fIndex(s.Cardinality() ? 0 : -1) {}
-
- template<class Item>
- BC_TStackActiveIterator<Item>::~BC_TStackActiveIterator() {}
-
- template<class Item>
- void BC_TStackActiveIterator<Item>::Reset()
- {
- fIndex = fStack.Cardinality() ? 0 : -1;
- }
-
- template<class Item>
- BC_Boolean BC_TStackActiveIterator<Item>::Next()
- {
- fIndex++;
- return !IsDone();
- }
-
- template<class Item>
- BC_Boolean BC_TStackActiveIterator<Item>::IsDone() const
- {
- return ((fIndex < 0) || (fIndex >= fStack.Cardinality()));
- }
-
- template<class Item>
- const Item* BC_TStackActiveIterator<Item>::CurrentItem() const
- {
- return IsDone() ? 0 : &fStack.ItemAt(fIndex);
- }
-
- template<class Item>
- Item* BC_TStackActiveIterator<Item>::CurrentItem()
- {
- return IsDone() ? 0 : &((Item&)(fStack.ItemAt(fIndex)));
- }
-
- template<class Item>
- BC_TStackPassiveIterator<Item>::BC_TStackPassiveIterator(const BC_TStack<Item>& s)
- : fStack(s) {}
-
- template<class Item>
- BC_TStackPassiveIterator<Item>::~BC_TStackPassiveIterator() {}
-
- template<class Item>
- BC_Boolean BC_TStackPassiveIterator<Item>::Apply(BC_Boolean (*f)(const Item&))
- {
- BC_TStackActiveIterator<Item> iter(fStack);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-
- template<class Item>
- BC_Boolean BC_TStackPassiveIterator<Item>::Apply(BC_Boolean (*f)(Item&))
- {
- BC_TStackActiveIterator<Item> iter(fStack);
- while (!iter.IsDone()) {
- if (!f(*iter.CurrentItem()))
- return 0;
- else
- iter.Next();
- }
- return 1;
- }
-