/* 
 * RZSimpleString - a lightweight, archivable, immutable string class
 *
 * You may freely copy, distribute and reuse the code in this example.
 * This code is provided AS IS without warranty of any kind, expressed 
 * or implied, as to its fitness for any particular use.
 *
 * Copyright 1995 Ralph Zazula (rzazula@next.com).  All Rights Reserved.
 *
 */

#import "RZSimpleString.h"
#import <appkit/nextstd.h>			// for NX_FREE
#import <objc/hashtable.h>			// for NXCopyStringBuffer

@implementation RZSimpleString

- init
{
	[self error:"use -initWith:, not -init"];
	return [self notImplemented:_cmd];
}

- initWith:(const char *)format, ...
{
	va_list args;
	static char buf[1024];
	
	if(self = [super init]) {
		va_start(args, format);
		vsprintf(buf, format, args);
		data = buf ? NXCopyStringBuffer(buf) : NULL;
	}
	return self;
}

- free
{
	if(data) {
		NX_FREE(data);
		data = NULL;
	}
	
	return [super free];
}

- (const char *)string
{
	return data;
}

- write:(NXTypedStream *)ts
{
	[super write:ts];
	NXWriteTypes(ts, "*", &data);
	return self;
}

- read:(NXTypedStream *)ts
{
	[super read:ts];
	NXReadTypes(ts, "*", &data);
	return self;
}

@end
