ftp.nice.ch/pub/next/science/mathematics/HippoDraw.2.0.s.tar.gz#/HippoDraw/Hippo.bproj/HTuple.m

This is HTuple.m in view mode; [Download] [Up]

/* HTuple.m	by Paul Kunz	December 1991
 * Object used to store information on open Hippo Tuple and methods
 * to archive it to NXTypedStream.
 *
 * $Id: HTuple.m,v 2.9 1993/07/26 21:49:09 pfkeb Exp $
 *
 * Copyright (C)  1991  The Board of Trustees of
 * The Leland Stanford Junior University.  All Rights Reserved.
 */ 
 
#import <appkit/appkit.h>

#import "HTuple.h"

#import "HAddColFunction.h"


#define INDEX_VERSION 1
#define FUNCTION_VERSION 2
#define CURRENT_VERSION FUNCTION_VERSION

@implementation HTuple

+ initialize
{
    [self setVersion:CURRENT_VERSION];
    return self;
}

- initTuple:(ntuple) nt file:(const char *)path
         by:(BOOL)refFlag mode:(BOOL) binFlag index:(int) iValue
{
    [super init];
    tuple = nt;
    isRef = refFlag;
    isBinary = binFlag;
    if ( filename == NULL ) {
        NX_ZONEMALLOC( [self zone], filename, char, strlen(path)+1 );
    } else {
        NX_ZONEREALLOC( [self zone], filename, char, strlen(path)+1 );
    }
    strcpy( filename, path );
    [self setFakeFilename:NO];
    ntindex = iValue;
    return self;
}
- (ntuple) ntuple
{
    return tuple;
}
- setNtuple:(ntuple) aTuple;
{
    tuple = aTuple;
    return self;
}
- (BOOL) isRef
{
    return isRef;
}
- setIsRef:(BOOL) refFlag
{
    isRef = refFlag;
    return self;
}
- setIsBinary:(BOOL) binFlag
{
    isBinary = binFlag;
    return self;
}
- (const char *)filename
{
    return filename;
}
- setFilename:(const char *)path
{
    if ( filename == NULL ) {
        NX_ZONEMALLOC( [self zone], filename, char, strlen(path)+1 );
    } else {
        NX_ZONEREALLOC( [self zone], filename, char, strlen(path)+1 );
    }
    strcpy( filename, path );
    return self;
}
- (int) index
{
    return ntindex;
}
- setIndex:(int) value
{
    ntindex = value;
    return self;
}
- setAltFilename:(const char *)path
{
    if ( altfilename == NULL ) {
        NX_ZONEMALLOC( [self zone], altfilename, char, strlen(path)+1 );
    } else {
        NX_ZONEREALLOC( [self zone], altfilename, char, strlen(path)+1 );
    }
    strcpy( altfilename, path );
    return self;
}
- (const char *)altfilename
{
    return altfilename;
}
- (BOOL) isFakeFilename
{
    return fakeFilename;
}
- setFakeFilename:(BOOL) bValue
{
    fakeFilename = bValue;
    return self;
}
- (BOOL) isSameTupleAs:aTuple
{
    if ( strcmp( filename, [aTuple filename] ) ) {
        if ( !altfilename || strcmp( altfilename, [aTuple filename] ) ) {
            return NO;
	}
    }
    if ( [aTuple index] != ntindex ) {
        return NO;
    }
    return YES;
}
- (const char *) title
{
    if ( tuple ) {
       return h_getNtTitle( tuple );
    } else {
       return "not available";
    }
}
/* Methods for handling column functions */
- (List *) functionList
{
    if ( !functionList ) {
        functionList = [[List allocFromZone:[self zone]] initCount:0];
    }
    return functionList;
}
- takeFunctionList:(List *)list
{
    functionList = [self functionList];
    [functionList appendList:list];
    [list empty];
    return self;
}    
- startArchivingTo:(const char *)directory
{
    HFunction	*func;
    int		i;
    
    i = [functionList count];
    while( i-- ) {
        func = [functionList objectAt:i];
	[func saveToDirectory:directory];
    }
    return self;
}
- write:(NXTypedStream *) stream
{
    ntuple	ntlist[] = {NULL, NULL};
    char	*buffer;
    int		nt_size, len_fn;
    
    [super write:stream];
    len_fn = strlen( filename );
    NXWriteTypes( stream, "cci", &isRef, &isBinary, &len_fn );
    NXWriteTypes( stream, "*", &filename );
    if ( [HTuple version] >= INDEX_VERSION ) {
        NXWriteTypes( stream, "i", &ntindex );
    }
    if ( !isRef ) {
	nt_size = h_ntSize( tuple );
        NX_ZONEMALLOC( [self zone], buffer, char, nt_size );
	ntlist[0] = tuple;
	h_writeMem( buffer, nt_size, NULL, ntlist );
	NXWriteType( stream, "i", &nt_size );
	NXWriteArray( stream, "c", nt_size, buffer );
	NX_FREE(buffer);
    }
    if ( [HTuple version] >= FUNCTION_VERSION ) {
        NXWriteObject( stream, functionList);
    }
    return self;
}
- read:(NXTypedStream *) stream
{
    ntuple	*ntlist;
    display	*dlist;
    char	*buffer;
    int		nt_size, len_fn;
    
    [super read:stream];
    NXReadTypes( stream, "cci", &isRef, &isBinary, &len_fn );
    NX_ZONEMALLOC( [self zone], filename, char, len_fn+1 );
    NXReadTypes( stream, "*", &filename );
    if ( NXTypedStreamClassVersion(stream, "HTuple") >= INDEX_VERSION ) {
	NXReadType( stream, "i", &ntindex );
    }
    if ( !isRef ) {
        NXReadType( stream, "i", &nt_size );
        NX_ZONEMALLOC( [self zone], buffer, char, nt_size );
	NXReadArray( stream, "c", nt_size, buffer );
	h_readMem( buffer, nt_size, &dlist, &ntlist );
	tuple = ntlist[0];
	NX_FREE(buffer);
    }
    if ( NXTypedStreamClassVersion(stream, "HTuple") >= FUNCTION_VERSION ) {
        functionList = NXReadObject( stream );
    }
    return self;
}
- (int) finishUnarchivingFrom:(const char *)directory;
{
    HAddColFunction	*funcObj;
    unsigned int	i, count;
    int			irc;
    
    if ( !isRef ) {
        return 0;
    }
    count = [functionList count];
    if ( !count ) {
        return 0;
    }
    
  /* The order of columns is importantfor the plot binding */
    for ( i = 0; i < count; i++ ) {
        funcObj = [functionList objectAt:i];
	[funcObj initFromDirectory:directory];
	irc = [funcObj runWith:self];
	if ( irc != 0 ) return irc;
    }
    return 0;
}
- free
{
    h_freeNt( tuple );
    NXZoneFree([self zone], filename );
    NXZoneFree([self zone], altfilename );
    [functionList freeObjects];
    NXZoneFree([self zone], functionList);
    return [super free];
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.