Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes
AEWordIterator Class Reference

#include <nsAEWordClass.h>

Inheritance diagram for AEWordIterator:
Inheritance graph
[legend]
Collaboration diagram for AEWordIterator:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { eNoNameKeyFormSupport = (eHasFormAbsolutePosition | eHasFormRelativePosition | eHasFormRange) }
enum  {
  eHasFormAbsolutePosition = (1 << eFormAbsolutePositionBit), eHasFormRelativePosition = (1 << eFormRelativePositionBit), eHasFormTest = (1 << eFormTestBit), eHasFormRange = (1 << eFormPropertyIDBit),
  eHasFormPropertyID = (1 << eFormRangeBit), eHasFormName = (1 << eFormNameBit), eStandardKeyFormSupport = (eHasFormAbsolutePosition | eHasFormRelativePosition | eHasFormRange | eHasFormName)
}
typedef UInt32 ItemRef
typedef UInt32 ItemID

Public Member Functions

 AEWordIterator ()
virtual UInt32 GetNumItems (const AEDesc *containerToken)
virtual ItemRef GetIndexedItemReference (const AEDesc *containerToken, TAEListIndex itemIndex)
virtual TAEListIndex GetIndexFromItemID (const AEDesc *containerToken, ItemID itemID)
virtual ItemID GetIndexedItemID (const AEDesc *containerToken, TAEListIndex itemIndex)
virtual ItemID GetIDFromReference (const AEDesc *containerToken, ItemRef itemRef)
virtual ItemRef GetReferenceFromID (const AEDesc *containerToken, ItemID itemID)
virtual ItemID GetItemIDFromToken (const AEDesc *token)
virtual void SetItemIDInCoreToken (const AEDesc *containerToken, CoreTokenRecord *tokenRecord, ItemID itemID)
virtual void GetItemFromContainer (DescType desiredClass, const AEDesc *containerToken, DescType containerClass, DescType keyForm, const AEDesc *keyData, AEDesc *resultToken)

Protected Types

enum  {
  eFormAbsolutePositionBit = 0, eFormRelativePositionBit, eFormTestBit, eFormRangeBit,
  eFormPropertyIDBit, eFormNameBit
}

Protected Member Functions

virtual ItemRef GetNamedItemReference (const AEDesc *containerToken, const char *itemName)
virtual ItemID GetNamedItemID (const AEDesc *containerToken, const char *itemName)
virtual void GetIndexedItemName (const AEDesc *containerToken, TAEListIndex itemIndex, char *outName, long maxLen)
virtual ItemRef ProcessFormRelativePostition (const AEDesc *anchorToken, const AEDesc *keyData)
TAEListIndex NormalizeAbsoluteIndex (const AEDesc *keyData, TAEListIndex maxIndex, Boolean *isAllItems)
void ProcessFormRange (AEDesc *keyData, AEDesc *start, AEDesc *stop)
void CheckKeyFormSupport (DescType keyForm)
DescType GetClass ()

Protected Attributes

DescType mClass
UInt16 mKeyFormSupport

Static Protected Attributes

static const ItemRef kNoItemRef = -1
static const ItemID kNoItemID = -1

Detailed Description

Definition at line 84 of file nsAEWordClass.h.


Member Typedef Documentation

typedef UInt32 AEClassIterator::ItemID [inherited]

Definition at line 94 of file nsAEClassIterator.h.

typedef UInt32 AEClassIterator::ItemRef [inherited]

Definition at line 93 of file nsAEClassIterator.h.


Member Enumeration Documentation

anonymous enum [protected, inherited]
Enumerator:
eFormAbsolutePositionBit 
eFormRelativePositionBit 
eFormTestBit 
eFormRangeBit 
eFormPropertyIDBit 
eFormNameBit 

Definition at line 51 of file nsAEClassIterator.h.

anonymous enum [inherited]
Enumerator:
eHasFormAbsolutePosition 
eHasFormRelativePosition 
eHasFormTest 
eHasFormRange 
eHasFormPropertyID 
eHasFormName 
eStandardKeyFormSupport 

