home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.7 KB | 391 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PROrdCol.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef PRORDCOL_H
- #include "PROrdCol.h"
- #endif
-
- #ifndef PRVALLNK_H
- #include "PRValLnk.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #include "FWODExce.h"
-
- //========================================================================================
- // Runtime informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwcollec
- #endif
-
- //========================================================================================
- // Ordered Collection API
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_AddFirst
- //----------------------------------------------------------------------------------------
-
- unsigned long SL_API FW_PrivOrderedCollection_Count(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- return collection->Count();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_AddFirst
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivOrderedCollection_AddFirst(FW_HLinkedList collection,
- const void* element)
- {
- FW_RETURN_ERR_TRY
- {
- FW_ASSERT(element != NULL);
-
- FW_CPrivValueLink* newLink = new FW_CPrivValueLink((void*)element);
-
- collection->AddFirst(newLink);
- }
- FW_RETURN_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_AddLast
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivOrderedCollection_AddLast(FW_HLinkedList collection,
- const void* element)
- {
- FW_RETURN_ERR_TRY
- {
- FW_ASSERT(element != NULL);
-
- FW_CPrivValueLink* newLink = new FW_CPrivValueLink((void*)element);
- collection->AddLast(newLink);
- }
- FW_RETURN_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_AddBefore
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivOrderedCollection_AddBefore(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing,
- const void* tobeadded)
- {
- FW_RETURN_ERR_TRY
- {
- FW_ASSERT(tobeadded != NULL);
-
- FW_CPrivLinkedListIterator iter(collection);
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) iter.First();
- while (aLink != NULL)
- {
- void* v = ((FW_CPrivValueLink*) aLink)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- FW_CPrivValueLink* newLink = new FW_CPrivValueLink((void*)tobeadded);
- collection->AddBefore(aLink, newLink);
- aLink = NULL;
- }
- else
- aLink = (FW_CPrivValueLink*) iter.Next();
- }
- }
- FW_RETURN_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_AddAfter
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivOrderedCollection_AddAfter(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing,
- const void* tobeadded)
- {
- FW_RETURN_ERR_TRY
- {
- FW_ASSERT(tobeadded != NULL);
-
- FW_CPrivLinkedListIterator iter(collection);
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) iter.First();
- while (aLink != NULL)
- {
- void* v = ((FW_CPrivValueLink*) aLink)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- FW_CPrivValueLink* newLink = new FW_CPrivValueLink((void*)tobeadded);
- collection->AddAfter(aLink, newLink);
- aLink = NULL;
- }
- else
- aLink = (FW_CPrivValueLink*) iter.Next();
- }
- }
- FW_RETURN_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_After
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_After(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing)
- {
- FW_CPrivValueLink* linkAfter = NULL;
-
- // No try block necessary - Do not throw
- FW_CPrivLinkedListIterator iter(collection);
-
- for (FW_CPrivValueLink* link = (FW_CPrivValueLink*) iter.First(); iter.IsNotComplete(); link = (FW_CPrivValueLink*) iter.Next())
- {
- void* v = ((FW_CPrivValueLink*) link)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- linkAfter = (FW_CPrivValueLink*) collection->After(link);
- break;
- }
- }
-
- return linkAfter ? linkAfter->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_Before
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_Before(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* linkBefore = NULL;
-
- FW_CPrivLinkedListIterator iter(collection);
-
- for (FW_CPrivValueLink* link = (FW_CPrivValueLink*) iter.First(); iter.IsNotComplete(); link = (FW_CPrivValueLink*) iter.Next())
- {
- void* v = ((FW_CPrivValueLink*) link)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- linkBefore = (FW_CPrivValueLink*) collection->Before(link);
- break;
- }
- }
-
- return linkBefore ? linkBefore->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_First
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_First(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* firstLink = (FW_CPrivValueLink*) collection->First();
- return firstLink ? firstLink->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_Last
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_Last(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* lastLink = (FW_CPrivValueLink*)collection->Last();
- return lastLink ? lastLink->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_RemoveFirst
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_RemoveFirst(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- void* value = NULL;
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) collection->RemoveFirst();
- if (aLink != NULL)
- {
- value = aLink->GetValue();
- delete aLink;
- }
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_RemoveLast
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollection_RemoveLast(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- void* value = NULL;
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) collection->RemoveLast();
- if (aLink != NULL)
- {
- value = aLink->GetValue();
- delete aLink;
- }
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_Remove
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivOrderedCollection_Remove(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing)
- {
- // No try block necessary - Do not throw
- FW_CPrivLinkedListIterator iter(collection);
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) iter.First();
- while (aLink != NULL)
- {
- void* v = ((FW_CPrivValueLink*) aLink)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- collection->Remove(aLink);
- delete aLink;
- aLink = NULL;
- }
- else
- aLink = (FW_CPrivValueLink*) iter.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_RemoveAll
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivOrderedCollection_RemoveAll(FW_HLinkedList collection)
- {
- // No try block necessary - Do not throw
- FW_CPrivLink* link = collection->RemoveFirst();
- while (link != NULL)
- {
- delete link;
- link = collection->RemoveFirst();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollection_Contains
- //----------------------------------------------------------------------------------------
-
- FW_Boolean SL_API FW_PrivOrderedCollection_Contains(FW_HLinkedList collection,
- FW_OrderedCollection_MatchProc matchProc,
- const void* existing)
- {
- // No try block necessary - Do not throw
- FW_CPrivLinkedListIterator iter(collection);
- FW_CPrivValueLink* aLink = (FW_CPrivValueLink*) iter.First();
- while (aLink != NULL)
- {
- void* v = ((FW_CPrivValueLink*) aLink)->GetValue();
-
- if ((matchProc)(v,existing))
- {
- return TRUE;
- }
- else
- aLink = (FW_CPrivValueLink*) iter.Next();
- }
- return FALSE;
- }
-
- //========================================================================================
- // OrderedCollection Iterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_First
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollectionIterator_First(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* link = (FW_CPrivValueLink*) iterator->First();
- return link ? link->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_Next
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollectionIterator_Next(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* link = (FW_CPrivValueLink*) iterator->Next();
- return link ? link->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_Last
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollectionIterator_Last(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* link = (FW_CPrivValueLink*) iterator->Last();
- return link ? link->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_Previous
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollectionIterator_Previous(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* link = (FW_CPrivValueLink*)iterator->Previous();
- return link ? link->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_Current
- //----------------------------------------------------------------------------------------
-
- void* SL_API FW_PrivOrderedCollectionIterator_Current(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- FW_CPrivValueLink* link = (FW_CPrivValueLink*)iterator->Current();
- return link ? link->GetValue() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivOrderedCollectionIterator_IsNotComplete
- //----------------------------------------------------------------------------------------
-
- FW_Boolean SL_API FW_PrivOrderedCollectionIterator_IsNotComplete(FW_HLinkedListIterator iterator)
- {
- // No try block necessary - Do not throw
- return iterator->IsNotComplete();
- }
-