/*	XStream.h
 *
 *		File wrapper routines. This defines a hierarchy of classes
 *	which provide various stream, pipe and file I/O abstractions
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#ifndef PandaWave_XSTREAM
#define PandaWave_XSTREAM

#include <XConfig.h>
#include <XHandle.h>

/************************************************************************/
/*																		*/
/*	Stream abstractions													*/
/*																		*/
/************************************************************************/

/*$	XGStream
 *
 *		The YAAF file stream. This is an abstraction of a data I/O
 *	mechanism for getting and setting data to a 'stream'
 */

class XGStream {
	public:
								XGStream()
									{
									}
		virtual					~XGStream()
									{
									}

		/*
		 *	Data I/O
		 */
		
		virtual	long			Read(long, void *) = 0;
		virtual	long			Write(long, void *) = 0;
		virtual void			Flush() = 0;
};

/*$	XGFileStream
 *
 *		File stream class; this adds seek and EOF markers
 */

class XGFileStream : public XGStream {
	public:
								XGFileStream()
									{
									}
		virtual					~XGFileStream()
									{
									}

		/*
		 *	File position and EOF markers
		 */
		
		virtual long			GetFilePos() = 0;
		virtual void			SetFilePos(long) = 0;
		virtual long			GetEOF() = 0;
		virtual void			SetEOF(long) = 0;
};

/*$	XGDataStream
 *
 *		Data stream class; this is used for things like serial
 *	port I/O
 */

class XGDataStream : public XGStream {
	public:
								XGDataStream()
									{
									}
		virtual					~XGDataStream()
									{
									}

		/*
		 *	Data stream routines
		 */
		
		virtual long			GetBufferSize() = 0;
};

/************************************************************************/
/*																		*/
/*	Handle File															*/
/*																		*/
/************************************************************************/

/*$	XGFileHandle
 *
 *		This is a handle-based file. This provides the various abstractions
 *	of file I/O, but in a handle. This is basically an override of the
 *	XHandle object which provides the various file I/O stuff
 */

class XGFileHandle : public XGHandle, public XGFileStream {
	public:
								XGFileHandle();
		virtual					~XGFileHandle();
		
		/*
		 *	File I/O routines
		 */
		
		virtual	long			Read(long, void *);
		virtual	long			Write(long, void *);
		virtual void			Flush(void);

		virtual long			GetFilePos();
		virtual void			SetFilePos(long);
		virtual long			GetEOF();
		virtual void			SetEOF(long);

	private:
		long					fPos;
};

#endif /* PandaWave_XSTREAM */
