home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.9 KB | 288 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDesc.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWDESC_H
- #define FWDESC_H
-
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- #ifndef FWRUNTYP_H
- #include "FWRunTyp.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODDesc_h
- #include "ODDesc.xh"
- #endif
-
- const ODDescType keyNoKey = 'noKy';
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- class FW_CDesc;
- class FW_CColor;
- class FW_CString;
- class ODObjectSpec;
- class ODOSLToken;
- class ODAddressDesc;
- class FW_CPoint;
- class FW_CRect;
-
- //========================================================================================
- // class FW_CDesc
- //========================================================================================
-
- class FW_CDesc
- {
- public:
- FW_DECLARE_AUTO(FW_CDesc)
-
- //----------------------------------------------------------------------------------------
- // Initialization/Destruction
- //
- FW_CDesc();
- FW_CDesc(const FW_CDesc& copyDesc);
- FW_CDesc(ODDesc* odDesc);
-
- virtual ~FW_CDesc();
-
- void Clear();
-
- void CoerceInPlace(ODDescType toType);
- void Coerce(ODDescType toType, FW_CDesc& coerceDesc) const;
-
- void CreateSimple(ODDescType dataType, const void* dataPtr, Size dataSize);
- void CreateList(void* commonDataPtr = NULL, Size commonDataSize = 0);
- void CreateRecord(void* commonDataPtr = NULL, Size commonDataSize = 0);
-
- //----------------------------------------------------------------------------------------
- // Data ownership
- //
- FW_Boolean OwnsODData() const {return fOwnODDesc;}
- void SetOwnsODData(FW_Boolean ownsODData) {fOwnODDesc = ownsODData;}
-
- //----------------------------------------------------------------------------------------
- // Direct access
- //
- ODDescType DescriptorType() const;
- void SetDescriptorType(ODDescType newType);
-
- FW_PlatformHandle PlatformDataHandle() const;
-
- inline FW_Boolean IsNullDescriptor() const { return DescriptorType() == typeNull; }
- inline FW_Boolean IsList() const { return DescriptorType() == typeAEList || IsRecord(); }
- inline FW_Boolean IsRecord() const { return DescriptorType() == typeAERecord || IsAppleEvent(); }
- inline FW_Boolean IsAppleEvent() const { return DescriptorType() == typeAppleEvent; }
-
- void GetDataByPtr(ODDescType dataType,
- void* dataPtr,
- Size* dataSize,
- Size maxSize,
- AEKeyword key = keyNoKey) const;
-
-
- void PutDataByPtr(ODDescType dataType,
- const void* dataPtr,
- Size dataSize,
- AEKeyword key = keyNoKey);
-
- void GetDataByDesc(FW_CDesc& desc, AEKeyword key, ODDescType desiredType = typeWildCard) const;
- void PutDataByDesc(const FW_CDesc& desc, AEKeyword key = keyNoKey);
-
- //----------------------------------------------------------------------------------------
- // List and record access
- //
- long GetItemCount() const;
-
- void GetDescFromList(long index, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
- void GetDescFromList(long index, AEKeyword& descKey, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
-
- void PutDescIntoList(const FW_CDesc& desc, long index = 0);
-
- FW_Boolean HasDataKey(AEKeyword key) const;
-
- void GetDataInfoByKey(AEKeyword key, ODDescType& typeCode, Size& dataSize) const;
-
- void DeleteItemByIndex(long index);
- void DeleteItemByKey(ODDescType key);
-
- //----------------------------------------------------------------------------------------
- // Type-Specific Access
- //
- ODDescType GetEnumeratedType(AEKeyword key = keyNoKey) const;
- void PutEnumeratedType(ODDescType value, AEKeyword = keyNoKey);
-
- ODDescType GetAbsoluteOrdinal(AEKeyword key = keyNoKey) const;
- void PutAbsoluteOrdinal(ODDescType value, AEKeyword = keyNoKey);
-
- ODDescType GetType(AEKeyword key = keyNoKey) const;
- void PutType(ODDescType value, AEKeyword = keyNoKey);
-
- FW_Boolean GetBoolean(AEKeyword key = keyNoKey) const;
- void PutBoolean(FW_Boolean value, AEKeyword = keyNoKey);
-
- long GetLongInteger(AEKeyword key = keyNoKey) const;
- void PutLongInteger(long value, AEKeyword = keyNoKey);
-
- short GetShortInteger(AEKeyword key = keyNoKey) const;
- void PutShortInteger(short value, AEKeyword = keyNoKey);
-
- void GetString(FW_CString& string, AEKeyword key = keyNoKey) const;
- void PutString(const FW_CString& string, AEKeyword key = keyNoKey);
-
- void GetColor(FW_CColor& color, AEKeyword key = keyNoKey) const;
- void PutColor(const FW_CColor& color, AEKeyword key = keyNoKey);
-
- void GetPoint(FW_CPoint& point, AEKeyword = keyNoKey) const;
- void PutPoint(const FW_CPoint& thePoint, AEKeyword key = keyNoKey);
-
- void GetRect(FW_CRect& rect, AEKeyword = keyNoKey) const;
- void PutRect(const FW_CRect& rect, AEKeyword = keyNoKey);
-
- //----------------------------------------------------------------------------------------
- // Comparison
- //
-
- FW_Boolean Compare(ODDescType operation, const FW_CDesc& other) const;
-
- //----------------------------------------------------------------------------------------
- // operators
- //
-
- FW_CDesc& operator= (const FW_CDesc& desc);
-
- operator const AEDesc&() const;
- operator AEDesc*() const;
- operator const AEDesc*() const;
-
- operator ODDesc*() const;
- operator ODObjectSpec*() const;
- operator ODOSLToken*() const;
- operator ODAddressDesc*() const;
- operator ODAddressDesc**();
-
- inline FW_Boolean HasODDesc() const { return fODDesc != NULL; }
-
-
- //----------------------------------------------------------------------------------------
- // Private synchronization methods
- //
-
- protected:
-
- FW_Boolean PrivCompareLists(ODDescType operation,
- const FW_CDesc& lhDesc,
- const FW_CDesc& rhDesc) const;
-
- FW_Boolean PrivCompareLongs(ODDescType operation,
- long lhs,
- long rhs) const;
-
- FW_Boolean PrivCompareStrings(ODDescType operation,
- const FW_CString& lhs,
- const FW_CString& rhs) const;
-
- FW_Boolean PrivCompareColors(ODDescType operation,
- const FW_CColor& lhs,
- const FW_CColor& rhs) const;
-
- FW_Boolean PrivCompareData(ODDescType operation,
- const FW_CDesc& lhDesc,
- const FW_CDesc& rhDesc) const;
-
- inline AEDesc* PrivGetPlatformDescPtr() const { return (AEDesc*)&fPlatformDesc; }
- inline ODDesc* PrivGetODDescPtr() const { return fODDesc; }
- inline ODDesc** PrivGetODDescHandle() { return &fODDesc; }
-
- inline void PrivUpdatePlatformDescIfStale() const;
- inline void PrivUpdateODDescIfStale() const;
-
- inline void PrivPlatformDescChanged() const;
- inline void PrivODDescChanged() const;
-
- enum FW_DescDataState { FW_kPlatformMatchesOD, FW_kSynchronizing, FW_kPlatformDataIsStale, FW_kODDataIsStale };
-
- void PrivUpdatePlatformDesc() const;
- void PrivUpdateODDesc() const;
-
- virtual ODDesc* PrivCreateODDesc(Environment* ev) const;
-
- void PrivFlushData();
- void PrivFlushPlatformData() const;
- void PrivFlushODData() const;
-
- void PrivDispose();
-
- private:
- FW_Boolean fOwnODDesc;
-
- FW_Boolean fRealPlatformDesc; // true if the platform descriptor was created
- // by a call to the AppleEvent Manager.
- // false if the platform descriptor was created
- // by copying the ODDesc. this is necessary
- // for compatibility with MacOS 8 where some
- // AEDescs (at least AppleEvents) contain ptrs
- // to secondary buffers that are also disposed
- // when AEDisposeDesc is called. This resulted
- // in a dangling pointer in the original AEDesc
- // from which the ODDesc, and later our platform
- // desc derived.
- AEDesc fPlatformDesc; // mutable - allocated lazily
- ODDesc* fODDesc; // mutable - allocated lazily
-
- FW_DescDataState fDataState; // mutable
-
- ODDescType fODDescType; // mutable - cached eagerly
- FW_Boolean fODDescTypeValid; // mutable
- };
-
- inline void FW_CDesc::PrivPlatformDescChanged() const
- {
- FW_ASSERT(fDataState != FW_kPlatformDataIsStale);
- // cast away const. data state is mutable
- ((FW_CDesc*)this)->fDataState = FW_kODDataIsStale;
- }
-
- inline void FW_CDesc::PrivODDescChanged() const
- {
- FW_ASSERT(fDataState != FW_kODDataIsStale);
- // cast away const. data state is mutable
- ((FW_CDesc*)this)->fDataState = FW_kPlatformDataIsStale;
- ((FW_CDesc*)this)->fODDescTypeValid = FALSE;
- }
-
-
- inline void FW_CDesc::PrivUpdatePlatformDescIfStale() const
- {
- if (fDataState == FW_kPlatformDataIsStale)
- PrivUpdatePlatformDesc();
- }
-
- inline void FW_CDesc::PrivUpdateODDescIfStale() const
- {
- if (fDataState == FW_kODDataIsStale)
- PrivUpdateODDesc();
- }
-
- #endif // FWDESC_H
-