/* You may freely copy, distribute and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or implied, as to
 * its fitness for any particular use.
 */ 

#import "CallRecord.h"

@implementation CallRecord : Object

/*
 * Purpose: Set and access data fields in a CallRecord.
 *
 * Two types of methods are implemented for the fields in the CallRecord
 *
 *   Methods of the form -setName: accept a string as input, copy the string 
 *   to a buffer, and set the instance variable to that buffer.
 *
 *   Methods of the form -name retrieve the data for 
 *   the corresponding instance variable.  
 */ 

- (const char *)name;
{
    return name;
}

- setName:(const char *)theName;
{
    if (theName) {
	name = NXCopyStringBuffer(theName);
    }
    return self;
}

- (const char *)street;
{
    return street;
}

- setStreet:(const char *)theStreet;
{
    if (theStreet) {
	street = NXCopyStringBuffer(theStreet);
    }
    return self;
}

- (const char *)city;
{
    return city;
}

- setCity:(const char *)theCity;
{
    if (theCity) {
	city = NXCopyStringBuffer(theCity);
    }
    return self;
}

- (const char *)state
{
    return state;
}

- setState:(const char *)theState;
{
    if (theState) {
	state = NXCopyStringBuffer(theState);
    }
    return self;
}

- (const char *)phone;
{
    return phone;
}

- setPhone:(const char *)thePhone;
{
    if (thePhone){
	phone = NXCopyStringBuffer(thePhone);
    }
    return self;
}

- (const char *)question;
{
    return question;
}

- setQuestion:(const char *)theQuestion;
{
    if (theQuestion) {
	question = NXCopyStringBuffer(theQuestion);
    }
    return self;
}

- (const char *)answer;
{
    return answer;
}

- setAnswer:(const char *)theAnswer;
{
    if (theAnswer) {
	answer = NXCopyStringBuffer(theAnswer);
    }
    return self;
}


/*
 * Purpose: Read and write the CallRecord to a stream
 *
 * These standard methods for archiving are inherited from Object. 
 * They're overridden by CallRecord for use in YourCall's data storage system. 
 *
 * When the HashTable containing CallRecords is read from the "call.log" file 
 * in CallController's init method, the HashTable sends a read: message 
 * to each CallRecord it contains. 
 *
 * When the HashTable containing CallRecords is written to the "call.log" file 
 * in CallController's saveCall: method, the HashTable sends a write: message 
 * to each CallRecord it contains. 
 */

- read:(NXTypedStream *)stream
{
    [super read:stream];
    NXReadTypes(stream, "*******", &name, &street, &city, &state, &phone, 
	&question, &answer);
    return self;
}

- write:(NXTypedStream *)stream
{
    [super write:stream];
    NXWriteTypes(stream, "*******", &name, &street, &city, &state, &phone, 
	&question, &answer);
    return self;
}


/*
 * Purpose: Frees the CallRecord's storage
 *
 * Inherited from Object 
 *
 * This method is overridden by CallRecord to free storage 
 * allocated by each of the set... methods.  
 *
 */

- free
{
    free(name);
    free(street);
    free(city);
    free(state);
    free(phone);
    free(question);
    free(answer);
    return [super free];
}

@end
