home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FW_CPrivFWNode.cpp
-
- Contains: Implementation of FW_CPrivNode class
-
- Written by: Richard Rodseth
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 10/24/94 jpa Added _Cast. Export fns on !ODDebug to keep
- linker happy. [1188344]
- <3> 9/29/94 RA 1189812: Mods for 68K build.
- <2> 6/9/94 RR Remove ASLM Stuff.
- <2> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <6> 2/7/94 JA Tiger Team Makeover!
- <5> 1/31/94 JA Syntactic tweaks to deal with changes in
- FW_CPrivLink and FW_CPrivLinkedList API.
- <4> 11/12/93 JBS fix SkipChildren()
- <3> 9/3/93 JBS added SkipChildren()
- <2> 7/21/93 NP Added outline destructor to FW_CPrivNode for ASLM.
- <1> 1/26/93 RCR first checked in
-
- To Do:
- Optimization: Many methods could be inlined for speed & code size improvements.
- */
-
- #include "FWFound.hpp"
-
- #ifndef FWNODE_H
- #include "FWNode.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwcollec
- #endif
-
- //======================================================================================
- // Class FW_CPrivNode
- //======================================================================================
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode::FW_CPrivNode()
- {
- fParent = NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::~FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode::~FW_CPrivNode()
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- unsigned long FW_CPrivNode::Size()
- {
- unsigned long size = 0;
-
- FW_CPrivNode* node = this->FirstTopDown();
- while (node)
- {
- size++;
- node = node->NextTopDown(FW_kFrontToBack);
- }
- return size;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetParent()
- {
- return fParent;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetFirstChild()
- {
- return (FW_CPrivNode*) this->First();
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetLastChild()
- {
- return (FW_CPrivNode*) this->Last();
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetNextSibling()
- {
- FW_CPrivNode* parent = this->GetParent();
- return parent ? parent->GetChildAfter(this) : NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetChildAfter(FW_CPrivNode* node)
- {
- return (FW_CPrivNode*) this->After(*node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetChildBefore(FW_CPrivNode* node)
- {
- return (FW_CPrivNode*) this->Before(*node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetPreviousSibling()
- {
- FW_CPrivNode* parent = this->GetParent();
- return parent ? parent->GetChildBefore(this) : NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::SetParent(FW_CPrivNode* parent)
- {
- fParent = parent;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::AddChildFirst(FW_CPrivNode* node)
- {
- node->SetParent(this);
- this->AddFirst(node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::AddChildLast(FW_CPrivNode* node)
- {
- node->SetParent(this);
- this->AddLast(node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::AddChildBefore(FW_CPrivNode& existing, FW_CPrivNode* node)
- {
- node->SetParent(this);
- this->FW_CPrivLinkedList::AddBefore(existing, node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::AddChildAfter(FW_CPrivNode& existing, FW_CPrivNode* node)
- {
- node->SetParent(this);
- this->FW_CPrivLinkedList::AddAfter(existing, node);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNode::RemoveChild(FW_CPrivNode& child)
- {
- this->FW_CPrivLinkedList::Remove(child);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::FirstTopDown()
- {
- return this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::NextTopDown(FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* child;
- if (siblingOrder == FW_kFrontToBack)
- child = this->GetFirstChild();
- else
- child = this->GetLastChild();
-
- if (child)
- return child;
- else
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = this->GetNextSibling();
- else
- sibling = this->GetPreviousSibling();
-
- if (sibling)
- return sibling;
- else
- return this->GetNextAunt(siblingOrder);
- }
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::GetNextAunt(FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* parent = this->GetParent();
-
- if (parent)
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = parent->GetNextSibling();
- else
- sibling = parent->GetPreviousSibling();
-
- if (sibling)
- return sibling;
- else
- return parent->GetNextAunt(siblingOrder);
- }
- else
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::FirstBottomUp(FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* child;
- if (siblingOrder == FW_kFrontToBack)
- child = this->GetFirstChild();
- else
- child = this->GetLastChild();
-
- if (child)
- return child->FirstBottomUp(siblingOrder);
- else
- return this;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNode::NextBottomUp(FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* parent = this->GetParent();
-
- if (parent)
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = parent->GetChildAfter(this);
- else
- sibling = parent->GetChildBefore(this);
-
- if (sibling)
- return sibling->FirstBottomUp(siblingOrder);
- else
- return parent;
- }
- else
- return NULL;
-
- return NULL;
- }
-
- //======================================================================================
- // FW_CPrivNodeTraverser
- //======================================================================================
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::FW_CPrivNodeTraverser
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNodeTraverser::FW_CPrivNodeTraverser(FW_CPrivNode* root,
- FW_TraversalType traversalType,
- FW_SiblingOrder siblingOrder)
- {
- fRoot = root;
- fCurrent = NULL;
- fTraversalType = traversalType;
- fSiblingOrder = siblingOrder;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::FW_CPrivNodeTraverser
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNodeTraverser::~FW_CPrivNodeTraverser()
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::FW_CPrivNodeTraverser
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::First()
- {
- if (fRoot)
- {
- if (fTraversalType == FW_kTopDown)
- fCurrent = this->FirstTopDown(fRoot);
- else if (fTraversalType == FW_kBottomUp)
- fCurrent = this->FirstBottomUp(fRoot,fSiblingOrder);
- else if (fTraversalType == FW_kChildrenOnly)
- {
- if (fSiblingOrder == FW_kFrontToBack)
- fCurrent = fRoot->GetFirstChild();
- else
- fCurrent = fRoot->GetLastChild();
- }
- return fCurrent;
- }
- else
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::Next
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::Next()
- {
- if (fCurrent)
- {
- if (fTraversalType == FW_kTopDown)
- fCurrent = this->NextTopDown(fCurrent, fSiblingOrder);
- else if (fTraversalType == FW_kBottomUp)
- fCurrent = this->NextBottomUp(fCurrent, fSiblingOrder);
- else if (fTraversalType == FW_kChildrenOnly)
- {
- if (fSiblingOrder == FW_kFrontToBack)
- fCurrent = fCurrent->GetNextSibling();
- else
- fCurrent = fCurrent->GetPreviousSibling();
- }
- return fCurrent;
- }
- else
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::SkipChildren
- //
- // Description
- //------------------------------------------------------------------------------
-
- void FW_CPrivNodeTraverser::SkipChildren()
- {
- FW_CPrivNode* next = NULL;
- FW_CPrivNode* skipTo = NULL;
- FW_CPrivNode* test = NULL;
-
- if (fCurrent)
- {
- if (fTraversalType == FW_kTopDown)
- {
- if (fSiblingOrder == FW_kFrontToBack)
- next = fCurrent->GetNextSibling();
- else
- next = fCurrent->GetPreviousSibling();
-
- if (!next)
- next = fCurrent->GetNextAunt(fSiblingOrder);
-
- test = fCurrent;
- while ( test != next )
- {
- FW_ASSERT(test != NULL);
- skipTo = test;
- test = this->NextTopDown(test, fSiblingOrder);
- }
-
- fCurrent = skipTo;
- }
- }
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::IsNotComplete
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivNodeTraverser::IsNotComplete()
- {
- return (fCurrent != NULL);
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::FirstTopDown
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::FirstTopDown(FW_CPrivNode* node)
- {
- return node;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::NextTopDown
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::NextTopDown(FW_CPrivNode* node, FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* child;
- if (siblingOrder == FW_kFrontToBack)
- child = node->GetFirstChild();
- else
- child = node->GetLastChild();
-
- if (child)
- return child;
- else if (node != fRoot)
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = node->GetNextSibling();
- else
- sibling = node->GetPreviousSibling();
-
- if (sibling)
- return sibling;
- else
- return this->GetNextAunt(node, siblingOrder);
- }
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::GetNextAunt
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::GetNextAunt(FW_CPrivNode* node, FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* parent = node->GetParent();
-
- if (parent && (parent != fRoot))
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = parent->GetNextSibling();
- else
- sibling = parent->GetPreviousSibling();
-
- if (sibling)
- return sibling;
- else
- return this->GetNextAunt(parent, siblingOrder);
- }
- else
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNodeTraverser::FirstBottomUp
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::FirstBottomUp(FW_CPrivNode* node, FW_SiblingOrder siblingOrder)
- {
- FW_CPrivNode* child;
- if (siblingOrder == FW_kFrontToBack)
- child = node->GetFirstChild();
- else
- child = node->GetLastChild();
-
- if (child)
- return this->FirstBottomUp(child, siblingOrder);
- else
- return node;
- }
-
- //------------------------------------------------------------------------------
- // FW_CPrivNode::FW_CPrivNode
- //
- // Description
- //------------------------------------------------------------------------------
-
- FW_CPrivNode* FW_CPrivNodeTraverser::NextBottomUp(FW_CPrivNode* node, FW_SiblingOrder siblingOrder)
- {
- if (node == fRoot)
- return NULL;
-
- FW_CPrivNode* parent = node->GetParent();
-
- if (parent)
- {
- FW_CPrivNode* sibling;
- if (siblingOrder == FW_kFrontToBack)
- sibling = parent->GetChildAfter(node);
- else
- sibling = parent->GetChildBefore(node);
-
- if (sibling)
- return this->FirstBottomUp(sibling, siblingOrder);
- else
- return parent;
- }
- else
- return NULL;
-
- return NULL;
- }
-
-