Blame src/gd_io_stream.cxx

Packit ed3af9
/* *****************************************************************************
Packit ed3af9
** $Id$
Packit ed3af9
** Initial file written and documented by:
Packit ed3af9
** Kevin Shepherd <kshepherd@php.net> December 2007
Packit ed3af9
** of Scarlet Line http://www.scarletline.com/
Packit ed3af9
*******************************************************************************/
Packit ed3af9
/** \file gd_io_stream.cxx
Packit ed3af9
	\brief Implementation of the methods of the gdIOCtx std stream specialization.
Packit ed3af9
	
Packit ed3af9
	Implements the derived specializations of gdIOCtx.
Packit ed3af9
	These methods are not called by users of libgd, they
Packit ed3af9
	are internal implementation.
Packit ed3af9
	Note that half of the below methods are trivial stubs,
Packit ed3af9
	as an input stream has no need of output methods, and vice-versa.
Packit ed3af9
*/
Packit ed3af9
#ifdef __cplusplus
Packit ed3af9
Packit ed3af9
#ifdef HAVE_CONFIG_H
Packit ed3af9
#include "config.h"
Packit ed3af9
#endif
Packit ed3af9
Packit ed3af9
#include "gd_io_stream.h"
Packit ed3af9
Packit ed3af9
/**	Read into buffer from stream
Packit ed3af9
	Return the number of bytes successfully read.  
Packit ed3af9
	If an error occurs, or the end-of-file is reached, the return value
Packit ed3af9
	is a short byte	count (or zero).
Packit ed3af9
*/
Packit ed3af9
int	istreamIOCtx::Getbuf (struct gdIOCtx * ctx, void * buf, int size)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	_str->read((char * )buf, size);
Packit ed3af9
	return _str->gcount();
Packit ed3af9
	}
Packit ed3af9
/**	Write from buffer to stream
Packit ed3af9
	Return the number of bytes successfully written.  
Packit ed3af9
	If an error occurs, or the end-of-file is reached, the return value
Packit ed3af9
	is a short byte	count (or zero).
Packit ed3af9
*/
Packit ed3af9
int	istreamIOCtx::Putbuf (struct gdIOCtx * , const void * , int )
Packit ed3af9
	{
Packit ed3af9
	return 0;
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
/**	Reads the next character from stream and returns it as an
Packit ed3af9
	unsigned char cast to an int, or EOF on end of file or error.
Packit ed3af9
*/
Packit ed3af9
int	istreamIOCtx::Getchar (struct gdIOCtx * ctx)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	return _str->get();
Packit ed3af9
	}
Packit ed3af9
/**	Write the character to stream
Packit ed3af9
	Character is cast to unsigned char before writing
Packit ed3af9
*/
Packit ed3af9
void	istreamIOCtx::Putchar (struct gdIOCtx * , int )
Packit ed3af9
	{
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
/** Seek to position offset from the beginning of the stream
Packit ed3af9
	must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! 
Packit ed3af9
*/
Packit ed3af9
int	istreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	_str->seekg(pos);
Packit ed3af9
	return !_str->fail();
Packit ed3af9
	}
Packit ed3af9
/** Obtains the current value of the stream position.
Packit ed3af9
	Returns -1 on error.
Packit ed3af9
*/
Packit ed3af9
long	istreamIOCtx::Tell (struct gdIOCtx * ctx)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	return _str->tellg();
Packit ed3af9
	}
Packit ed3af9
/** Deallocate the context
Packit ed3af9
*/
Packit ed3af9
void	istreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
Packit ed3af9
	{
Packit ed3af9
	delete (istreamIOCtx * )ctx;
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
/**	Read into buffer from stream
Packit ed3af9
	Return the number of bytes successfully read.  
Packit ed3af9
	If an error occurs, or the end-of-file is reached, the return value
Packit ed3af9
	is a short byte	count (or zero).
Packit ed3af9
*/
Packit ed3af9
int	ostreamIOCtx::Getbuf (struct gdIOCtx * , void * , int )
Packit ed3af9
	{
Packit ed3af9
	return 0;
Packit ed3af9
	}
Packit ed3af9
/**	Write from buffer to stream
Packit ed3af9
	Return the number of bytes successfully written.  
Packit ed3af9
	If an error occurs, or the end-of-file is reached, the return value
Packit ed3af9
	is a short byte	count (or zero).
Packit ed3af9
*/
Packit ed3af9
int	ostreamIOCtx::Putbuf (struct gdIOCtx * ctx, const void * buf, int size)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	_str->write((const char * )buf, size);
Packit ed3af9
	return _str->bad()?0:size;
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
/**	Reads the next character from stream and returns it as an
Packit ed3af9
	unsigned char cast to an int, or EOF on end of file or error.
Packit ed3af9
*/
Packit ed3af9
int	ostreamIOCtx::Getchar (struct gdIOCtx * )
Packit ed3af9
	{
Packit ed3af9
	return EOF;
Packit ed3af9
	}
Packit ed3af9
/**	Write the character to stream
Packit ed3af9
	Character is cast to unsigned char before writing
Packit ed3af9
*/
Packit ed3af9
void	ostreamIOCtx::Putchar (struct gdIOCtx * ctx, int c)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	_str->put((char)c);
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
/** Seek to position offset from the beginning of the stream
Packit ed3af9
	must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! 
Packit ed3af9
*/
Packit ed3af9
int	ostreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	_str->seekp(pos);
Packit ed3af9
	return !_str->fail();
Packit ed3af9
	}
Packit ed3af9
/** Obtains the current value of the stream position.
Packit ed3af9
	Returns -1 on error.
Packit ed3af9
*/
Packit ed3af9
long	ostreamIOCtx::Tell (struct gdIOCtx * ctx)
Packit ed3af9
	{
Packit ed3af9
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
Packit ed3af9
	return _str->tellp();
Packit ed3af9
	}
Packit ed3af9
/** Deallocate the context
Packit ed3af9
*/
Packit ed3af9
void	ostreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
Packit ed3af9
	{
Packit ed3af9
	delete (ostreamIOCtx * )ctx;
Packit ed3af9
	}
Packit ed3af9
Packit ed3af9
#endif /* __cplusplus */