Back to index

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

#include <nsAEClassIterator.h>

Inheritance diagram for AEClassIterator:
Inheritance graph
[legend]

List of all members.

Public Types

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

 AEClassIterator (DescType classType, UInt16 keyFormSupport=eStandardKeyFormSupport)
virtual ~AEClassIterator ()
virtual void GetItemFromContainer (DescType desiredClass, const AEDesc *containerToken, DescType containerClass, DescType keyForm, const AEDesc *keyData, AEDesc *resultToken)
virtual UInt32 GetNumItems (const AEDesc *containerToken)=0

Protected Types

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

Protected Member Functions

virtual ItemRef GetNamedItemReference (const AEDesc *containerToken, const char *itemName)=0
virtual ItemRef GetIndexedItemReference (const AEDesc *containerToken, TAEListIndex itemIndex)=0
virtual TAEListIndex GetIndexFromItemID (const AEDesc *containerToken, ItemID itemID)=0
virtual ItemID GetNamedItemID (const AEDesc *containerToken, const char *itemName)=0
virtual ItemID GetIndexedItemID (const AEDesc *containerToken, TAEListIndex itemIndex)=0
virtual void GetIndexedItemName (const AEDesc *containerToken, TAEListIndex itemIndex, char *outName, long maxLen)=0
virtual ItemID GetIDFromReference (const AEDesc *containerToken, ItemRef itemRef)=0
virtual ItemRef GetReferenceFromID (const AEDesc *containerToken, ItemID itemID)=0
virtual ItemID GetItemIDFromToken (const AEDesc *token)=0
virtual void SetItemIDInCoreToken (const AEDesc *containerToken, CoreTokenRecord *tokenRecord, ItemID itemID)=0
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 46 of file nsAEClassIterator.h.


Member Typedef Documentation

Definition at line 94 of file nsAEClassIterator.h.

Definition at line 93 of file nsAEClassIterator.h.


Member Enumeration Documentation

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

Definition at line 51 of file nsAEClassIterator.h.

anonymous enum
Enumerator:
eHasFormAbsolutePosition 
eHasFormRelativePosition 
eHasFormTest 
eHasFormRange 
eHasFormPropertyID 
eHasFormName 
eStandardKeyFormSupport 

Definition at line 64 of file nsAEClassIterator.h.


Constructor & Destructor Documentation

AEClassIterator::AEClassIterator ( DescType  classType,
UInt16  keyFormSupport = eStandardKeyFormSupport 
) [inline]

Definition at line 77 of file nsAEClassIterator.h.

                                          :      mClass(classType)
                                          ,      mKeyFormSupport(keyFormSupport)
                                          {}
virtual AEClassIterator::~AEClassIterator ( ) [inline, virtual]

Definition at line 82 of file nsAEClassIterator.h.

{}

Member Function Documentation

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

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]

Definition at line 127 of file nsAEClassIterator.h.

{ return mClass; }

Here is the caller graph for this function:

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

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual ItemID AEClassIterator::GetIndexedItemID ( const AEDesc *  containerToken,
TAEListIndex  itemIndex 
) [protected, pure virtual]

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual void AEClassIterator::GetIndexedItemName ( const AEDesc *  containerToken,
TAEListIndex  itemIndex,
char *  outName,
long  maxLen 
) [protected, pure virtual]
virtual ItemRef AEClassIterator::GetIndexedItemReference ( const AEDesc *  containerToken,
TAEListIndex  itemIndex 
) [protected, pure virtual]

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual TAEListIndex AEClassIterator::GetIndexFromItemID ( const AEDesc *  containerToken,
ItemID  itemID 
) [protected, pure virtual]

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

void AEClassIterator::GetItemFromContainer ( DescType  desiredClass,
const AEDesc *  containerToken,
DescType  containerClass,
DescType  keyForm,
const AEDesc *  keyData,
AEDesc *  resultToken 
) [virtual]

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:

virtual ItemID AEClassIterator::GetItemIDFromToken ( const AEDesc *  token) [protected, pure virtual]

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual ItemID AEClassIterator::GetNamedItemID ( const AEDesc *  containerToken,
const char *  itemName 
) [protected, pure virtual]
virtual ItemRef AEClassIterator::GetNamedItemReference ( const AEDesc *  containerToken,
const char *  itemName 
) [protected, pure virtual]

Implemented in AEUnnamedClassIterator, AENamedClassIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual UInt32 AEClassIterator::GetNumItems ( const AEDesc *  containerToken) [pure virtual]

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:

virtual ItemRef AEClassIterator::GetReferenceFromID ( const AEDesc *  containerToken,
ItemID  itemID 
) [protected, pure virtual]
TAEListIndex AEClassIterator::NormalizeAbsoluteIndex ( const AEDesc *  keyData,
TAEListIndex  maxIndex,
Boolean isAllItems 
) [protected]

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]

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]

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:

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

Implemented in AENamedClassIterator, AEWordIterator, and AEWindowIterator.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 99 of file nsAEClassIterator.h.

Definition at line 98 of file nsAEClassIterator.h.

DescType AEClassIterator::mClass [protected]

Definition at line 130 of file nsAEClassIterator.h.

Definition at line 131 of file nsAEClassIterator.h.


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