Definition at line 64 of file nsAEClassIterator.h.

anonymous enum [inherited]
Enumerator:
eNoNameKeyFormSupport 

Definition at line 186 of file nsAEClassIterator.h.


Constructor & Destructor Documentation

Definition at line 86 of file nsAEWordClass.h.


Member Function Documentation

void AEClassIterator::CheckKeyFormSupport ( DescType  keyForm) [protected, inherited]

Definition at line 368 of file nsAEClassIterator.cpp.

{
       UInt16               testMask;
       switch (keyForm)
       {
              case formAbsolutePosition:         testMask = eHasFormAbsolutePosition;             break;
              case formRelativePosition:         testMask = eHasFormRelativePosition;             break;
              case formTest:                                   testMask = eHasFormTest;                         break;
              case formRange:                           testMask = eHasFormRange;                        break;
              case formPropertyID:               testMask = eHasFormPropertyID;                   break;
              case formName:                            testMask = eHasFormName;                         break;
              default:
                     AE_ASSERT(false, "Unknown key form");
       }
       if ((mKeyFormSupport & testMask) == 0)
              ThrowOSErr(errAEBadKeyForm);
}

Here is the caller graph for this function:

DescType AEClassIterator::GetClass ( ) [inline, protected, inherited]

Definition at line 127 of file nsAEClassIterator.h.

{ return mClass; }

Here is the caller graph for this function:

AEClassIterator::ItemID AEWordIterator::GetIDFromReference ( const AEDesc *  containerToken,
ItemRef  itemRef 
) [virtual]

Implements AEClassIterator.

Definition at line 94 of file nsAEWordClass.cpp.

{
       return (ItemID)itemRef;
}
AEClassIterator::ItemID AEWordIterator::GetIndexedItemID ( const AEDesc *  containerToken,
TAEListIndex  itemIndex 
) [virtual]

Implements AEClassIterator.

Definition at line 85 of file nsAEWordClass.cpp.

{
       return (ItemID)GetIndexedItemReference(containerToken, itemIndex);
}

Here is the call graph for this function:

virtual void AEUnnamedClassIterator::GetIndexedItemName ( const AEDesc *  containerToken,
TAEListIndex  itemIndex,
char *  outName,
long  maxLen 
) [inline, protected, virtual, inherited]

Implements AEClassIterator.

Definition at line 202 of file nsAEClassIterator.h.

{ ThrowOSErr(errAEEventNotHandled); }
AEClassIterator::ItemRef AEWordIterator::GetIndexedItemReference ( const AEDesc *  containerToken,
TAEListIndex  itemIndex 
) [virtual]

Implements AEClassIterator.

Definition at line 67 of file nsAEWordClass.cpp.

{
       return (ItemRef)itemIndex;
}

Here is the caller graph for this function:

TAEListIndex AEWordIterator::GetIndexFromItemID ( const AEDesc *  containerToken,
ItemID  itemID 
) [virtual]

Implements AEClassIterator.

Definition at line 76 of file nsAEWordClass.cpp.

{
       return (TAEListIndex)itemID;
}
void AEClassIterator::GetItemFromContainer ( DescType  desiredClass,
const AEDesc *  containerToken,
DescType  containerClass,
DescType  keyForm,
const AEDesc *  keyData,
AEDesc *  resultToken 
) [virtual, inherited]

Reimplemented in AENamedClassIterator.

Definition at line 53 of file nsAEClassIterator.cpp.

