home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / Include / FWDesc.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.3 KB  |  276 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDesc.h
  4. //    Release Version:    $ ODF 1 $
  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 FWENVDEF_H
  15. #include "FWEnvDef.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. const ODDescType typeODFSemanticObject = 'FWob';
  39. const ODDescType typeODFSemObjCollection = 'FWsc';
  40. const ODDescType typeODFPropertyDesignator = 'FWpd';
  41.  
  42. //========================================================================================
  43. //    Forward Declarations
  44. //========================================================================================
  45.  
  46. class FW_CDesc;
  47. class FW_CColor;
  48. class FW_CString;
  49. class ODObjectSpec;
  50. class ODOSLToken;
  51. class ODAddressDesc;
  52.  
  53. //========================================================================================
  54. //    class FW_CDesc
  55. //========================================================================================
  56.  
  57. class FW_CDesc
  58. {
  59. public:
  60.     FW_DECLARE_AUTO(FW_CDesc)
  61.     
  62. //----------------------------------------------------------------------------------------
  63. //    Initialization/Destruction
  64. //
  65.     FW_CDesc();
  66.     FW_CDesc(const FW_CDesc& copyDesc);
  67.     FW_CDesc(ODDesc* odDesc);
  68.     
  69.     virtual ~FW_CDesc();
  70.     
  71.     void     Clear();
  72.     
  73.     void    CoerceInPlace(ODDescType toType);
  74.     void    Coerce(ODDescType toType, FW_CDesc& coerceDesc) const;
  75.  
  76.     void    CreateSimple(ODDescType dataType, const void* dataPtr, Size dataSize);
  77.     void    CreateList(void* commonDataPtr = NULL, Size commonDataSize = 0);
  78.     void    CreateRecord(void* commonDataPtr = NULL, Size commonDataSize = 0);
  79.     
  80. //----------------------------------------------------------------------------------------
  81. //    Data ownership
  82. //    
  83.     FW_Boolean     OwnsODData() const {return fOwnODDesc;}
  84.     void        SetOwnsODData(FW_Boolean ownsODData) {fOwnODDesc = ownsODData;}
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    Direct access
  88. //
  89.     ODDescType         DescriptorType() const;
  90.     void              SetDescriptorType(ODDescType newType);
  91.     
  92.     FW_PlatformHandle PlatformDataHandle() const;
  93.     
  94.     inline FW_Boolean IsNullDescriptor() const    { return DescriptorType() == typeNull; }
  95.     inline FW_Boolean IsList() const            { return DescriptorType() == typeAEList || IsRecord(); }
  96.     inline FW_Boolean IsRecord() const            { return DescriptorType() == typeAERecord || IsAppleEvent(); }
  97.     inline FW_Boolean IsAppleEvent() const        { return DescriptorType() == typeAppleEvent; }
  98.     
  99.     void             GetDataByPtr(ODDescType dataType, 
  100.                             void* dataPtr, 
  101.                             Size& dataSize, 
  102.                             Size maxSize, 
  103.                             AEKeyword key = keyNoKey) const;
  104.                     
  105.  
  106.     void            PutDataByPtr(ODDescType dataType, 
  107.                                 const void* dataPtr, 
  108.                                 Size dataSize,
  109.                                 AEKeyword key = keyNoKey);
  110.     
  111.     void             GetDataByDesc(FW_CDesc& desc, AEKeyword key, ODDescType desiredType = typeWildCard) const;
  112.     void             PutDataByDesc(const FW_CDesc& desc, AEKeyword key = keyNoKey);
  113.     
  114. //----------------------------------------------------------------------------------------
  115. //    List and record access
  116. //
  117.     long             GetItemCount() const;
  118.     
  119.     void             GetDescFromList(long index, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
  120.     void             GetDescFromList(long index, AEKeyword& descKey, FW_CDesc& retrievedDesc, ODDescType desiredType = typeWildCard) const;
  121.  
  122.     void             PutDescIntoList(const FW_CDesc& desc, long index = 0);
  123.             
  124.     FW_Boolean         HasDataKey(AEKeyword key) const;
  125.     
  126.     void             GetDataInfoByKey(AEKeyword key, ODDescType& typeCode, Size& dataSize) const;
  127.     
  128.     void             DeleteListItem(long index);
  129.     void             DeleteListItem(ODDescType key);
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    Type-Specific Access
  133. //
  134.     ODDescType        GetEnumeratedType(AEKeyword key = keyNoKey) const;
  135.     void            PutEnumeratedType(ODDescType value, AEKeyword = keyNoKey);
  136.  
  137.     ODDescType        GetAbsoluteOrdinal(AEKeyword key = keyNoKey) const;
  138.     void            PutAbsoluteOrdinal(ODDescType value, AEKeyword = keyNoKey);
  139.  
  140.     ODDescType        GetType(AEKeyword key = keyNoKey) const;
  141.     void            PutType(ODDescType value, AEKeyword = keyNoKey);
  142.  
  143.     FW_Boolean        GetBoolean(AEKeyword key = keyNoKey) const;
  144.     void            PutBoolean(FW_Boolean value, AEKeyword = keyNoKey);
  145.  
  146.     long            GetLongInteger(AEKeyword key = keyNoKey) const;
  147.     void            PutLongInteger(long value, AEKeyword = keyNoKey);
  148.  
  149.     short            GetShortInteger(AEKeyword key = keyNoKey) const;
  150.     void            PutShortInteger(short value, AEKeyword = keyNoKey);
  151.  
  152.     void            GetString(FW_CString& string, AEKeyword key = keyNoKey) const;
  153.     void            PutString(const FW_CString& string, AEKeyword key = keyNoKey);
  154.     
  155.     void            GetColor(FW_CColor& color, AEKeyword key = keyNoKey) const;
  156.     void            PutColor(const FW_CColor& color, AEKeyword key = keyNoKey);
  157.     
  158.     FW_SPlatformPoint     GetPoint(AEKeyword = keyNoKey) const;
  159.     void                PutPoint(FW_SPlatformPoint thePoint, AEKeyword key = keyNoKey);
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    Comparison
  163. //
  164.  
  165.     FW_Boolean        Compare(ODDescType operation, const FW_CDesc& other) const;
  166.     
  167. //----------------------------------------------------------------------------------------
  168. //    operators
  169. //
  170.     
  171.     FW_CDesc& operator= (const FW_CDesc& desc);
  172.         
  173.     operator const AEDesc&() const;
  174.     operator AEDesc*() const;
  175.     operator const AEDesc*() const;
  176.     
  177.     operator ODDesc*() const;
  178.     operator ODObjectSpec*() const;
  179.     operator ODOSLToken*() const;
  180.     operator ODAddressDesc*() const;
  181.     operator ODAddressDesc**();
  182.     
  183.     inline FW_Boolean HasODDesc() const { return fODDesc != NULL; }
  184.     
  185.     
  186. //----------------------------------------------------------------------------------------
  187. //    Private synchronization methods
  188. //
  189.  
  190. protected:
  191.     
  192.     FW_Boolean        PrivCompareLists(ODDescType operation,
  193.                                     const FW_CDesc& lhDesc,
  194.                                     const FW_CDesc& rhDesc) const;
  195.                                     
  196.     FW_Boolean        PrivCompareLongs(ODDescType operation, 
  197.                                     long lhs, 
  198.                                     long rhs) const;
  199.                                     
  200.     FW_Boolean        PrivCompareStrings(ODDescType operation, 
  201.                                     const FW_CString& lhs, 
  202.                                     const FW_CString& rhs) const;
  203.  
  204.     FW_Boolean        PrivCompareColors(ODDescType operation,
  205.                                     const FW_CColor& lhs,
  206.                                     const FW_CColor& rhs) const;
  207.                                     
  208.     FW_Boolean        PrivCompareData(ODDescType operation,
  209.                                     const FW_CDesc& lhDesc,
  210.                                     const FW_CDesc& rhDesc) const;
  211.  
  212.     inline AEDesc*     PrivGetPlatformDescPtr() const { return (AEDesc*)&fPlatformDesc; }
  213.     inline ODDesc*    PrivGetODDescPtr() const { return fODDesc; }
  214.     inline ODDesc** PrivGetODDescHandle() { return &fODDesc; }
  215.         
  216.     inline void     PrivUpdatePlatformDescIfStale() const;
  217.     inline void     PrivUpdateODDescIfStale() const;
  218.     
  219.     inline void     PrivPlatformDescChanged() const;
  220.     inline void     PrivODDescChanged() const;
  221.  
  222.     enum FW_DescDataState { FW_kPlatformMatchesOD, FW_kSynchronizing, FW_kPlatformDataIsStale, FW_kODDataIsStale };
  223.  
  224.     void             PrivUpdatePlatformDesc() const;
  225.     void             PrivUpdateODDesc() const;
  226.     
  227.     virtual ODDesc* PrivCreateODDesc(Environment* ev) const;
  228.     
  229.     void            PrivFlushData();
  230.     void            PrivFlushPlatformData() const;
  231.     void            PrivFlushODData() const;
  232.     
  233.     void             PrivDispose();
  234.     
  235. private:
  236.     FW_Boolean            fOwnODDesc;
  237.     
  238.     AEDesc                fPlatformDesc;        // mutable - allocated lazily
  239.     ODDesc*             fODDesc;            // mutable - allocated lazily
  240.  
  241.     FW_DescDataState    fDataState;            // mutable
  242.     
  243.     ODDescType            fODDescType;        // mutable - cached eagerly
  244.     FW_Boolean            fODDescTypeValid;    // mutable
  245. };
  246.  
  247. inline void FW_CDesc::PrivPlatformDescChanged() const
  248. {
  249.     FW_ASSERT(fDataState != FW_kPlatformDataIsStale);
  250.         // cast away const. data state is mutable
  251.     ((FW_CDesc*)this)->fDataState = FW_kODDataIsStale;
  252. }
  253.  
  254. inline void FW_CDesc::PrivODDescChanged() const
  255. {
  256.     FW_ASSERT(fDataState != FW_kODDataIsStale);
  257.         // cast away const. data state is mutable
  258.     ((FW_CDesc*)this)->fDataState = FW_kPlatformDataIsStale;
  259.     ((FW_CDesc*)this)->fODDescTypeValid = FALSE;
  260. }
  261.  
  262.  
  263. inline void FW_CDesc::PrivUpdatePlatformDescIfStale() const
  264. {
  265.     if (fDataState == FW_kPlatformDataIsStale)
  266.         PrivUpdatePlatformDesc();
  267. }
  268.  
  269. inline void FW_CDesc::PrivUpdateODDescIfStale() const
  270. {
  271.     if (fDataState == FW_kODDataIsStale)
  272.         PrivUpdateODDesc();
  273. }
  274.  
  275. #endif // FWDESC_H
  276.