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 / Found / ODUtils / Unused / ODDesUtl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-16  |  2.9 KB  |  132 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODDesUtl.cpp
  3.  
  4.     Contains:    Implementation of ODDesc<->AEDesc conversion utilities
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11. */
  12.  
  13. #ifndef _ODDEBUG_
  14. #include "ODDebug.h"
  15. #endif
  16.  
  17. #ifndef _ODMEMORY_
  18. #include <ODMemory.h>
  19. #endif
  20.  
  21. #ifndef _EXCEPT_
  22. #include "Except.h"
  23. #endif
  24.  
  25. #ifndef _ODDESUTL_
  26. #include <ODDesUtl.h>
  27. #endif
  28.  
  29. #ifndef SOM_ODDesc_xh
  30. #include "ODDesc.xh"
  31. #endif
  32.  
  33. #ifndef _BARRAY_
  34. #include "BArray.h"
  35. #endif
  36.  
  37. #ifndef SOMCorba_h
  38. #include "somcorba.h"
  39. #endif
  40.  
  41.  
  42. //------------------------------------------------------------------------------
  43. // ODDescToAEDesc
  44. //------------------------------------------------------------------------------
  45.  
  46. ODError ODDescToAEDesc(ODDesc* odDesc, AEDesc* aeDesc)
  47. {
  48. //    *aeDesc = *(odDesc->GetAEDesc(somGetGlobalEnvironment()));
  49. //    return noErr;
  50.     ODError            error = noErr;
  51.     Environment*    ev = somGetGlobalEnvironment();
  52.     ODDescType        descType = odDesc->GetDescType(ev);
  53.     const DescType    randomDescType = 'nick';
  54.  
  55.     TRY
  56.         ODByteArray    data;
  57.  
  58.         if (descType == typeNull)
  59.         {
  60.             aeDesc->dataHandle = kODNULL;
  61.             aeDesc->descriptorType = typeNull;
  62.         }
  63.         else
  64.         {
  65.             data = odDesc->GetRawData(ev);
  66.             // CAREFUL HERE! IF YOU CALL AECreateDesc USING typeAEList OR
  67.             //    typeAERecord, IT WILL STICK A HEADER ON THE DESCRIPTOR FOR YOU.
  68.             //    THAT'S NOT WHAT YOU WANT IN THIS CASE BECAUSE THE ODDESC ALREADY
  69.             //    CONTAINS ALL THE RAW DATA INCLUDING THE HEADER. WORK AROUND
  70.             //    BY CREATING DESCRIPTOR WITH RANDOM TYPE AND SETTING THE DescType
  71.             //    AFTERWORDS.
  72.             THROW_IF_ERROR(AECreateDesc(randomDescType,
  73.                                         data._buffer, data._length, aeDesc));
  74.             aeDesc->descriptorType = odDesc->GetDescType(ev);
  75.             DisposeByteArrayStruct(data);
  76.         }
  77.     CATCH_ALL
  78.         error = ErrorCode();
  79.     ENDTRY
  80.     
  81.     return error;
  82. }
  83.  
  84. //------------------------------------------------------------------------------
  85. // AEDescToODDesc
  86. //------------------------------------------------------------------------------
  87.  
  88. ODError AEDescToODDesc(AEDesc* aeDesc, ODDesc* odDesc)
  89. {
  90. //    odDesc->SetAEDesc(somGetGlobalEnvironment(), aeDesc);
  91.     ODError            error = noErr;
  92.     Environment*    ev = somGetGlobalEnvironment();
  93.     Handle            dataHandle = aeDesc->dataHandle;
  94.     ODDescType        descType = aeDesc->descriptorType;
  95.  
  96. //    if (dataHandle == kODNULL && descType != typeNull)
  97. //        THROW(kODErrUndefined);
  98.     
  99.     TRY
  100.         ODByteArray        data;
  101.         unsigned long    dataSize;
  102.  
  103.         if (dataHandle != kODNULL)
  104.         {
  105.             dataSize = ODGetHandleSize(dataHandle);
  106.             data._buffer = (octet*)ODNewPtr(dataSize);
  107.             ODBlockMove(*(dataHandle), data._buffer, dataSize);
  108.             data._length = dataSize;
  109.             data._maximum = dataSize;
  110.     
  111.             odDesc->SetRawData(ev, &data);
  112.  
  113.             DisposeByteArrayStruct(data);
  114.         }
  115.         odDesc->SetDescType(ev, descType);
  116.  
  117.     CATCH_ALL
  118.         error = ErrorCode();
  119.     ENDTRY
  120.     
  121.     return error;
  122. }
  123. #if 0
  124. ODError AEDescChanged(AEDesc* aeDesc, ODDesc* odDesc)
  125. {
  126. //    AEDesc* desc = odDesc->GetAEDesc(somGetGlobalEnvironment());
  127. //    WASSERT( desc );
  128. //    *desc = *aeDesc;
  129.     return noErr;
  130. }
  131. #endif /* 0 */
  132.