summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-2.1.1/src/gd_io_stream.cxx
blob: 28021afc1ae8f2bb3d0aa91f106d71345e830c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* *****************************************************************************
** $Id$
** Initial file written and documented by:
** Kevin Shepherd <kshepherd@php.net> December 2007
** of Scarlet Line http://www.scarletline.com/
*******************************************************************************/
/** \file gd_io_stream.cxx
	\brief Implementation of the methods of the gdIOCtx std stream specialization.
	
	Implements the derived specializations of gdIOCtx.
	These methods are not called by users of libgd, they
	are internal implementation.
	Note that half of the below methods are trivial stubs,
	as an input stream has no need of output methods, and vice-versa.
*/
#ifdef __cplusplus

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gd_io_stream.h"

/**	Read into buffer from stream
	Return the number of bytes successfully read.  
	If an error occurs, or the end-of-file is reached, the return value
	is a short byte	count (or zero).
*/
int	istreamIOCtx::Getbuf (struct gdIOCtx * ctx, void * buf, int size)
	{
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
	_str->read((char * )buf, size);
	return _str->gcount();
	}
/**	Write from buffer to stream
	Return the number of bytes successfully written.  
	If an error occurs, or the end-of-file is reached, the return value
	is a short byte	count (or zero).
*/
int	istreamIOCtx::Putbuf (struct gdIOCtx * , const void * , int )
	{
	return 0;
	}

/**	Reads the next character from stream and returns it as an
	unsigned char cast to an int, or EOF on end of file or error.
*/
int	istreamIOCtx::Getchar (struct gdIOCtx * ctx)
	{
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
	return _str->get();
	}
/**	Write the character to stream
	Character is cast to unsigned char before writing
*/
void	istreamIOCtx::Putchar (struct gdIOCtx * , int )
	{
	}

/** Seek to position offset from the beginning of the stream
	must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! 
*/
int	istreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
	{
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
	_str->seekg(pos);
	return !_str->fail();
	}
/** Obtains the current value of the stream position.
	Returns -1 on error.
*/
long	istreamIOCtx::Tell (struct gdIOCtx * ctx)
	{
	stream_type * _str = ( (istreamIOCtx * ) ctx )->_M_stream;
	return _str->tellg();
	}
/** Deallocate the context
*/
void	istreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
	{
	delete (istreamIOCtx * )ctx;
	}

/**	Read into buffer from stream
	Return the number of bytes successfully read.  
	If an error occurs, or the end-of-file is reached, the return value
	is a short byte	count (or zero).
*/
int	ostreamIOCtx::Getbuf (struct gdIOCtx * , void * , int )
	{
	return 0;
	}
/**	Write from buffer to stream
	Return the number of bytes successfully written.  
	If an error occurs, or the end-of-file is reached, the return value
	is a short byte	count (or zero).
*/
int	ostreamIOCtx::Putbuf (struct gdIOCtx * ctx, const void * buf, int size)
	{
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
	_str->write((const char * )buf, size);
	return _str->bad()?0:size;
	}

/**	Reads the next character from stream and returns it as an
	unsigned char cast to an int, or EOF on end of file or error.
*/
int	ostreamIOCtx::Getchar (struct gdIOCtx * )
	{
	return EOF;
	}
/**	Write the character to stream
	Character is cast to unsigned char before writing
*/
void	ostreamIOCtx::Putchar (struct gdIOCtx * ctx, int c)
	{
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
	_str->put((char)c);
	}

/** Seek to position offset from the beginning of the stream
	must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! 
*/
int	ostreamIOCtx::Seek (struct gdIOCtx * ctx, const int pos)
	{
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
	_str->seekp(pos);
	return !_str->fail();
	}
/** Obtains the current value of the stream position.
	Returns -1 on error.
*/
long	ostreamIOCtx::Tell (struct gdIOCtx * ctx)
	{
	stream_type * _str = ( (ostreamIOCtx * ) ctx )->_M_stream;
	return _str->tellp();
	}
/** Deallocate the context
*/
void	ostreamIOCtx::FreeCtx (struct gdIOCtx * ctx)
	{
	delete (ostreamIOCtx * )ctx;
	}

#endif /* __cplusplus */