home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / FWDesc.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.9 KB  |  288 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDesc.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWDESC_H
  11. #define FWDESC_H
  12.  
  13.  
  14. #ifndef FWSTDDEF_H
  15. #include "FWStdDef.h"
  16. #endif
  17.  
  18. #ifndef FWEXCEPT_H
  19. #include "FWExcept.h"
  20. #endif
  21.  
  22. #ifndef FWRUNTYP_H
  23. #include "FWRunTyp.h"
  24. #endif
  25.  
  26. #ifndef FWDEBUG_H
  27. #include "FWDebug.h"
  28. #endif
  29.  
  30. // ----- OpenDoc Includes -----
  31.  
  32. #ifndef SOM_ODDesc_h
  33. #include "ODDesc.xh"
  34. #endif
  35.  
  36. const ODDescType keyNoKey = 'noKy';
  37.  
  38. //========================================================================================
  39. //    Forward Declarations
  40. //========================================================================================
  41.  
  42. class FW_CDesc;
  43. class FW_CColor;
  44. class FW_CString;
  45. class ODObjectSpec;
  46. class ODOSLToken;
  47. class ODAddressDesc;
  48. class FW_CPoint;
  49. class FW_CRect;
  50.  
  51. //========================================================================================
  52. //    class FW_CDesc
  53. //========================================================================================
  54.  
  55. class FW_CDesc
  56. {
  57. public:
  58.     FW_DECLARE_AUTO(FW_CDesc)
  59.     
  60. //----------------------------------------------------------------------------------------
  61. //    Initialization/Destruction
  62. //
  63.     FW_CDesc();
  64.     FW_CDesc(const FW_CDesc& copyDesc);
  65.     FW_CDesc(ODDesc* odDesc);
  66.     
  67.     virtual ~FW_CDesc();
  68.     
  69.     void     Clear();
  70.     
  71.     void    CoerceInPlace(ODDescType toType);
  72.     void    Coerce(ODDescType toType, FW_CDesc& coerceDesc) const;
  73.  
  74.     void    CreateSimple(ODDescType dataType, const void* dataPtr, Size dataSize);
  75.     void    CreateList(void* commonDataPtr = NULL, Size commonDataSize = 0);
  76.     void    CreateRecord(void* commonDataPtr = NULL, Size commonDataSize = 0);
  77.     
  78. //----------------------------------------------------------------------------------------
  79. //    Data ownership
  80. //    
  81.     FW_Boolean     OwnsODData() const {return fOwnODDesc;}
  82.     void        SetOwnsODData(FW_Boolean ownsODData) {fOwnODDesc = ownsODData;}
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    Direct access
  86. //
  87.     ODDescType         DescriptorType() const;
  88.     void              SetDescriptorType(ODDescType newType);
  89.     
  90.     FW_PlatformHandle PlatformDataHandle() const;
  91.     
  92.     inline FW_Boolean IsNullDescriptor() const    { return DescriptorType() == typeNull; }
  93.     inline FW_Boolean IsList() const            { return DescriptorType() == typeAEList || IsRecord(); }
  94.     inline FW_Boolean IsRecord() const            { return DescriptorType() == typeAERecord || IsAppleEvent(); }
  95.     inline FW_Boolean IsAppleEvent() const        { return DescriptorType() == typeAppleEvent; }
  96.     
  97.     void             GetDataByPtr(ODDescType dataType, 
  98.                             void* dataPtr, 
  99.                             Size* dataSize, 
  100.                             Size maxSize, 
  101.                             AEKeyword key = keyNoKey) const;
  102.                     
  103.  
  104.     void            PutDataByPtr(ODDescType dataType, 
  105.                                 const void* dataPtr, 
  106.                                 Size dataSize,
  107.                                 AEKeyword key = keyNoKey);
  108.     
  109.     void             GetDataByDesc(FW_CDesc& desc, AEKeyword key, ODDescType desiredType = typeWildCard) const;
  110.     void             PutDataByDesc(const FW_CDesc& desc, AEKeyword key = keyNoKey);
  111.     
  112. //----------------------------------------------------------------------------------------
  113. //    List and record access
  114. //
  115.     long             GetItemCount() const;
  116.     
  117.     void             GetDescFromList(long index, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
  118.     void             GetDescFromList(long index, AEKeyword& descKey, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
  119.  
  120.     void             PutDescIntoList(const FW_CDesc& desc, long index = 0);
  121.             
  122.     FW_Boolean         HasDataKey(AEKeyword key) const;
  123.     
  124.     void             GetDataInfoByKey(AEKeyword key, ODDescType& typeCode, Size& dataSize) const;
  125.     
  126.     void             DeleteItemByIndex(long index);
  127.     void             DeleteItemByKey(ODDescType key);
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    Type-Specific Access
  131. //
  132.     ODDescType        GetEnumeratedType(AEKeyword key = keyNoKey) const;
  133.     void            PutEnumeratedType(ODDescType value, AEKeyword = keyNoKey);
  134.  
  135.     ODDescType        GetAbsoluteOrdinal(AEKeyword key = keyNoKey) const;
  136.     void            PutAbsoluteOrdinal(ODDescType value, AEKeyword = keyNoKey);
  137.  
  138.     ODDescType        GetType(AEKeyword key = keyNoKey) const;
  139.     void            PutType(ODDescType value, AEKeyword = keyNoKey);
  140.  
  141.     FW_Boolean        GetBoolean(AEKeyword key = keyNoKey) const;
  142.     void            PutBoolean(FW_Boolean value, AEKeyword = keyNoKey);
  143.  
  144.     long            GetLongInteger(AEKeyword key = keyNoKey) const;
  145.     void            PutLongInteger(long value, AEKeyword = keyNoKey);
  146.  
  147.     short            GetShortInteger(AEKeyword key = keyNoKey) const;
  148.     void            PutShortInteger(short value, AEKeyword = keyNoKey);
  149.  
  150.     void            GetString(FW_CString& string, AEKeyword key = keyNoKey) const;
  151.     void            PutString(const FW_CString& string, AEKeyword key = keyNoKey);
  152.     
  153.     void            GetColor(FW_CColor& color, AEKeyword key = keyNoKey) const;
  154.     void            PutColor(const FW_CColor& color, AEKeyword key = keyNoKey);
  155.     
  156.     void             GetPoint(FW_CPoint& point, AEKeyword = keyNoKey) const;
  157.     void            PutPoint(const FW_CPoint& thePoint, AEKeyword key = keyNoKey);
  158.     
  159.     void            GetRect(FW_CRect& rect, AEKeyword = keyNoKey) const;
  160.     void            PutRect(const FW_CRect& rect, AEKeyword = keyNoKey);
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    Comparison
  164. //
  165.  
  166.     FW_Boolean        Compare(ODDescType operation, const FW_CDesc& other) const;
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    operators
  170. //
  171.     
  172.     FW_CDesc& operator= (const FW_CDesc& desc);
  173.         
  174.     operator const AEDesc&() const;
  175.     operator AEDesc*() const;
  176.     operator const AEDesc*() const;
  177.     
  178.     operator ODDesc*() const;
  179.     operator ODObjectSpec*() const;
  180.     operator ODOSLToken*() const;
  181.     operator ODAddressDesc*() const;
  182.     operator ODAddressDesc**();
  183.     
  184.     inline FW_Boolean HasODDesc() const { return fODDesc != NULL; }
  185.     
  186.     
  187. //----------------------------------------------------------------------------------------
  188. //    Private synchronization methods
  189. //
  190.  
  191. protected:
  192.     
  193.     FW_Boolean        PrivCompareLists(ODDescType operation,
  194.                                     const FW_CDesc& lhDesc,
  195.                                     const FW_CDesc& rhDesc) const;
  196.                                     
  197.     FW_Boolean        PrivCompareLongs(ODDescType operation, 
  198.                                     long lhs, 
  199.                                     long rhs) const;
  200.                                     
  201.     FW_Boolean        PrivCompareStrings(ODDescType operation, 
  202.                                     const FW_CString& lhs, 
  203.                                     const FW_CString& rhs) const;
  204.  
  205.     FW_Boolean        PrivCompareColors(ODDescType operation,
  206.                                     const FW_CColor& lhs,
  207.                                     const FW_CColor& rhs) const;
  208.                                     
  209.     FW_Boolean        PrivCompareData(ODDescType operation,
  210.                                     const FW_CDesc& lhDesc,
  211.                                     const FW_CDesc& rhDesc) const;
  212.  
  213.     inline AEDesc*     PrivGetPlatformDescPtr() const { return (AEDesc*)&fPlatformDesc; }
  214.     inline ODDesc*    PrivGetODDescPtr() const { return fODDesc; }
  215.     inline ODDesc** PrivGetODDescHandle() { return &fODDesc; }
  216.         
  217.     inline void     PrivUpdatePlatformDescIfStale() const;
  218.     inline void     PrivUpdateODDescIfStale() const;
  219.     
  220.     inline void     PrivPlatformDescChanged() const;
  221.     inline void     PrivODDescChanged() const;
  222.  
  223.     enum FW_DescDataState { FW_kPlatformMatchesOD, FW_kSynchronizing, FW_kPlatformDataIsStale, FW_kODDataIsStale };
  224.  
  225.     void             PrivUpdatePlatformDesc() const;
  226.     void             PrivUpdateODDesc() const;
  227.     
  228.     virtual ODDesc* PrivCreateODDesc(Environment* ev) const;
  229.     
  230.     void            PrivFlushData();
  231.     void            PrivFlushPlatformData() const;
  232.     void            PrivFlushODData() const;
  233.     
  234.     void             PrivDispose();
  235.         
  236. private:
  237.     FW_Boolean            fOwnODDesc;
  238.     
  239.     FW_Boolean            fRealPlatformDesc;    // true if the platform descriptor was created
  240.                                             // by a call to the AppleEvent Manager.
  241.                                             // false if the platform descriptor was created
  242.                                             // by copying the ODDesc. this is necessary
  243.                                             // for compatibility with MacOS 8 where some
  244.                                             // AEDescs (at least AppleEvents) contain ptrs
  245.                                             // to secondary buffers that are also disposed
  246.                                             // when AEDisposeDesc is called. This resulted
  247.                                             // in a dangling pointer in the original AEDesc
  248.                                             // from which the ODDesc, and later our platform
  249.                                             // desc derived.
  250.     AEDesc                fPlatformDesc;        // mutable - allocated lazily
  251.     ODDesc*             fODDesc;            // mutable - allocated lazily
  252.  
  253.     FW_DescDataState    fDataState;            // mutable
  254.     
  255.     ODDescType            fODDescType;        // mutable - cached eagerly
  256.     FW_Boolean            fODDescTypeValid;    // mutable
  257. };
  258.  
  259. inline void FW_CDesc::PrivPlatformDescChanged() const
  260. {
  261.     FW_ASSERT(fDataState != FW_kPlatformDataIsStale);
  262.         // cast away const. data state is mutable
  263.     ((FW_CDesc*)this)->fDataState = FW_kODDataIsStale;
  264. }
  265.  
  266. inline void FW_CDesc::PrivODDescChanged() const
  267. {
  268.     FW_ASSERT(fDataState != FW_kODDataIsStale);
  269.         // cast away const. data state is mutable
  270.     ((FW_CDesc*)this)->fDataState = FW_kPlatformDataIsStale;
  271.     ((FW_CDesc*)this)->fODDescTypeValid = FALSE;
  272. }
  273.  
  274.  
  275. inline void FW_CDesc::PrivUpdatePlatformDescIfStale() const
  276. {
  277.     if (fDataState == FW_kPlatformDataIsStale)
  278.         PrivUpdatePlatformDesc();
  279. }
  280.  
  281. inline void FW_CDesc::PrivUpdateODDescIfStale() const
  282. {
  283.     if (fDataState == FW_kODDataIsStale)
  284.         PrivUpdateODDesc();
  285. }
  286.  
  287. #endif // FWDESC_H
  288.