home *** CD-ROM | disk | FTP | other *** search
- /*
- * CustomIO_Lib.c
- *
- * Demo/Template for writing custom IO functions
- *
- * Custom Attribute example
- */
- #include "QD3D.h"
- #include "QD3DSet.h"
-
- #include "QD3DIO.h"
-
- #include "CustomIO_Lib.h"
-
- /*
- * Globals
- */
- static TQ3ObjectClass gCustomAttributeClass;
-
- /*
- * Static Functions
- */
-
- static TQ3Status CustomAttribute_Traverse(
- TQ3Object unused,
- CustomAttributeRecord *customAttribute,
- TQ3ViewObject view)
- {
- (void) unused;
-
- if (customAttribute->clickModel == NULL)
- return kQ3Success;
-
- if (Q3View_SubmitWriteData(
- view, sizeof(TQ3Uns32), customAttribute, NULL) == kQ3Failure)
- {
- return kQ3Failure;
- }
-
- if (Q3Object_Submit(customAttribute->clickModel, view) == kQ3Failure)
- return kQ3Failure;
-
- return kQ3Success;
- }
-
- static TQ3Status CustomAttribute_Write(
- CustomAttributeRecord *customAttribute,
- TQ3FileObject file)
- {
- return
- Q3Uns32_Write((TQ3Uns32) customAttribute->isOn, file) == kQ3Success &&
- Q3Comment_Write("isOn", file) == kQ3Success ? kQ3Success : kQ3Failure;
- }
-
- static TQ3Status CustomAttribute_ReadData(
- TQ3AttributeSet attributeSet,
- TQ3FileObject file)
- {
- CustomAttributeRecord customAttribute;
- TQ3Status status;
-
- if (Q3Uns32_Read((TQ3Uns32 *) &customAttribute.isOn, file) == kQ3Failure)
- return kQ3Failure;
-
- customAttribute.clickModel = NULL;
-
- while (Q3File_IsEndOfContainer(file, NULL) == kQ3False)
- {
- customAttribute.clickModel = Q3File_ReadObject(file);
-
- if (customAttribute.clickModel == NULL)
- return kQ3Failure;
-
- if (Q3Object_IsType(customAttribute.clickModel, kQ3GroupTypeDisplay))
- break;
-
- Q3Object_Dispose(customAttribute.clickModel);
- customAttribute.clickModel = NULL;
- }
-
- status = Q3Set_Add(attributeSet, kCustomAttributeType, &customAttribute);
-
- if (customAttribute.clickModel)
- Q3Object_Dispose(customAttribute.clickModel);
-
- return status;
- }
-
- static TQ3Status CustomAttribute_CopyAdd(
- CustomAttributeRecord *src,
- CustomAttributeRecord *dst)
- {
- *dst = *src;
- if (dst->clickModel != NULL)
- Q3Shared_GetReference(dst->clickModel);
-
- return kQ3Success;
- }
-
- static TQ3Status CustomAttribute_CopyReplace(
- CustomAttributeRecord *src,
- CustomAttributeRecord *dst)
- {
- if (src->clickModel != NULL)
- Q3Shared_GetReference(src->clickModel);
- if (dst->clickModel != NULL)
- Q3Object_Dispose(dst->clickModel);
-
- *dst = *src;
-
- return kQ3Success;
- }
-
- static TQ3Status CustomAttribute_Delete(
- CustomAttributeRecord *src)
- {
- if (src->clickModel != NULL)
- Q3Object_Dispose(src->clickModel);
- return kQ3Success;
- }
-
- TQ3Status CustomAttribute_Unregister(
- void)
- {
- if ( gCustomAttributeClass != NULL )
- return Q3ObjectClass_Unregister(gCustomAttributeClass);
-
- return kQ3Failure;
- }
-
- /*
- * CustomAttribute_MetaHandler
- */
- static TQ3FunctionPointer CustomAttribute_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) CustomAttribute_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) CustomAttribute_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) CustomAttribute_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) CustomAttribute_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) CustomAttribute_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) CustomAttribute_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * CustomAttribute_Register
- */
- TQ3Status CustomAttribute_Register(
- void)
- {
- gCustomAttributeClass =
- Q3ElementClass_Register(
- kCustomAttributeType,
- "CustomAttribute",
- sizeof(CustomAttributeRecord),
- CustomAttribute_MetaHandler);
-
- return (gCustomAttributeClass == NULL ? kQ3Failure : kQ3Success);
- }
-