#ifndef _TSTREAM_
#define _TSTREAM_


#if THINK_C || __SC__
	#include <oops.h>
#endif
#include <Files.h>
#include <Errors.h>

// GS_SDKPPC_JAK - 
// Now that the SDK plug-ins are PPC, the type "extended" is not defined for PPC.
// So I can either define double_t as double, or call fp.h to do it for me, or simply replace double_t with double here.
// typedef extended double_t;
// typedef double double_t; 
#include "fp.h"		// fp.h will define double_t to be double on PPC.


#if THINK_C || __SC__
class TStream : PascalObject
#else
class TStream
#endif
{
	public:
		TStream() {}
		virtual void GS_API Free();
		
		virtual OSErr GS_API GetSize(long &size);
		virtual OSErr GS_API SetSize(long size);
		virtual OSErr GS_API GetPos(long &pos);
		virtual OSErr GS_API SetPos(long pos);
		virtual OSErr GS_API SkipBytes(long d);
		virtual OSErr GS_API ToStart();
		virtual OSErr GS_API ToEnd();
		
		virtual Boolean GS_API AtEnd();
		
		virtual OSErr GS_API ReadBytes(void *buf, long &count);
		OSErr ReadBytesNC(void *buf, long count)
			{ long c = count; return this->ReadBytes(buf,c); }
		virtual OSErr GS_API UnReadBytes(long count);

		OSErr operator>>(char &c)				{return this->ReadBytesNC(&c,1);}
		OSErr operator>>(unsigned char &c)		{return this->ReadBytesNC(&c,1);}
		OSErr operator>>(long &l)				{return this->ReadBytesNC(&l,sizeof(long));}
		OSErr operator>>(short &s)				{return this->ReadBytesNC(&s,sizeof(short));}
		OSErr operator>>(double_t &d)			{return this->ReadBytesNC(&d,sizeof(double_t));}
};

class TFileStream : public TStream {
	protected:
		short 	fRefNum;
		
	public:
		TFileStream(): fRefNum(0) 	{}
		virtual void GS_API Free();
		
		OSErr GS_API Open(Str255 fileName, short vRefNum);
		OSErr GS_API Close();
	
		virtual OSErr GS_API GetSize(long &size);
		virtual OSErr GS_API SetSize(long size);
		virtual OSErr GS_API GetPos(long &pos);
		virtual OSErr GS_API SetPos(long pos);
		virtual OSErr GS_API SkipBytes(long d);
		virtual OSErr GS_API ToStart();
		virtual OSErr GS_API ToEnd();
		virtual Boolean GS_API AtEnd();
		
		OSErr GS_API ReadBytes(void *buf, long &count);
		OSErr GS_API UnReadBytes(long count);
};

#endif
