home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-16 | 1.7 KB | 104 lines | [TEXT/CWIE] |
- /*
- File: CustomAttributes.cp
-
- Contains: Quickie minimal implementation of
- Collection Manager for System 7.x.
-
- Version: 1.0 (for System 7.5)
-
- Copyright: ©1995 Chris K. Thomas. All Rights Reserved.
- */
-
- #include "Collections++.h"
-
- //
- // add a tag if nonexistant or change existing tag
- //
-
- void
- TagTable::SetTag(FlavorType inTag, void * inData, long inDataSize)
- {
- Ptr tagPtr;
-
- if(!LookupTag(inTag, &tagPtr))
- {
- //
- // add tag
- //
- CollectableTag ourTag;
-
- ourTag.tag = inTag;
- ourTag.ptr = NewPtrClear(inDataSize);
-
- Assert_(ourTag.ptr);
-
- if(ourTag.ptr == NULL)
- throw MemError();
-
- BlockMoveData(inData, ourTag.ptr, inDataSize);
-
- // DebugNum(mTagTable.getcount() + 1);
- mTagTable.setcount(mTagTable.getcount() + 1);
-
- mTagTable.lock();
- mTagTable[mTagTable.getcount() - 1] = ourTag;
- mTagTable.unlock();
- }
- else
- {
- //
- // set tag
- //
- Assert_(tagPtr);
- SetPtrSize(tagPtr, inDataSize);
-
- long error = MemError();
-
- if(error != noErr)
- throw error;
-
- BlockMoveData(inData, tagPtr, inDataSize);
- }
- }
-
- TagTable::~TagTable()
- {
- mTagTable.lock();
-
- long tagCount = mTagTable.getcount();
-
- for(long curTag = 0; curTag < tagCount; curTag++)
- {
- Assert_(mTagTable[curTag].ptr);
- DisposePtr(mTagTable[curTag].ptr);
- }
-
- mTagTable.unlock();
- }
-
- //
- // LookupTag
- // Given a tag, return the corresponding data
- //
- Boolean
- TagTable::LookupTag(FlavorType inTag, Ptr *outData)
- {
- mTagTable.lock();
-
- long tagCount = mTagTable.getcount();
- Boolean outFound = false;
-
- for(long curTag = 0; curTag < tagCount; curTag++)
- {
- if(mTagTable[curTag].tag == inTag)
- {
- *outData = mTagTable[curTag].ptr;
- outFound = true;
- break;
- }
- }
-
- mTagTable.unlock();
-
- return outFound;
- }