Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
src/dpgIO.c
/****************************************************************************** |
** ** |
** Module: dpgIO.c ** |
** ** |
** ** |
** ** |
** ** |
** ** |
** Copyright (C) 1995-1996 Apple Computer, Inc. All rights reserved. ** |
** ** |
** ** |
*****************************************************************************/ |
#include "dpg.h" |
#include "dpgIO.h" |
#include "dpgMemory.h" |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyDistanceList_Read() |
* |
* Comments: |
* |
\*===========================================================================*/ |
static TQ3Status exDistanceProxyDistanceList_Read( |
TQ3GroupObject group, |
TQ3FileObject file) |
{ |
unsigned long flag; |
float distance; |
unsigned long i, cnt; |
TQ3DistanceProxyDisplayGroupPrivate *gPriv; |
gPriv = DPG_GETPRIVATE(group); |
if (Q3Uns32_Read(&cnt, file) == kQ3Failure) |
return kQ3Failure; |
for (i=0, gPriv->distIOTblCnt = 0; i < cnt; i++) |
{ |
if (Q3Uns32_Read(&flag, file) == kQ3Failure) |
return kQ3Failure; |
if (Q3Float32_Read(&distance, file) == kQ3Failure) |
return kQ3Failure; |
if (flag == kQ3True) { |
gPriv->distIOTbl = dpgRealloc( |
gPriv->distIOTbl, |
sizeof(TQ3DistanceIOData) * (gPriv->distIOTblCnt+1)); |
if (!gPriv->distIOTbl) |
{ |
gPriv->distIOTblCnt = 0; |
dpgFree(gPriv->distIOTbl); |
gPriv->distIOTbl = 0; |
return kQ3Failure; |
} |
gPriv->distIOTbl[gPriv->distIOTblCnt].distance = distance; |
gPriv->distIOTbl[gPriv->distIOTblCnt].index = i; |
gPriv->distIOTblCnt++; |
} |
} |
return kQ3Success; |
} |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyDistanceList_Traverse() |
* |
* Comments: |
* |
\*===========================================================================*/ |
static unsigned long exDistanceProxyDistanceList_Traverse( |
TQ3GroupObject group) |
{ |
TQ3DistanceProxyDisplayGroupPrivate *gPriv; |
unsigned long size = 0; |
gPriv = DPG_GETPRIVATE(group); |
Q3Group_CountObjects(group, &size); |
size = 4 /* unsigned long */ + |
(size * (4 /* boolean */ + 4 /* float */)); |
return size; |
} |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyDistanceList_Write() |
* |
* Comments: |
* |
\*===========================================================================*/ |
static TQ3Status exDistanceProxyDistanceList_Write( |
TQ3GroupObject group, |
TQ3FileObject file) |
{ |
TQ3DistanceProxyDisplayGroupPrivate *gPriv; |
TQ3GroupPosition position; |
unsigned long cnt; |
gPriv = DPG_GETPRIVATE(group); |
if (Q3Comment_Write("Distance Pair", file) == kQ3Failure) |
return kQ3Failure; |
Q3Group_CountObjects(group, &cnt); |
if ((Q3Uns32_Write(cnt, file) == kQ3Failure) || |
(Q3Comment_Write("Count", file) == kQ3Failure)) |
return kQ3Failure; |
for (Q3Group_GetFirstPosition(group, &position); position != NULL;) |
{ |
float distance; |
unsigned long flag; |
flag = (unsigned long)exDistanceProxyGroup_GetDistanceAtPosition(group, position, &distance); |
if ((Q3Uns32_Write(flag, file) == kQ3Failure) || |
(Q3Float32_Write(distance, file) == kQ3Failure) || |
(Q3NewLine_Write(file) == kQ3Failure)) |
return kQ3Failure; |
Q3Group_GetNextPosition(group, &position); |
} |
return kQ3Success; |
} |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyGroup_Read() |
* |
* Comments: |
* |
\*===========================================================================*/ |
TQ3GroupObject exDistanceProxyGroup_Read( |
TQ3FileObject file) |
{ |
TQ3Point3D refPt; |
unsigned long flags; |
TQ3GroupObject group; |
/* XXX EiFileReadState_BeginGroup(file); */ |
if ((Q3Point3D_Read(&refPt, file) == kQ3Failure) || |
(Q3Uns32_Read(&flags, file) == kQ3Failure)) |
return NULL; |
group = exDistanceProxyGroup_New(&refPt, flags); |
if (group == NULL) |
return NULL; |
if (exDistanceProxyDistanceList_Read(group, file) == kQ3Failure) |
{ |
Q3Object_Dispose(group); |
group = NULL; |
} |
return group; |
} |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyGroup_Traverse() |
* |
* Comments: |
* |
\*===========================================================================*/ |
TQ3Status exDistanceProxyGroup_Traverse( |
TQ3GroupObject group, |
void *unused, |
TQ3ViewObject view) |
{ |
unsigned long size; |
unused; /* Unused */ |
/* |
TQ3Point3D refPt = (float * 3) = 12 |
unsigned long flags = 4 |
total size = 16 |
*/ |
size = 16 + exDistanceProxyDistanceList_Traverse(group); |
if (Q3XView_SubmitWriteData(view, size, group, NULL) == kQ3Failure) |
return kQ3Failure; |
//if (EiView_TraverseObjectClass(view, EgDisplayGroupStateClass, group) == kQ3Failure) |
// return kQ3Failure; |
return kQ3Success; |
} |
/*===========================================================================*\ |
* |
* Routine: exDistanceProxyGroup_Write() |
* |
* Comments: |
* |
\*===========================================================================*/ |
TQ3Status exDistanceProxyGroup_Write( |
TQ3GroupObject group, |
TQ3FileObject file) |
{ |
TQ3DistanceProxyDisplayGroupPrivate *gPriv; |
unsigned long size = 0; |
gPriv = DPG_GETPRIVATE(group); |
if ((Q3NewLine_Write(file) == kQ3Failure) || |
(Q3Point3D_Write(&gPriv->refPt, file) == kQ3Failure) || |
(Q3Comment_Write("reference point", file) == kQ3Failure) || |
(Q3Uns32_Write(gPriv->flag, file) == kQ3Failure) || |
(Q3Comment_Write("flag", file) == kQ3Failure) || |
(exDistanceProxyDistanceList_Write(group, file) == kQ3Failure)) |
return kQ3Failure; |
return kQ3Success; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14