home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Unsupported Libraries / CustomIO_Lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-31  |  3.7 KB  |  173 lines  |  [TEXT/MPS ]

  1. /*
  2.  * CustomIO_Lib.c
  3.  *
  4.  *    Demo/Template for writing custom IO functions
  5.  *    
  6.  *    Custom Attribute example
  7.  */
  8. #include "QD3D.h"
  9. #include "QD3DSet.h"
  10.  
  11. #include "QD3DIO.h"
  12.  
  13. #include "CustomIO_Lib.h"
  14.  
  15. /*
  16.  * Globals
  17.  */
  18. static TQ3ObjectClass gCustomAttributeClass;
  19.  
  20. /*
  21.  * Static Functions
  22.  */
  23.  
  24. static TQ3Status CustomAttribute_Traverse(
  25.     TQ3Object                unused,
  26.     CustomAttributeRecord    *customAttribute,
  27.     TQ3ViewObject            view)
  28. {
  29.     (void) unused;
  30.     
  31.     if (customAttribute->clickModel == NULL)
  32.         return kQ3Success;
  33.  
  34.     if (Q3View_SubmitWriteData(
  35.         view, sizeof(TQ3Uns32), customAttribute, NULL) == kQ3Failure)
  36.     {
  37.         return kQ3Failure;
  38.     }
  39.  
  40.     if (Q3Object_Submit(customAttribute->clickModel, view) == kQ3Failure)
  41.         return kQ3Failure;
  42.  
  43.     return kQ3Success;
  44. }
  45.  
  46. static TQ3Status CustomAttribute_Write(
  47.     CustomAttributeRecord    *customAttribute,
  48.     TQ3FileObject            file)
  49. {
  50.     return 
  51.         Q3Uns32_Write((TQ3Uns32) customAttribute->isOn, file) == kQ3Success &&
  52.         Q3Comment_Write("isOn", file) == kQ3Success ? kQ3Success : kQ3Failure;
  53. }
  54.  
  55. static TQ3Status CustomAttribute_ReadData(
  56.     TQ3AttributeSet            attributeSet,
  57.     TQ3FileObject            file)
  58. {
  59.     CustomAttributeRecord    customAttribute;
  60.     TQ3Status                status;
  61.     
  62.     if (Q3Uns32_Read((TQ3Uns32 *) &customAttribute.isOn, file) == kQ3Failure)
  63.         return kQ3Failure;
  64.  
  65.     customAttribute.clickModel = NULL;
  66.  
  67.     while (Q3File_IsEndOfContainer(file, NULL) == kQ3False)
  68.     {
  69.         customAttribute.clickModel = Q3File_ReadObject(file);
  70.  
  71.         if (customAttribute.clickModel == NULL)
  72.             return kQ3Failure;
  73.  
  74.         if (Q3Object_IsType(customAttribute.clickModel, kQ3GroupTypeDisplay))
  75.             break;
  76.         
  77.         Q3Object_Dispose(customAttribute.clickModel);
  78.         customAttribute.clickModel = NULL;
  79.     }
  80.         
  81.     status = Q3Set_Add(attributeSet, kCustomAttributeType, &customAttribute);
  82.  
  83.     if (customAttribute.clickModel)
  84.         Q3Object_Dispose(customAttribute.clickModel);
  85.  
  86.     return status;
  87. }
  88.  
  89. static TQ3Status CustomAttribute_CopyAdd(
  90.     CustomAttributeRecord    *src,
  91.     CustomAttributeRecord    *dst)
  92. {
  93.     *dst = *src;
  94.     if (dst->clickModel != NULL) 
  95.         Q3Shared_GetReference(dst->clickModel);
  96.     
  97.     return kQ3Success;
  98. }
  99.  
  100. static TQ3Status CustomAttribute_CopyReplace(
  101.     CustomAttributeRecord    *src,
  102.     CustomAttributeRecord    *dst)
  103. {
  104.     if (src->clickModel != NULL)
  105.         Q3Shared_GetReference(src->clickModel);
  106.     if (dst->clickModel != NULL) 
  107.         Q3Object_Dispose(dst->clickModel);
  108.  
  109.     *dst = *src;
  110.  
  111.     return kQ3Success;
  112. }
  113.  
  114. static TQ3Status CustomAttribute_Delete(
  115.     CustomAttributeRecord    *src)
  116. {
  117.     if (src->clickModel != NULL) 
  118.         Q3Object_Dispose(src->clickModel);
  119.     return kQ3Success;
  120. }
  121.  
  122. TQ3Status CustomAttribute_Unregister(
  123.     void)
  124. {
  125.     if ( gCustomAttributeClass != NULL )
  126.         return    Q3ObjectClass_Unregister(gCustomAttributeClass);
  127.         
  128.     return kQ3Failure;
  129. }
  130.  
  131. /*
  132.  * CustomAttribute_MetaHandler
  133.  */
  134. static TQ3FunctionPointer CustomAttribute_MetaHandler(
  135.     TQ3MethodType        methodType)
  136. {
  137.     switch (methodType)
  138.     {
  139.         case kQ3MethodTypeObjectTraverse:
  140.             return (TQ3FunctionPointer) CustomAttribute_Traverse;
  141.         case kQ3MethodTypeObjectWrite:
  142.             return (TQ3FunctionPointer) CustomAttribute_Write;
  143.         case kQ3MethodTypeObjectReadData:
  144.             return (TQ3FunctionPointer) CustomAttribute_ReadData;
  145.         case kQ3MethodTypeElementCopyAdd:
  146.         case kQ3MethodTypeElementCopyGet:
  147.         case kQ3MethodTypeElementCopyDuplicate:
  148.             return (TQ3FunctionPointer) CustomAttribute_CopyAdd;
  149.         case kQ3MethodTypeElementCopyReplace:
  150.             return (TQ3FunctionPointer) CustomAttribute_CopyReplace;
  151.         case kQ3MethodTypeElementDelete:
  152.             return (TQ3FunctionPointer) CustomAttribute_Delete;
  153.         default:
  154.             return (TQ3FunctionPointer) NULL;
  155.     }
  156. }
  157.  
  158. /*
  159.  * CustomAttribute_Register
  160.  */
  161. TQ3Status CustomAttribute_Register(
  162.     void)
  163. {
  164.     gCustomAttributeClass = 
  165.         Q3ElementClass_Register(
  166.             kCustomAttributeType,
  167.             "CustomAttribute",
  168.             sizeof(CustomAttributeRecord),
  169.             CustomAttribute_MetaHandler);
  170.  
  171.     return (gCustomAttributeClass == NULL ? kQ3Failure : kQ3Success);
  172. }
  173.