Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Protected Member Functions
AEComparisons Class Reference

#include <nsAECompare.h>

List of all members.

Static Public Member Functions

static Boolean CompareTexts (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareEnumeration (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareInteger (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareFixed (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareFloat (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareBoolean (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareRGBColor (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean ComparePoint (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean CompareRect (DescType oper, const AEDesc *desc1, const AEDesc *desc2)
static Boolean TryPrimitiveComparison (DescType comparisonOperator, const AEDesc *desc1, const AEDesc *desc2)

Static Protected Member Functions

static Boolean EqualRGB (RGBColor colorA, RGBColor colorB)

Detailed Description

Definition at line 41 of file nsAECompare.h.


Member Function Documentation

Boolean AEComparisons::CompareBoolean ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 339 of file nsAECompare.cpp.

{
       OSErr  err    = noErr;
       Boolean       result = false;
       
       Boolean       bool1  = ((**(char **)desc1->dataHandle) != 0);
       Boolean       bool2  = ((**(char **)desc2->dataHandle) != 0);
              
       if (oper == kAEEquals) 
              result = (bool1 == bool2);
       else
              ThrowOSErr(errAEBadTestKey);              // No other tests make sense

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareEnumeration ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 158 of file nsAECompare.cpp.

{
       OSErr         err    = noErr;
       Boolean              result = false;
       long                 lhs;
       long                 rhs;
       StAEDesc             charDesc;
       
       // Make each number is a long integer (in case it's a short integer or other integer type) 
       // before extracting the data */
       
       err = AECoerceDesc(desc1, typeChar, &charDesc);
       ThrowIfOSErr(err);

       lhs = **(long **)(charDesc.dataHandle);
       AEDisposeDesc(&charDesc);
       
       err = AECoerceDesc(desc2, typeChar, &charDesc);
       ThrowIfOSErr(err);

       rhs = **(long **)charDesc.dataHandle;
       AEDisposeDesc(&charDesc);
       
       switch (oper) 
       {
              case kAEEquals:
                     result = (lhs == rhs);      // equality is the only test that makes sense for enumerators
                     break;
              
              default:
                     ThrowOSErr(errAEBadTestKey);
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareFixed ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 250 of file nsAECompare.cpp.

{
       OSErr         err    = noErr;
       Boolean              result = false;
       Fixed         lhs;
       Fixed         rhs;
       
       err = DescToFixed(desc1, &lhs);
       ThrowIfOSErr(err);
              
       err = DescToFixed(desc2, &rhs);
       ThrowIfOSErr(err);
       
       switch (oper) 
       {
              case kAEEquals:
                     result = (lhs == rhs);
                     break;
              
              case kAELessThan:
                     result = (lhs < rhs);
                     break;
              
              case kAELessThanEquals:
                     result = (lhs <= rhs);
                     break;
              
              case kAEGreaterThan:
                     result = (lhs > rhs);
                     break;
              
                     case kAEGreaterThanEquals:
                     result = (lhs >= rhs);
                     break;
              
              default:
                     ThrowOSErr(errAEBadTestKey);
       }
       
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareFloat ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 294 of file nsAECompare.cpp.

{
       OSErr  err    = noErr;
       Boolean       result = false;
       float          lhs;
       float   rhs;
       
       err = DescToFloat(desc1, &lhs);
       ThrowIfOSErr(err);
              
       err = DescToFloat(desc2, &rhs);
       ThrowIfOSErr(err);
       
       switch (oper) 
       {
              case kAEEquals:
                     result = (lhs == rhs);
                     break;
              
              case kAELessThan:
                     result = (lhs < rhs);
                     break;
              
              case kAELessThanEquals:
                     result = (lhs <= rhs);
                     break;
              
              case kAEGreaterThan:
                     result = (lhs > rhs);
                     break;
              
                     case kAEGreaterThanEquals:
                     result = (lhs >= rhs);
                     break;
              
              default:
                     ThrowOSErr(errAEBadTestKey);
       }
       
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareInteger ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 196 of file nsAECompare.cpp.

{
       OSErr         err    = noErr;
       Boolean              result = false;
       long                 lhs;
       long                 rhs;
       StAEDesc             longDesc;
       
       // Make each number is a long integer (in case it's a short integer or other integer type) 
       // before extracting the data */
       
       err = AECoerceDesc(desc1, typeLongInteger, &longDesc);
       ThrowIfOSErr(err);

       lhs = **(long **)(longDesc.dataHandle);
       AEDisposeDesc(&longDesc);
       
       err = AECoerceDesc(desc2, typeLongInteger, &longDesc);
       ThrowIfOSErr(err);

       rhs = **(long **)longDesc.dataHandle;
       AEDisposeDesc(&longDesc);
       
       switch (oper) 
       {
              case kAEEquals:
                     result = (lhs == rhs);
                     break;
              
              case kAELessThan:
                     result = (lhs < rhs);
                     break;
              
              case kAELessThanEquals:
                     result = (lhs <= rhs);
                     break;
              
              case kAEGreaterThan:
                     result = (lhs > rhs);
                     break;
              
              case kAEGreaterThanEquals:
                     result = (lhs >= rhs);
                     break;
              
              default:
                     ThrowOSErr(errAEBadTestKey);
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::ComparePoint ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 381 of file nsAECompare.cpp.

{
       OSErr  err = noErr;
       Boolean       result = false;
       
       Point         lhs;
       Point         rhs;
       
       err = DescToPoint(desc1, &lhs);
       ThrowIfOSErr(err);
              
       err = DescToPoint(desc2, &rhs);
       ThrowIfOSErr(err);
              
       switch (oper)
       {
              case kAEEquals:
                     result = (lhs.h = rhs.h && lhs.v == rhs.v);
                     break;
                     
              case kAELessThan:
                     result = (lhs.h < rhs.h && lhs.v < rhs.v);
                     break;
              
              case kAELessThanEquals:
                     result = (lhs.h <= rhs.h && lhs.v <= rhs.v);
                     break;
              
              case kAEGreaterThan:
                     result = (lhs.h > rhs.h && lhs.v > rhs.v);
                     break;
              
              case kAEGreaterThanEquals:
                     result = (lhs.h >= rhs.h && lhs.v >= rhs.v);
                     break;
              
              default:
                     ThrowOSErr(errAEBadTestKey);              // No other tests make sense
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareRect ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 426 of file nsAECompare.cpp.

{
       OSErr  err = noErr;
       Boolean       result = false;
       Rect          lhs;
       Rect          rhs;
       
       err = DescToRect(desc1, &lhs);
       ThrowIfOSErr(err);
              
       err = DescToRect(desc2, &rhs);
       ThrowIfOSErr(err);
              
       switch (oper)
       {
              // compare size AND location
              case kAEEquals:      
                     result = ((lhs.top == rhs.top) && (lhs.left == rhs.left) && (lhs.bottom == rhs.bottom) && (lhs.right == rhs.right));
                     break;
                     
              // compare size only on the rest of the tests
              case kAELessThan:    
                     result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left)));
                     break;
              
              case kAELessThanEquals:
                     result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left)));
                     break;
              
              case kAEGreaterThan:
                     result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left)));
                     break;
              
              case kAEGreaterThanEquals:
                     result = (((lhs.bottom - lhs.top) < (rhs.bottom - rhs.top)) && ((lhs.right - lhs.left) < (lhs.right - rhs.left)));
                     break;
              
              case kAEContains:
                     // Note: two identical Rects contain each other, according to this test:
                     result = ((lhs.top <= rhs.top) && (lhs.left <= rhs.left) && (lhs.bottom >= rhs.bottom) && (lhs.right >= rhs.right));
                     break;
                     
              default:
                     ThrowOSErr(errAEBadTestKey);              // No other tests make sense
       }

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareRGBColor ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 357 of file nsAECompare.cpp.

{
       OSErr  err = noErr;
       Boolean       result = false;
       
       RGBColor lhs;
       RGBColor rhs;
       
       err = DescToRGBColor(desc1, &lhs);
       ThrowIfOSErr(err);
              
       err = DescToRGBColor(desc2, &rhs);
       ThrowIfOSErr(err);

       if (oper == kAEEquals) 
              result = EqualRGB(lhs, rhs);
       else
              ThrowOSErr(errAEBadTestKey);              // No other tests make sense

       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean AEComparisons::CompareTexts ( DescType  oper,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 48 of file nsAECompare.cpp.

{
       Boolean       result = false;
       
       short  compareResult;
       Handle  lhsHandle = 0, rhsHandle = 0;
       char   *lhs;
       char   *rhs;
       long          lhsSize;
       long          rhsSize;
       
       // FIXME:  this can leak lhsHandle if second conversion fails.
       if (DescToTextHandle(desc1, &lhsHandle) != noErr || DescToTextHandle(desc2, &rhsHandle) != noErr)
           goto fail;
       
       lhsSize = GetHandleSize(lhsHandle);
       HLock(lhsHandle);
       lhs = *(lhsHandle);
       
       rhsSize = GetHandleSize(rhsHandle);
       HLock(rhsHandle);
       rhs = *(rhsHandle);

       compareResult = ::CompareText(lhs, rhs, lhsSize, rhsSize, nil);

       switch (oper) 
       {
              case kAEEquals:
                     result = (compareResult == 0);
                     break;
              
              case kAELessThan:
                     result = (compareResult < 0);
                     break;
              
              case kAELessThanEquals:
                     result = (compareResult <= 0);
                     break;
              
              case kAEGreaterThan:
                     result = (compareResult > 0);
                     break;
              
              case kAEGreaterThanEquals:
                     result = (compareResult >= 0);
                     break;
              
              case kAEBeginsWith:
                     if (rhsSize > lhsSize)
                     {
                            result = false;
                     }
                     else
                     {
                            // compare only the number of characters in rhs
                            // begin comparing at the beginning of lhs
                            compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
                            result = (compareResult == 0);
                     }
                     break;
                     
              case kAEEndsWith:
                     if (rhsSize > lhsSize)
                     {
                            result = false;
                     }
                     else
                     {
                            // compare only the number of characters in rhs
                            // begin comparing rhsSize characters from the end of lhs
                            // start 
                            
                            lhs += (lhsSize - rhsSize);
                            compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
                            result = (compareResult == 0);
                     }
                     break;

              case kAEContains:
                     // Here I use an inefficient search strategy, but we're dealing with small amounts
                     // of text and by using CompareText(), we're doing the same style of comparison
                     // as in the other cases above.
                     
                     result = false;
                     while (lhsSize >= rhsSize)
                     {
                            compareResult = CompareText(lhs, rhs, rhsSize, rhsSize, nil);
                            if (compareResult == 0)
                            {
                                   result = true;
                                   break;
                            }
                            lhs++;
                            lhsSize--;
                     }
                     break;

              default:
                     ThrowOSErr(errAEBadTestKey);
       }

fail:
    if (lhsHandle) DisposeHandle(lhsHandle);
    if (rhsHandle) DisposeHandle(rhsHandle);
       
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Boolean AEComparisons::EqualRGB ( RGBColor  colorA,
RGBColor  colorB 
) [inline, static, protected]

Definition at line 58 of file nsAECompare.h.

       {
              return((colorA.red == colorB.red) && (colorA.green == colorB.green) && (colorA.blue == colorB.blue));
       }

Here is the caller graph for this function:

Boolean AEComparisons::TryPrimitiveComparison ( DescType  comparisonOperator,
const AEDesc *  desc1,
const AEDesc *  desc2 
) [static]

Definition at line 482 of file nsAECompare.cpp.

{
       Boolean       result = false;
       
       // This has to handle all the data types used in the application's
       // object model implementation.
       switch (desc1->descriptorType) 
       {
              case typeChar:
                     result = CompareTexts(comparisonOperator, desc1, desc2);
                     break;
              
              case typeShortInteger:             // also covers typeSMInt           'shor'
              case typeLongInteger:              // also covers typeInteger  'long'
              case typeMagnitude:                //                                        'magn'
                     result = CompareInteger(comparisonOperator, desc1, desc2);
                     break;

              case typeEnumerated:
                     result = CompareEnumeration(comparisonOperator, desc1, desc2);
                     break;
              
              case typeFixed:
                     result = CompareFixed(comparisonOperator, desc1, desc2);
                     break;

              case typeFloat:
                     result = CompareFloat(comparisonOperator, desc1, desc2);
                     break;
              
              case typeBoolean:
                     result = CompareBoolean(comparisonOperator, desc1, desc2);
                     break;
                            
              case typeRGBColor:
                     result = CompareRGBColor(comparisonOperator, desc1, desc2);
                     break;
                            
              case typeQDRectangle:
                     result = CompareRect(comparisonOperator, desc1, desc2);
                     break;
                            
              case typeQDPoint:
                     result = ComparePoint(comparisonOperator, desc1, desc2);
                     break;
                            
              default:
                     ThrowOSErr(errAEWrongDataType);
       }

       return result;
}

Here is the call graph for this function:


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