{
       OSErr                       err    = noErr;
       
       CStr255                            itemName;
       ItemRef                            itemRef = kNoItemRef;
       ItemID                      itemID = kNoItemID;
       DescType                           keyDataType   = keyData->descriptorType;

       Boolean                            wantsAllItems = false;

       StAEDesc                           startObject;  // These are used to resolve formRange
       StAEDesc                           stopObject;
              
       CoreTokenRecord             token;
       
       long                               numItems = GetNumItems(containerToken);
       TAEListIndex                itemIndex;
       
       CheckKeyFormSupport(keyForm);             // throws on error
       
       switch (keyForm)
       {
              case formName:                                                                                                                // item by name
                     if (DescToCString(keyData, itemName, 255) != noErr)
                            ThrowIfOSErr(errAECoercionFail);

                     itemRef = GetNamedItemReference(containerToken, itemName);
                     if (itemRef == kNoItemRef)
                            ThrowIfOSErr(errAENoSuchObject);
                     break;
              
              case formAbsolutePosition:                                                                                             // item by number
                     itemIndex = NormalizeAbsoluteIndex(keyData, numItems, &wantsAllItems);
                     if (wantsAllItems == false)
                     {
                            if (itemIndex == 0 || itemIndex > numItems)
                                   ThrowOSErr(errAEIllegalIndex);
                     }
                     itemRef = GetIndexedItemReference(containerToken, itemIndex);
                     if (itemRef == kNoItemRef)
                            ThrowOSErr(errAENoSuchObject);
                     break; 
              
              case formRelativePosition:
                     itemRef = ProcessFormRelativePostition(containerToken, keyData);
                     break; 
              
              case formRange:
                     switch (keyDataType)
                     {             
                            case typeRangeDescriptor:
                                   {
                                          ProcessFormRange((AEDesc *)keyData, &startObject, &stopObject);
                                          
                                          ConstAETokenDesc     startToken(&startObject);
                                          ConstAETokenDesc     stopToken(&stopObject);
                                          DescType             startType = startToken.GetDispatchClass();
                                          DescType             stopType  = stopToken.GetDispatchClass();
        
                                          if (startType != mClass || stopType != mClass)
                                                 ThrowOSErr(errAEWrongDataType);
                                   }
                                   break;

                            default:
                                   ThrowOSErr(errAEWrongDataType);
                                   break; 
                     }
                     break; 
              
              default:
                     ThrowIfOSErr(errAEEventNotHandled);
       }
       
       // if user asked for all items, and there aren't any,
       // we'll be kind and return an empty list.

       if (wantsAllItems && (err == errAENoSuchObject || err == errAEIllegalIndex))
       {
              err = AECreateList(nil, 0, false, (AEDescList*)resultToken);
              ThrowIfOSErr(err);
              return;
       }

       ThrowIfOSErr(err);

       // fill in the result token
       token.dispatchClass  = GetClass();
       token.objectClass    = GetClass();
       token.propertyCode   = typeNull;
       
       if (wantsAllItems)
       {
              err = AECreateList(NULL, 0, false, (AEDescList*)resultToken);
              ThrowIfOSErr(err);
              
              for (TAEListIndex index = 1; index <= numItems; index++)
              {
                     ItemID        itemID = GetIndexedItemID(containerToken, index);
                     if (itemID != kNoItemID)
                     {
                            SetItemIDInCoreToken(containerToken, &token, itemID);
                            err = AEPutPtr(resultToken, 0, desiredClass, &token, sizeof(token));
                            ThrowIfOSErr(err);
                     }
              }
       }
       else if (keyForm == formRange)
       {
              ConstAETokenDesc            startToken(&startObject);
              ConstAETokenDesc            stopToken(&stopObject);
              
              ItemID               beginItemID   = GetItemIDFromToken(&startObject);
              ItemID               endItemID            = GetItemIDFromToken(&stopObject);
              
              TAEListIndex         beginIndex           = GetIndexFromItemID(containerToken, beginItemID);
              TAEListIndex         endIndex             = GetIndexFromItemID(containerToken, endItemID);
                                                                      
              err = AECreateList(nil, 0, false, (AEDescList*)resultToken);
              ThrowIfOSErr(err);
                     
              if (beginIndex > endIndex) // swap elements
              {
                     TAEListIndex  temp = beginIndex;
                     beginIndex           = endIndex;
                     endIndex      = temp;
              }
              
              for (TAEListIndex i = beginIndex; i <= endIndex; i ++)
              {
                     ItemID        itemID = GetIndexedItemID(containerToken, i);
                     if (itemID != kNoItemID)
                     {
                            SetItemIDInCoreToken(containerToken, &token, itemID);
                            err = AEPutPtr(resultToken, 0, desiredClass, &token, sizeof(token));
                            ThrowIfOSErr(err);
                     }
              }
       }
       else
       {
              SetItemIDInCoreToken(containerToken, &token, GetIDFromReference(containerToken, itemRef));
              err = AECreateDesc(desiredClass, &token, sizeof(token), resultToken);
              ThrowIfOSErr(err);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements AEClassIterator.

Definition at line 112 of file nsAEWordClass.cpp.

{
       AETokenDesc   container(token);
       return (ItemID)container.GetElementNumber();
}

Here is the call graph for this function:

virtual ItemID AEUnnamedClassIterator::GetNamedItemID ( const AEDesc *  containerToken,
const char *  itemName 
) [inline, protected, virtual, inherited]

Implements AEClassIterator.

Definition at line 201 of file nsAEClassIterator.h.

{ ThrowOSErr(errAEEventNotHandled); return 0; }
virtual ItemRef AEUnnamedClassIterator::GetNamedItemReference ( const AEDesc *  containerToken,
const char *  itemName 
) [inline, protected, virtual, inherited]

Implements AEClassIterator.

Definition at line 200 of file nsAEClassIterator.h.

{ ThrowOSErr(errAEEventNotHandled); return 0; }
UInt32 AEWordIterator::GetNumItems ( const AEDesc *  containerToken) [virtual]

Implements AEClassIterator.

Definition at line 55 of file nsAEWordClass.cpp.

{
       AETokenDesc   container(containerToken);
       WEReference   theWE = container.GetWEReference();

       return theWE ? GetWENumWords(theWE) : 0;
}

Here is the caller graph for this function:

AEClassIterator::ItemRef AEWordIterator::GetReferenceFromID ( const AEDesc *  containerToken,
ItemID  itemID 
) [virtual]

Implements AEClassIterator.

Definition at line 103 of file nsAEWordClass.cpp.

{
       return (ItemRef)itemID;
}
TAEListIndex AEClassIterator::NormalizeAbsoluteIndex ( const AEDesc *  keyData,
TAEListIndex  maxIndex,
Boolean isAllItems 
) [protected, inherited]

Definition at line 268 of file nsAEClassIterator.cpp.

{
       TAEListIndex  index;
       *isAllItems = false;                                                  // set to true if we receive kAEAll constant
       
       // Extract the formAbsolutePosition data, either a integer or a literal constant
       
       switch (keyData->descriptorType)
       {
              case typeLongInteger:                                          // positve or negative index
                     if (DescToLong(keyData, &index) != noErr)
                            ThrowOSErr(errAECoercionFail);
                            
                     if (index < 0)                                                 // convert a negative index from end of list to a positive index from beginning of list
                            index = maxIndex + index + 1;
                     break;
                     
          case typeAbsoluteOrdinal:                                                                      // 'abso'
                     DescType             ordinalDesc;
                     if (DescToDescType((AEDesc*)keyData, &ordinalDesc) != noErr)
                            ThrowOSErr(errAECoercionFail);
                     
                     switch (ordinalDesc)
                     {
                            case kAEFirst:
                                   index = 1;
                                   break;
                                   
                            case kAEMiddle:
                                   index = (maxIndex >> 1) + (maxIndex % 2);
                                   break;
                                          
                            case kAELast:
                                   index = maxIndex;
                                   break;
                                          
                            case kAEAny:
                                   index = (TickCount() % maxIndex) + 1;            // poor man's random
                                   break;
                                          
                            case kAEAll:
                                   index = 1;
                                   *isAllItems = true;
                                   break;
                     }
                     break;

              default:
                     ThrowOSErr(errAEWrongDataType);
       }

       // range-check the new index number
       if ((index < 1) || (index > maxIndex))
              ThrowOSErr(errAEIllegalIndex);
              
       return index;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AEClassIterator::ProcessFormRange ( AEDesc *  keyData,
AEDesc *  start,
AEDesc *  stop 
) [protected, inherited]

Definition at line 333 of file nsAEClassIterator.cpp.

{
       OSErr         err = noErr;
       StAEDesc             rangeRecord;
       StAEDesc             ospec;
       
       // coerce the range record data into an AERecord 
       
       err = AECoerceDesc(keyData, typeAERecord, &rangeRecord);
       ThrowIfOSErr(err);
        
       // object specifier for first object in the range
       err = AEGetKeyDesc(&rangeRecord, keyAERangeStart, typeWildCard, &ospec);
       if (err == noErr && ospec.descriptorType == typeObjectSpecifier)
              err = AEResolve(&ospec, kAEIDoMinimum, start);
              
       ThrowIfOSErr(err);
              
       ospec.Clear();
              
       // object specifier for last object in the range
       
       err = AEGetKeyDesc(&rangeRecord, keyAERangeStop, typeWildCard, &ospec);
       if (err == noErr && ospec.descriptorType == typeObjectSpecifier)
              err = AEResolve(&ospec, kAEIDoMinimum, stop);

       ThrowIfOSErr(err);
}

Here is the call graph for this function:

Here is the caller graph for this function:

AEClassIterator::ItemRef AEClassIterator::ProcessFormRelativePostition ( const AEDesc *  anchorToken,
const AEDesc *  keyData 
) [protected, virtual, inherited]

Definition at line 212 of file nsAEClassIterator.cpp.

{
       OSErr         err = noErr;
       ItemID        anchorItemID = GetItemIDFromToken(anchorToken);
       TAEListIndex  anchorListIndex = GetIndexFromItemID(anchorToken, anchorItemID);
       TAEListIndex  wantedListIndex = 0;
       long                 numItems = GetNumItems(anchorToken);
       ItemRef              returnRef = kNoItemRef;

       if (anchorListIndex != 0)
       {
              switch (keyData->descriptorType)
              {
                 case typeEnumerated:
                            DescType             positionEnum; 
                            if (DescToDescType((AEDesc*)keyData, &positionEnum) != noErr)
                                   ThrowIfOSErr(errAECoercionFail);

                            switch (positionEnum)
                            {
                                   case kAENext:                                    // get the window behind the anchor
                                          wantedListIndex = anchorListIndex + 1;
                                          if (wantedListIndex > numItems)
                                                 err = errAENoSuchObject;
                                          break;
                                          
                                   case kAEPrevious:                                // get the document in front of the anchor
                                          wantedListIndex = anchorListIndex - 1;
                                          if (wantedListIndex < 1)
                                                 err = errAENoSuchObject;
                                          break;
                                          
                                   default:
                                          err = errAEEventNotHandled;
                                          break;
                            }
                            ThrowIfOSErr(err);
                            break;
                            
                     default:
                            err = errAECoercionFail;
                            break;
              }
       }
       
       ThrowIfOSErr(err);
       return GetIndexedItemReference(anchorToken, wantedListIndex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AEWordIterator::SetItemIDInCoreToken ( const AEDesc *  containerToken,
CoreTokenRecord tokenRecord,
ItemID  itemID 
) [virtual]

Implements AEClassIterator.

Definition at line 122 of file nsAEWordClass.cpp.

{
       AETokenDesc          tokenDesc(containerToken);
       WindowPtr            wind = tokenDesc.GetWindowPtr();
       WEReference          theWE = tokenDesc.GetWEReference();

       tokenRecord->window = wind;
       tokenRecord->theWE = theWE;
       
       tokenRecord->elementNumber = (TAEListIndex)itemID;
}

Here is the call graph for this function:


Member Data Documentation

const AEClassIterator::ItemID AEClassIterator::kNoItemID = -1 [static, protected, inherited]

Definition at line 99 of file nsAEClassIterator.h.

const AEClassIterator::ItemRef AEClassIterator::kNoItemRef = -1 [static, protected, inherited]

Definition at line 98 of file nsAEClassIterator.h.

DescType AEClassIterator::mClass [protected, inherited]

Definition at line 130 of file nsAEClassIterator.h.

UInt16 AEClassIterator::mKeyFormSupport [protected, inherited]

Definition at line 131 of file nsAEClassIterator.h.


The documentation for this class was generated from the following files: